Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Race {
- public static void main(String[] args) {
- Car petty = new Car("Richard Petty", 30);
- Car waltrip = new Car("Darrel Waltrip", 30);
- // System.out.println(petty);
- // petty.setSpeed(petty.getSpeed() + petty.randomSpeedChange());
- // System.out.println(petty);
- System.out
- .println("Out comes the green flag! Here we go race fans, it's the Great Race-Off between "
- + petty.getName() + " and " + waltrip.getName() + "!");
- while (petty.getLocation() < 1000 && waltrip.getLocation() < 1000) {
- petty.setSpeed(petty.getSpeed() + petty.randomSpeedChange());
- waltrip.setSpeed(waltrip.getSpeed() + petty.randomSpeedChange());
- if (petty.getLocation() > waltrip.getLocation()) {
- petty.decelerate();
- waltrip.accelerate();
- } else if (waltrip.getLocation() > petty.getLocation()) {
- petty.accelerate();
- waltrip.decelerate();
- }
- petty.setLocation(petty.getLocation() + petty.getSpeed());
- waltrip.setLocation(waltrip.getLocation() + waltrip.getSpeed());
- if (petty.getLocation() >= (waltrip.getLocation() + 100)
- && petty.getLocation() < 1000) {
- System.out.println(petty.getName()
- + " has a commanding lead! He leads "
- + waltrip.getName() + " by "
- + (petty.getLocation() - waltrip.getLocation())
- + " units. " + petty.getName() + " is at marker "
- + petty.getLocation() + " . " + petty.getName()
- + " is zipping along at " + petty.getSpeed() + " UPH!");
- } else if (petty.getLocation() >= (waltrip.getLocation() + 50)
- && petty.getLocation() < (waltrip.getLocation() + 100)
- && petty.getLocation() < 1000) {
- System.out.println(petty.getName()
- + " is slightly leading against " + waltrip.getName()
- + " by "
- + (petty.getLocation() - waltrip.getLocation())
- + " units. " + petty.getName() + " is at marker "
- + petty.getLocation() + " . " + petty.getName()
- + " is moving along at " + petty.getSpeed() + " UPH.");
- } else if (petty.getLocation() > waltrip.getLocation()
- && petty.getLocation() < (waltrip.getLocation() + 50)
- && petty.getLocation() < 1000) {
- System.out.println(petty.getName()
- + " is barely leading against " + waltrip.getName()
- + " at the " + petty.getLocation() + " mark."
- + petty.getName() + " is moving at " + petty.getSpeed()
- + " UPH.");
- } else if (waltrip.getLocation() >= (petty.getLocation() + 100)
- && waltrip.getLocation() < 1000) {
- System.out.println(waltrip.getName() + " is punishing "
- + petty.getName() + " by "
- + (waltrip.getLocation() - petty.getLocation())
- + " units! " + waltrip.getName() + " is at marker "
- + waltrip.getLocation() + " . " + waltrip.getName()
- + " has got the hammer down at " + petty.getSpeed()
- + " UPH!");
- } else if (waltrip.getLocation() >= (petty.getLocation() + 50)
- && waltrip.getLocation() < (petty.getLocation() + 100)
- && waltrip.getLocation() < 1000) {
- System.out.println(waltrip.getName() + " has a decent lead on "
- + petty.getName() + " by "
- + (waltrip.getLocation() - petty.getLocation())
- + " units. " + waltrip.getName() + " is at marker "
- + waltrip.getLocation() + " . " + waltrip.getName()
- + " is moving at a good pace of " + petty.getSpeed()
- + " UPH.");
- } else if (waltrip.getLocation() > petty.getLocation()
- && waltrip.getLocation() < (petty.getLocation() + 50)
- && waltrip.getLocation() < 1000) {
- System.out.println(waltrip.getName() + " has a small lead on "
- + petty.getName() + " by "
- + (waltrip.getLocation() - petty.getLocation())
- + " units. " + waltrip.getName() + " is at marker "
- + waltrip.getLocation() + " . " + waltrip.getName()
- + " had better raise his speed of " + petty.getSpeed()
- + " UPH if he hopes to keep this lead.");
- } else if (waltrip.getLocation() == petty.getLocation()
- && waltrip.getLocation() < 1000) {
- System.out.println("They are tied in a dead heat at marker "
- + petty.getLocation() + "! Petty is moving along at "
- + petty.getSpeed() + " UPH. Waltrip is traveling at "
- + waltrip.getSpeed() + " UPH.");
- }
- }
- if (petty.getLocation() >= 1000
- && petty.getLocation() > waltrip.getLocation()) {
- System.out.println(petty.getName() + " wins the race against "
- + waltrip.getName() + "! " + petty.getName()
- + " finished at a speed of " + petty.getSpeed() + " UPH.");
- } else {
- System.out
- .println(waltrip.getName() + " wins the race against "
- + petty.getName() + "! " + waltrip.getName()
- + " finished at a speed of " + waltrip.getSpeed()
- + " UPH.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement