Classes: Color, Random, String, ArrayList, Graphics
For this assignment, you must work in teams of 2.
You may decide how your team works together (we will discuss it in class too), but please
explain it to me in a readme.txt file that will be part of the submission for this assignment.
Answer any other questions in the write-up in the file also (unless it's already been turned in).
You will only submit 1 set of files; make sure to include both your names, Andrew IDs, and the honor statement in all your code, using the format given in class.
Due Week 7: Tuesday by 8pm.
Important: for any graphical classes that need to draw make sure you use this
exact signature:
This method should execute all the code to draw in g,
including calling any other methods (they will also need to take g as an argument).
Both LineArt.java (HW2) and ConnectTheDots.java (HW3) show the basic idea.
Reminder: for any Helper class, make sure your instance variables are private
and that you write toString()!
Written exercise, due Friday by the end of lab (so this is what you should work on during the Week 4
lab). Submit your team's answers via Canvas no later than the end of the day on Friday of Week 4.
Write the following code:
Note: make sure you get your basic design of the attributes reviewed.
The traffic light starts out indicating stop. When it changes, it goes to go;
from go, it goes to caution. After caution it returns to stop.
When drawing each of the lights off, the following colors work nicely:
The size of your traffic light should be based on the width and height of
the drawing area - have a look at your LineArt.java from HW2. Why is this calculation done in
paintComponent()?
Code your class to finish this program: RunLight.
It will use your TrafficLight class to show the light, let the user click on it to have it
change state, and then it will redraw your TrafficLight.
For instance, if the secret phrase is Java is Great!, the display string would be
____ __ _____!
The SecretString class can check if a certain string matches the secret phrase.
The SecretString class has the ability to reveal letters - you can give it a set of letters
(as a string), and it will "uncover" each one that matches; it will also tell you how many letters it uncovered.
Re-read CH 7.16 in your book and use an ArrayList Below is a sample dialog for the game (user input is shown as bold):
Note: You must write a test plan for GuessWord submit it on Canvas. You should also have it reviewed by a
TA during office hours. Make sure you think about error tests.
All elevators should start out on the bottom floor. The elevator for your program will have a maximum of 20
floors.
Your program should prompt the user for the floor they would like the elevator to go to, then
move the elevator to this floor.
When the elevator moves, it must first close the door and print the
message shown below. As the elevator goes passed a floor, it should print a message
that says "Going up to floor N" or "Going down to floor N". When it reaches
the destination floor, it should print the message "Opening door at floor N".
Your program should continue to prompt the user for the
floor and go there until they just press enter, then the program should end.
Your output should look like this (user input is shown in bold): Make sure your names, Andrew IDs, and the Academic Integrity statement are in all of your submitted code.
Note: Associated written assignments will be assigned and due before the final due-date.
public void paintComponent(Graphics g)
new Color(187, 0, 0) // red off
new Color(187, 187, 0) // yellow off
new Color(0, 100, 0)) // green off
***********************************************
Welcome to Cathy's fabulous word-guessing game!
***********************************************
Would you like to play? yes
---- -- -----!
Guess the phrase: Hello
No, that's not it.
Guess a letter: a
There are 3 "a"s
_a_a __ ___a_!
Guess the phrase: Hello World
No, that's not it.
Guess a letter: j
There is 1 "j"
Ja_a __ ___a_!
Guess the phrase: Java World
No, that's not it.
Guess a letter: x
There are 0 "x"s
Ja_a __ ___a_!
Guess the phrase: java is great
**Yes, that's it! You guessed it in 4 tries!
***********************************************
Would you like to play again? yep
_ ____ __ ____.
Guess the phrase: java is great
No, that's not it.
Guess a letter: e
There are 2 "e"s
_ ___e __ ___e.
Guess the phrase: i love to code!
**Yes, that's it! You guessed it in 2 tries!
***********************************************
Would you like to play again? no
***********************************************
Thanks for playing Cathy's word-guessing game!
***********************************************
The elevator is on floor 1.
Please enter the new floor (Enter to quit): 4
Closing door.
Going up to floor 2.
Going up to floor 3.
Opening door at floor 4.
The elevator is on floor 4.
Please enter the new floor (Enter to quit): 1
Closing door.
Going down to floor 3.
Going down to floor 2.
Opening door at floor 1.
The elevator is on floor 1.
Please enter the new floor (Enter to quit): -3
Invalid floor!
The elevator is on floor 1.
Please enter the new floor (Enter to quit): 1
Closing door.
Opening door at floor 1.
The elevator is on floor 1.
Please enter the new floor (Enter to quit):
Bye!
Make sure you test it well!