Advertisement
Dakpluto

Race.java

Oct 12th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.67 KB | None | 0 0
  1. public class Race {
  2.  
  3.     public static void main(String[] args) {
  4.         Car petty = new Car("Richard Petty", 30);
  5.         Car waltrip = new Car("Darrel Waltrip", 30);
  6.         // System.out.println(petty);
  7.         // petty.setSpeed(petty.getSpeed() + petty.randomSpeedChange());
  8.         // System.out.println(petty);
  9.  
  10.         System.out
  11.                 .println("Out comes the green flag! Here we go race fans, it's the Great Race-Off between "
  12.                         + petty.getName() + " and " + waltrip.getName() + "!");
  13.  
  14.         while (petty.getLocation() < 1000 && waltrip.getLocation() < 1000) {
  15.             petty.setSpeed(petty.getSpeed() + petty.randomSpeedChange());
  16.             waltrip.setSpeed(waltrip.getSpeed() + petty.randomSpeedChange());
  17.  
  18.             if (petty.getLocation() > waltrip.getLocation()) {
  19.                 petty.decelerate();
  20.                 waltrip.accelerate();
  21.             } else if (waltrip.getLocation() > petty.getLocation()) {
  22.                 petty.accelerate();
  23.                 waltrip.decelerate();
  24.             }
  25.             petty.setLocation(petty.getLocation() + petty.getSpeed());
  26.             waltrip.setLocation(waltrip.getLocation() + waltrip.getSpeed());
  27.  
  28.             if (petty.getLocation() >= (waltrip.getLocation() + 100)
  29.                     && petty.getLocation() < 1000) {
  30.                 System.out.println(petty.getName()
  31.                         + " has a commanding lead!  He leads "
  32.                         + waltrip.getName() + " by "
  33.                         + (petty.getLocation() - waltrip.getLocation())
  34.                         + " units. " + petty.getName() + " is at marker "
  35.                         + petty.getLocation() + " . " + petty.getName()
  36.                         + " is zipping along at " + petty.getSpeed() + " UPH!");
  37.             } else if (petty.getLocation() >= (waltrip.getLocation() + 50)
  38.                     && petty.getLocation() < (waltrip.getLocation() + 100)
  39.                     && petty.getLocation() < 1000) {
  40.                 System.out.println(petty.getName()
  41.                         + " is slightly leading against " + waltrip.getName()
  42.                         + " by "
  43.                         + (petty.getLocation() - waltrip.getLocation())
  44.                         + " units. " + petty.getName() + " is at marker "
  45.                         + petty.getLocation() + " . " + petty.getName()
  46.                         + " is moving along at " + petty.getSpeed() + " UPH.");
  47.             } else if (petty.getLocation() > waltrip.getLocation()
  48.                     && petty.getLocation() < (waltrip.getLocation() + 50)
  49.                     && petty.getLocation() < 1000) {
  50.                 System.out.println(petty.getName()
  51.                         + " is barely leading against " + waltrip.getName()
  52.                         + "  at the " + petty.getLocation() + " mark."
  53.                         + petty.getName() + " is moving at " + petty.getSpeed()
  54.                         + " UPH.");
  55.             } else if (waltrip.getLocation() >= (petty.getLocation() + 100)
  56.                     && waltrip.getLocation() < 1000) {
  57.                 System.out.println(waltrip.getName() + " is punishing "
  58.                         + petty.getName() + " by "
  59.                         + (waltrip.getLocation() - petty.getLocation())
  60.                         + " units! " + waltrip.getName() + " is at marker "
  61.                         + waltrip.getLocation() + " . " + waltrip.getName()
  62.                         + " has got the hammer down at " + petty.getSpeed()
  63.                         + " UPH!");
  64.             } else if (waltrip.getLocation() >= (petty.getLocation() + 50)
  65.                     && waltrip.getLocation() < (petty.getLocation() + 100)
  66.                     && waltrip.getLocation() < 1000) {
  67.                 System.out.println(waltrip.getName() + " has a decent lead on "
  68.                         + petty.getName() + " by "
  69.                         + (waltrip.getLocation() - petty.getLocation())
  70.                         + " units. " + waltrip.getName() + " is at marker "
  71.                         + waltrip.getLocation() + " . " + waltrip.getName()
  72.                         + " is moving at a good pace of " + petty.getSpeed()
  73.                         + " UPH.");
  74.             } else if (waltrip.getLocation() > petty.getLocation()
  75.                     && waltrip.getLocation() < (petty.getLocation() + 50)
  76.                     && waltrip.getLocation() < 1000) {
  77.                 System.out.println(waltrip.getName() + " has a small lead on "
  78.                         + petty.getName() + " by "
  79.                         + (waltrip.getLocation() - petty.getLocation())
  80.                         + " units. " + waltrip.getName() + " is at marker "
  81.                         + waltrip.getLocation() + " . " + waltrip.getName()
  82.                         + " had better raise his speed of " + petty.getSpeed()
  83.                         + " UPH if he hopes to keep this lead.");
  84.             } else if (waltrip.getLocation() == petty.getLocation()
  85.                     && waltrip.getLocation() < 1000) {
  86.                 System.out.println("They are tied in a dead heat at marker "
  87.                         + petty.getLocation() + "! Petty is moving along at "
  88.                         + petty.getSpeed() + " UPH.  Waltrip is traveling at "
  89.                         + waltrip.getSpeed() + " UPH.");
  90.             }
  91.  
  92.         }
  93.  
  94.         if (petty.getLocation() >= 1000
  95.                 && petty.getLocation() > waltrip.getLocation()) {
  96.             System.out.println(petty.getName() + " wins the race against "
  97.                     + waltrip.getName() + "! " + petty.getName()
  98.                     + " finished at a speed of " + petty.getSpeed() + " UPH.");
  99.         } else {
  100.             System.out
  101.                     .println(waltrip.getName() + " wins the race against "
  102.                             + petty.getName() + "! " + waltrip.getName()
  103.                             + " finished at a speed of " + waltrip.getSpeed()
  104.                             + " UPH.");
  105.         }
  106.  
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement