Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170706;
- import java.util.Scanner;
- public class CarTester {
- public static void main(String[] args) {
- // create a scanner
- Scanner s = new Scanner(System.in);
- // create a new car
- Car myCar = new Car();
- System.out.printf("default car was created: %s\n\n", myCar);
- do {
- System.out.print("Enter car Number: ");
- } while (!myCar.setCarNumber(s.nextInt()));
- System.out.printf("car number was updated successfuly to: %d\n",
- myCar.getCarNumber());
- int targetSpeed;
- System.out
- .print("Enter target speed (positive=forward , negative=backword: ");
- targetSpeed = s.nextInt();
- System.out.println("\ncar start moving . . .");
- if (targetSpeed > 0) {
- // start moving forward
- myCar.accelerate();
- } else {
- // start moving backward
- myCar.decelerate();
- }
- System.out.printf("car is accelerating: %s\n", myCar);
- // continue moving
- for (int i = 1; i < Math.abs(targetSpeed); i += 1) {
- // speed up in the same direction
- myCar.accelerate();
- System.out.printf("car is accelerating: %s\n", myCar);
- }
- // decelerating 2km/h
- System.out.println("\nstart decelerating 2 km/h . . .");
- myCar.decelerate();
- System.out.printf("car is decelerating: %s\n", myCar);
- myCar.decelerate();
- System.out.printf("car is decelerating: %s\n", myCar);
- // stop the car
- myCar.stop();
- System.out.printf("\ncar has stopped %s\n", myCar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement