AP Computer Science Homework Set 4 Arrays and ArrayLists of ...
AP Computer Science Homework Set 4 Arrays and ArrayLists of ...
AP Computer Science Homework Set 4 Arrays and ArrayLists of ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
P4B. Write a program that creates a “ClockStore” class that is able to hold<br />
“Clock” objects. You should reuse the Clock class from the previous chapter.<br />
The class should meet the following requirements:<br />
1. Write a class “ClockStore” that consists <strong>of</strong> a private array called<br />
“clocksInStock” that can hold 3 Clock objects.<br />
2. Create an instance <strong>of</strong> class “ClockStore” <strong>and</strong> populate it with three Clock<br />
objects using the Clock’s constructor. You set the time for each Clock.<br />
Here’s a sample demonstrating how to place a Clock in the array at position<br />
“0”:<br />
clocksInStock[0] = new Clock( 12, 30, 45 );<br />
4. Write a processor method mostSeconds() that returns index <strong>of</strong> the Clock<br />
that has the highest total seconds as calculated by the Clock method<br />
totalSeconds(). The ClockStore method mostSeconds() should<br />
have the following header:<br />
int mostSeconds()<br />
5. Write a toString() method that traverses the array <strong>of</strong> Clocks using a foreach<br />
loop. This should print the time <strong>of</strong> each clock using each Clock’s<br />
toString() method.<br />
6. Write a driver class “ClockDriver” that tests the above methods.<br />
P4C. Write a program that creates a “Roster” class that is able to hold<br />
“Student” objects. You should reuse the Student class from the previous<br />
chapter.<br />
The class should meet the following requirements:<br />
1. Write a class “Roster” that consists <strong>of</strong> a private array <strong>of</strong> Students.<br />
2. Create an instance <strong>of</strong> class “Roster” <strong>and</strong> populate it with three Student<br />
objects.<br />
3. Write a Roster findStudentWithMaxGPA() method that traverses the<br />
array with a for loop <strong>and</strong> returns out the name <strong>of</strong> the student with the max<br />
GPA.<br />
4. Write a Roster toString() method prints the name <strong>of</strong> the student with the<br />
maximum GPA (via calling the method findStudentWithMaxGPA().<br />
5. Write a driver class “RosterDriver” that tests the above methods.<br />
Page 2<br />
<strong>AP</strong> <strong>Computer</strong> <strong>Science</strong> – HW <strong>Set</strong> 4 Programs<br />
http://thecubscientist.com