Arithmetic
String Class
Math Class
Class Structure
100

int x = 5/10

What is stored in x?

0

100
What is the result of


"rachmaninoff".length()

12

100

int x = Math.random();

What is x?

0

100

Explain what a static method is.

A static method is a method that is not invoked from an object (and thus, does not use any instance variables).

200

double x = 5/10;

What is stored in x?

0.0

200

What is the result of 

"rachmaninoff".substring(0)

"rachmaninoff"

200

double x = (int) Math.random();

What is x?

0.0

200

A Building class has an empty (null) constructor. Write the header for the empty constructor

public Building()

300

double x = (double) 5/10;

What is stored in x?

0.5

300

What is the result of

String x = "hello";

x + x.substring(x.length() - 1);

"helloo"

300

double x = Math.random() - Math.random();

What is the smallest possible value of x?

-1.0 (not including)

300

A Person object consists of a name (String) and an age (int). Write an accessor method for the name instance variable.

public String getName()

{ return this.name;}

400
double x = 5*4/10;


What is stored in x?

2.0
400

What is the result of

"AP Computer Science".substring(5,6);

"m"

400

int x = (int) 5*Math.random();

What is the largest possible value of x?

4

400

A Person object consists of a name (String) and an age (int). Write an appropriate constructor for the Person class that fills in the instance variables.

public Person(String name, int age)

{

    this.name = name;

    this.age = age;

}

500

int x = 11 % 3;

What is stored in x?

2
500

String s = "ap-cs-a";

int i =  s.indexOf("-");

s = s.substring(0,i) + s.substring(i+1);

What is stored in variable 's'?

"apcs-a"

500

int x = 10*((int) Math.random()) + 5;

What is x?

5

500

A Student consists of a name "String" and a grade level (int). A Group consists of two Student objects s1 and s2. Write a Group constructor that takes in a name and a grade for each Student (4 arguments total), constructs two Students, and assigns them to the Group instance variables s1 and s2.

public Group(String n1, int g1, String n2, int g2)

{

    this.s1 = new Student(n1, g1);

    this.s2 = new Student(n2, g2);

}

M
e
n
u