1.
Consider the transaction of asking your professor for your grade in your computer science course. Identify the objects in this transaction and the types of messages that would be passed among them.
RiddleUser class (ListingΒ 2.4.7), give two examples of object instantiation and explain what is being done.
Riddle and RiddleUser examples discussed in this chapter.
RiddleUser class (ListingΒ 2.4.7), identify three examples of method calls and explain what is being done.
Riddle example.
int 74ElmStreet Big_N L$&%# boolean Boolean _number
Int public Private Joe j1 2*K big numb
Big_N as a class name since the first leter is captialized.Boolean is the identifier/class name for the wrapper class of the boolean primitive type, and it can be re-used as a variable identifier.Int is not the identifier/class name for the wrapper class of the boolean primitive type, instead Integer is used.Private as a class name since the first leter is captialized.Joe as a class name since the first leter is captialized.j1 is a legal identifier, and most Java coding conventions would have it be a variable, field, or method name.public is a reserved access modifier word._, so L$&%# is not allowedboolean is a reserved wordint is a reserved word2*K is an expression, and identifiers canβt start with a number or have any symbol other than _ (underscore) in them.big numb has a space in it, and identifiers canβt have any non-alphanumeric character other than _ (underscore) in them.public boolean isEven;
Private boolean isEven;
private boolean isOdd
public boolean is Odd;
string S;
public String boolean;
private boolean even = 0;
private String s = helloWorld;
public String boolean()
private void String ()
private void myMethod
private myMethod()
public static void Main (String argv[])
public int m;
public boolean b;
public String s;
m = "86";
m = 86;
m = true;
s = 1295;
s = "1295";
b = "true";
b = false
NumberAdder class, add statements to its main() method to create two instances of this class, named adder1 and adder2. Then add statements to set adder1βs numbers to 10 and 15, and adder2βs numbers to 100 and 200. Then add statements to print their respective sums.
NumberAdder class in the previous exercise, what are the names of its instance variables and instance methods? Identify three expressions that occur in the program and explain what they do. Identify two assignment statements and explain what they do.
new along with an objectβs constructor. 5 primitive type variable an identifier that has memory for the actual value of the variable 6 reference type variable an identifier that has memory for the reference to the object that holds the values of the variable.NumberCruncher that has a single int variable as its only instance variable(a.k.a. field). Then define methods that perform the following operations on its number: getVal, doubleVal, tripleVal, squareVal, and cubeVal that returns the result, but doesnβt modify the object. Set the initial value of the number with a constructor as was done with the instance variables in the Riddle class.
main() method and add it to the NumberCruncher class defined in the previous problem. Use it to create a NumberCruncher instance, with a certain initial value, and then get it to report its double, triple, square, and cube.
Cube object, that has an integer attribute for the length of its side. The object should be capable of reporting its surface area and volume. The surface area of a cube is six times the area of any side. The volume is calculated by cubing the side.
CubeUser object that will use the Cube object defined in the previous exercise. This class should create three Cube instances, each with a different side length, and then report their respective surface areas and volumes.
Entry, which consists of a name, address, and phone number, all represented as String s. For the classβs interface, define methods to get the values of each of its instance variables. Thus, for the name variable, it should have a getName() method. The constructor should take the name, address, and phone number as arguments.
Canvas, which serves as a user interface, and which draws three instances of a Triangle class named t1, t2, and t3.