Using the design you wrote in the In-Lab, implement a Time class.
Your Time class should implement this TimeInterface and the Comparable interface this way:
public class Time implements Comparable, TimeInterface {...}
Note that
all comments have been ommited from this interface, but you should supply them.
public interface TimeInterface { Time addTime(int minutes); Time addTime(int hours, int minutes); int compareTo(Time rhs); String toString(); }
To help you test your class, and to sure you are using the compareTo and toString methods correctly, a elementary driver is included. After you get it to run correctly, you should add some I/O to the driver so you become familiar with the Scanner class. It is much easier to use than the BufferedReader class in older versions of Java.
Hand in: You will hand in the source code for the Time class, as well as the source code for the TimeUser class, and the commented interface. William will let you know anything else he wants.
Out-Lab 2--Working with Arrays
This will be a two week lab;
It will be due at the beginning of lab October 10.
Here is one solution, in case you are interested. I do not expect your program to
find solutions and your output will not be graphical like this one.
You can start the knight in any square you like.
Out-Lab 5--Linked Lists
This will be a two week lab;
It will be due at the beginning of lab November 7.
For this lab, you will solve the problem of storing an phone book two different ways.
Out-Lab 6--Using Queues for Simulation
This will be a two week lab;
It will be due at the beginning of lab November 21.
Description
Input
You will have an input file that will contain information about
the people coming to the MVD. It will have:
Further details: Incorporate the following details into your program:
Sign in 10 seconds Renew license 90 seconds Register automobile 60 seconds See cashier (payment) 30 seconds See cashier (check not approved)10 seconds
Out-Lab 7--The Tortoise and the Hare
This lab will be due during the last week of class
Description
The race begins at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves it way up the side of a slippery mountain, so occasionally the contenders lose ground.
A clock ticks once per second. Withe each tick of the clock, your application should adjust the position of the animal according to the rules given below. Use variables to keep track of the positions of the animals. Start each animal at psotion 1. If an animal slips left before square one, move it back to square 1.
Generate the percentages below by producing a random integer i in the
range 1 <= i <= 10.
For the tortoise, perform a "fast plod" when 1 <= i <= 5, a "
slip" when 6 <= i <= 7 or a'slow plod" when 8 <= i <= 10.
Use a similar techinique to move the hare.
Begin the race by displaying
BANG !!!
AND THEY'RE OFF!!!!
Then, for each tick of the clock (i.e. each repetition of a loop), display a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your application should display OUCH! Beginning at that position. All output positions other than the T, the H, or the OUCH!!! (in case of a tie) should be blank.
After each line is displayed, test for whether either animal has reached or passed square 70. If so, display the winner and terminate the simulation. If the tortoise wins, display TORTOISE WINS!! If the hare wins, display Hare wins. If both animals win on the same tick of the clock, display It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock.
Animal | of the time |
||
Tortoise | Fast plod Slip Slow plod |
50% 20% 30% | 3 squares to the right 6 squares to the left 1 square to the right |
Hart | Sleep Big hop Big Slip Small hop Small slip |
20% 20% 10% 30% 20% |
No move at all 9 squares to the right 12 squares to the left 1 square to the right 2 squares to the left |
Sample output This is shorter than most runs
BANG!!!! AND THEY'RE OFF !!!!! H T H T H T OUCH!!! H T H T H T H T H T H T H T HT H T H T OUCH!!! T H TH H T T H TH T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H T H Hare wins. TIME ELAPSED = 43 seconds