Advertisement
Epi-Pdo

VehicleSystem

Oct 22nd, 2020
2,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class VehicleSystem {
  5.  
  6.     public static void main(String [] args){
  7.         int i=0;
  8.         Scanner input = new Scanner(System.in);  // Create a Scanner object
  9.         StreetRacer street=new StreetRacer();
  10.         FormulaOne f1=new FormulaOne();
  11.         Aircraft aircraft=new Aircraft();
  12.      
  13.         while(i!=4) {
  14.             System.out.println("Type 1 for StreetRacer, 2 for FormulaOne, 3 for AirCraft, 4 to exit: ");
  15.             i=input.nextInt();
  16.  
  17.             //print default behavior for vehicle
  18.             if(i==1) {
  19.                 street.Display();
  20.                 street.performMove();
  21.             }
  22.             else if(i==2){
  23.                 f1.Display();
  24.                 f1.performMove();
  25.             }
  26.             else if(i==3){
  27.                 aircraft.Display();
  28.                 aircraft.performMove();
  29.             }
  30.             else {
  31.                 System.out.println("Invalid choice of type of vehicle. Try again");
  32.             }
  33.  
  34.             while(i==1){
  35.                 System.out.println();
  36.                 System.out.println("Type 1 if you want me to drive, 2 to fly, 3 to exit choosing my moving behavior: ");
  37.                 int inputbehavior=input.nextInt();
  38.                 if(inputbehavior==1){
  39.                     street.Display();
  40.                     street.setBehavior(new Driving());
  41.                     street.performMove();
  42.                 }
  43.                 else if(inputbehavior==2){
  44.                     street.Display();
  45.                     System.out.print("I cant fly");
  46.                 }
  47.                 else if(inputbehavior==3){
  48.                     i=0;//
  49.                 }
  50.                 else {
  51.                     System.out.println("Invalid choice of behavior. Try again");
  52.                 }
  53.             }
  54.  
  55.             while(i==2){
  56.                 System.out.println();
  57.                 System.out.println("Type 1 if you want me to drive, 2 to fly, 3 to exit choosing my moving behavior: ");
  58.                 int inputbehavior=input.nextInt();
  59.                 if(inputbehavior==1){
  60.                     f1.Display();
  61.                     f1.setBehavior(new Driving());
  62.                     f1.performMove();
  63.                 }
  64.                 else if(inputbehavior==2){
  65.                     f1.Display();
  66.                     System.out.print("I cant fly");
  67.  
  68.                 }
  69.                 else if(inputbehavior==3){
  70.                     i=0;//
  71.                 }
  72.                 else {
  73.                     System.out.println("Invalid choice of behavior. Try again");
  74.                 }
  75.  
  76.             }
  77.  
  78.             while(i==3){
  79.                 System.out.println();
  80.                 System.out.println("Type 1 if you want me to drive, 2 to fly, 3 to exit choosing my moving behavior: ");
  81.                 int inputbehavior=input.nextInt();
  82.                 if(inputbehavior==1){
  83.                     aircraft.Display();
  84.                     aircraft.setBehavior(new Driving());
  85.                     aircraft.performMove();
  86.                 }
  87.                 else if(inputbehavior==2){
  88.                     aircraft.Display();
  89.                     aircraft.setBehavior(new Flying());
  90.                     aircraft.performMove();
  91.  
  92.                 }
  93.                 else if(inputbehavior==3){
  94.                     i=0;//
  95.                 }
  96.                 else {
  97.                     System.out.println("Invalid choice of behavior. Try again");
  98.                 }
  99.             }
  100.  
  101.  
  102.  
  103.  
  104.         }
  105.  
  106.  
  107.     }
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement