Last active
April 11, 2016 16:46
-
-
Save dante-byte/b1b886521788b02eab105a4a13ab9e98 to your computer and use it in GitHub Desktop.
Day 6 Homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.blue.camaro; | |
public class MuscleCar | |
{ | |
public String color; | |
public String make; | |
public String model; | |
public boolean isCarStarted = false; | |
int amountToAccelerateBy = 10; | |
int speed = 0; | |
int gasLevel = 10; | |
public MuscleCar() { | |
color = "Blue"; | |
make = "Camaro"; | |
model = "SuperSport"; | |
} | |
public MuscleCar(String inputColor, String inputMake, String inputModel) { | |
color = inputColor; | |
make = inputMake; | |
model = inputModel; | |
} | |
public void startCar() { | |
System.out.println("Starting your car! "); | |
isCarStarted = true; | |
} | |
public void accelerate() throws Exception { | |
if (gasLevel > 0 && isCarStarted) { | |
speed = speed + 5; | |
System.out.println("Your car accelerated 5 mph your speed is " + speed); | |
gasLevel = gasLevel -1; | |
System.out.println("Your car gas Leve is" + gasLevel); | |
} else { | |
throw new Exception(); | |
} | |
} | |
public void accelerate(int amountToAccelerateBy) { | |
System.out.println("What amount to accelerate by: " + amountToAccelerateBy); | |
} | |
public void brake() { | |
System.out.println("Youre breaking"); | |
speed = speed - 1; | |
System.out.println("You are slowing down by 1 mph, your current speed is " + speed); | |
if (speed == 0) { | |
System.out.println("You are not moving "); | |
} | |
} | |
public void print() { | |
System.out.println(""); | |
System.out.println(model + color + make); | |
System.out.println("your gas leve is " + gasLevel); | |
System.out.println("Youre driving at " + speed); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.blue.camaro; | |
import java.util.Scanner; | |
public class RunnerMuscleCar { | |
public static void main(String[] args) { | |
System.out.println("Running ..."); | |
//MuscleCar myMuscleCar = new MuscleCar(); | |
welcomeuser(); | |
} | |
public static void welcomeuser() { | |
System.out.println("Donta welcome to your dream car "); | |
System.out.println("What's the color of your car? "); | |
Scanner lineScanner = new Scanner(System.in); | |
String carColor = lineScanner.nextLine(); | |
System.out.println("Your car color is... " + carColor); | |
System.out.println("What's the make of your car? "); | |
String carMake = lineScanner.nextLine(); | |
System.out.println("The make of your car is " + carMake); | |
System.out.println("What's the model of your car? "); | |
String carModel = lineScanner.nextLine(); | |
System.out.println("The model of your car is " + carModel); | |
MuscleCar userCar = new MuscleCar(carColor, carMake, carModel); | |
userCar.print(); | |
System.out.println("What would like to do with your car " ); | |
for (int counter = 0; counter < 100; counter++) | |
{ | |
System.out.println("There are 6 options - choose one "); | |
System.out.println("Options 1 - Start the car "); | |
System.out.println("Options 2 - Stop the car "); | |
System.out.println("Options 3 - Accelerate "); | |
System.out.println("Options 4 - Break "); | |
System.out.println("Options 5 - Print Info "); | |
System.out.println("Options 6 - Exit "); | |
System.out.println("Options 7 - Drive faster"); | |
String userCommandChoice = lineScanner.nextLine(); | |
System.out.println("The user chose option " + userCommandChoice); | |
boolean userChoseOptionOne = userCommandChoice.equals("1"); | |
boolean userChoseOptionTwo = userCommandChoice.equals("2"); | |
boolean userChoseOptionThree = userCommandChoice.equals("3"); | |
boolean userChoseOptionFour = userCommandChoice.equals("4"); | |
boolean userChoseOptionFive = userCommandChoice.equals("5"); | |
boolean userChoseOptionSix = userCommandChoice.equals("6"); | |
boolean userchoseOptionSeven = userCommandChoice.equals("7"); | |
if (userChoseOptionOne) { | |
System.out.println("Your car has started"); | |
userCar.startCar(); | |
} | |
if (userChoseOptionTwo) { | |
System.out.println("Stooooop not so fast"); | |
} | |
if (userChoseOptionThree) { | |
System.out.println("accelerate"); | |
try { | |
userCar.accelerate(); | |
} catch (Exception exception) { | |
System.out.println("You cannot accelerate without starting first!"); | |
} | |
} | |
if (userChoseOptionFour) { | |
System.out.println("breaking"); | |
userCar.brake(); | |
} | |
if (userChoseOptionFive) { | |
System.out.println("Here are your stats"); | |
userCar.print(); | |
System.out.println("The make of your car is " + carMake); | |
System.out.println("The model of your car is " + carModel); | |
System.out.println("The color of your car is " + carColor); | |
} | |
if (userChoseOptionSix) { | |
System.out.println("Ok I'll see you the next time"); | |
break; | |
} | |
if (userchoseOptionSeven) { | |
System.out.println("enter the amount that you would like to accelerate by"); | |
Scanner sc = new Scanner(System.in); | |
int amount = sc.nextInt(); | |
userCar.accelerate(amount); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment