The class TimeBook in Listing 7.14 is not really finished. Complete the definition of this class in

Question:

The class TimeBook in Listing 7.14 is not really finished. Complete the definition of this class in the way described in the text. In particular, be sure to add a default constructor, as well as set and get methods that change or retrieve each of the instance variables and each indexed variable of each array instance variable. Be sure you replace the stub setHours with a method that obtains values from the keyboard. You should also define a private method having two int parameters that displays the first parameter in the number of spaces given by a second parameter. The extra spaces not filled by the first parameter are to be filled with blanks.

This will let you write each array element in exactly four spaces, for example, and so will allow you to display a neat rectangular arrangement of array elements. Be sure that the main method in Listing 7.14 works correctly with these new methods. Also, write a separate test program to test all the new methods. (Hint: To display an int value n in a fixed number of spaces, use Integer.toString( n ) to convert the number to a string value, and then work with the string value. This method is discussed in Chapter 6 in the section “Wrapper Classes.”)


Listing 7.14

Class that records the t ime worked by each of a company's employees during one five-day week. A sample application is in the main method. */ public class TimeBook { private int numberofEmployees; //hours[i][j] has the hours for //employee j on day i. private int[]) hours; private int[0 weekHours; //weekHours[i]

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: