Week 7 Homework
Instruction
Use the link provided by your professor to access the GitHub repo with the starter code.
This assignment consists of two parts.
Part 1: Complete Exercise 7.3
This exercise has you trace a program with multiple objects. The program with explanations can be found in Figures 7.2 and 7.3. The code can also be found in the assignment repository. Use this Excel file in the repository to use for the tracing.
Part 2: Complete the following program
In the GitHub starter code, skeletons for the Time and TimeDriver class have been provided. Replace the < insert ...> lines with your own code such that the program operates properly. More specifically:
- In the
Timeclass, provide a method definition for thesetHoursmethod such thatsetHourscan be called as part of a method-call chain. - In the
TimeDriverclass, provide a single statement that chains calls to thesetHours,setMinutes,setSeconds, andprintTimemethods. Use reasonable values for your method-call arguments. If you pass 8 tosetHours, 59 tosetMinutes, and 0 tosetSeconds, then your method-call-chaining statement should print08:59:00
public class Time {
private int hours;
private int minutes;
private int seconds;
//**********************************************************
<insert setHours method definition here>
public Time setMinutes(int minutes) {
this.minutes = minutes;
return this;
} // end setMinutes
public Time setSeconds(int seconds) {
this.seconds = seconds;
return this;
} // end setSeconds
//************************************************************
public void printTime() {
System.out.printf("%02d:%02d:%02d\n", hours, minutes, seconds);
} // end printTime
} // end Time class
public class TimeDriver {
public static void main(String[] args) {
Time time = new Time();
<insert chained-method-calls statement here >
}
} // end TimeDriver class
Submission Instructions:
Commit and Push your files to GitHub Classroom.