Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Announcer {
- private static int randomAnnounce;
- public int getRandomAnnounce() {
- return randomAnnounce;
- }
- public void setRandomAnnounce(int randomAnnounce) {
- Announcer.randomAnnounce = randomAnnounce;
- }
- public static void generateRandomAnnounce() {
- int result;
- Random randomSaying = new Random();
- result = randomSaying.nextInt(4);
- Announcer.randomAnnounce = result;
- }
- public String toString() {
- return "Announcer [randomAnnounce=" + randomAnnounce + "]";
- }
- public String announceLeader(int leader, Car[] cars) {
- String result;
- switch (Announcer.randomAnnounce) {
- case 0:
- result = "The current leader is " + cars[leader].getName()
- + ". They are at lap location "
- + cars[leader].getLocation() + " and zipping along at "
- + cars[leader].getSpeed() + " UPH.";
- return result;
- case 1:
- result = "Our leader is " + cars[leader].getName()
- + " at location " + cars[leader].getLocation()
- + ". The leader's speed is " + cars[leader].getSpeed()
- + " UPH.";
- return result;
- case 2:
- result = cars[leader].getName()
- + " is in the lead! At a speed of "
- + cars[leader].getSpeed()
- + " UPH they have quickly moved to location "
- + cars[leader].getLocation() + ".";
- return result;
- case 3:
- result = cars[leader].getName()
- + " is leading the field right now. Moving at "
- + cars[leader].getSpeed()
- + " UPH they are getting closer to the finish! Only "
- + (1000 - cars[leader].getLocation())
- + " location units remain!";
- return result;
- default:
- result = "hmmm. We have an error";
- return result;
- }
- }
- public String announceWinner(int leader, Car[] cars) {
- String result;
- result = "And the winner is " + cars[leader].getName()
- + "!!! They finished the race at a speed of "
- + cars[leader].getSpeed() + " UPH!";
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement