Question: 1. Suppose the providers of your Java compiler decide to change the way that a String object stores its characters, and they update the String

1. Suppose the providers of your Java compiler decide to change the way that a String object stores its characters, and they update the String method implementations accordingly. Which parts of your code do you need to change when you get the new compiler?

2. Supply the body of a method

public static void reset()

that resets the counter back to zero (for the Counter class in section 8.2).

3. What does the following code segment print (assuming the implementation of the CashRegister class as shown in section 8.3)?

CashRegister reg = new CashRegister( );

reg.clear( );

reg.addItem(0.95);

reg.addItem(0.95);

System.out.println(reg.getCount( ) + " " + reg.getTotal( ));

4. Name two accessor methods of the String class (HINT: look at the API).

5. Provide documentation comments for the Counter class of section 8.2.

6. Consider a class Grade that represents a letter grade, such as A+ or B. Give two different sets of instance variables that can be used for implementing the Grade class.

7. What are the values of register1, itemCount, register1.totalPrice, register2.itemCount, and register2.totalPrice after these statements?

CashRegister register1 = new CashRegister( );

register1.addItem(0.90);

register1.addItem(0.95);

CashRegister register2 = new CashRegister( );

register2.addItem(1.90);

8. Consider the length( ) method of the String class. How many parameters does it have, and what are their data types?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!