Advertisement
Dakpluto

Announcer.java

Oct 12th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Announcer {
  4.     private static int randomAnnounce;
  5.  
  6.     public int getRandomAnnounce() {
  7.         return randomAnnounce;
  8.     }
  9.  
  10.     public void setRandomAnnounce(int randomAnnounce) {
  11.         Announcer.randomAnnounce = randomAnnounce;
  12.     }
  13.  
  14.     public static void generateRandomAnnounce() {
  15.         int result;
  16.         Random randomSaying = new Random();
  17.         result = randomSaying.nextInt(4);
  18.         Announcer.randomAnnounce = result;
  19.     }
  20.  
  21.     public String toString() {
  22.         return "Announcer [randomAnnounce=" + randomAnnounce + "]";
  23.     }
  24.  
  25.     public String announceLeader(int leader, Car[] cars) {
  26.         String result;
  27.         switch (Announcer.randomAnnounce) {
  28.         case 0:
  29.             result = "The current leader is " + cars[leader].getName()
  30.                     + ".  They are at lap location "
  31.                     + cars[leader].getLocation() + " and zipping along at "
  32.                     + cars[leader].getSpeed() + " UPH.";
  33.             return result;
  34.         case 1:
  35.             result = "Our leader is " + cars[leader].getName()
  36.                     + " at location " + cars[leader].getLocation()
  37.                     + ".  The leader's speed is " + cars[leader].getSpeed()
  38.                     + " UPH.";
  39.             return result;
  40.  
  41.         case 2:
  42.             result = cars[leader].getName()
  43.                     + " is in the lead!  At a speed of "
  44.                     + cars[leader].getSpeed()
  45.                     + " UPH they have quickly moved to location "
  46.                     + cars[leader].getLocation() + ".";
  47.             return result;
  48.  
  49.         case 3:
  50.             result = cars[leader].getName()
  51.                     + " is leading the field right now.  Moving at "
  52.                     + cars[leader].getSpeed()
  53.                     + " UPH they are getting closer to the finish!  Only "
  54.                     + (1000 - cars[leader].getLocation())
  55.                     + " location units remain!";
  56.             return result;
  57.  
  58.         default:
  59.             result = "hmmm.  We have an error";
  60.             return result;
  61.         }
  62.     }
  63.  
  64.     public String announceWinner(int leader, Car[] cars) {
  65.         String result;
  66.         result = "And the winner is " + cars[leader].getName()
  67.                 + "!!! They finished the race at a speed of "
  68.                 + cars[leader].getSpeed() + " UPH!";
  69.         return result;
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement