2016-10-13 58 views
1

我在Java中有點生疏,沒有爲這樣的年齡編程任何東西。我嘗試創建一個簡單的停車場管理器程序並實現以下類車輛和子類Car,Van ,摩托車(擴展車輛類別),汽車類別應包含關於車門數量和顏色的信息,範類應包括有關貨車貨物體積的信息,摩托車類應包含有關發動機的信息大小,該程序應允許將車輛添加到停車場,刪除車輛並打印目前停放的車輛列表,並提供停放的車輛是汽車車或貨車的信息,但我設計了所有課程。用戶在此輸入。用戶在添加車輛時應允許輸入汽車自行車或貨車型號,登記牌,車輛顏色,以及n門。並且程序應該在選擇相應的菜單選項時打印信息。你能看看我到目前爲止的代碼,任何幫助將不勝感激。我的問題是讓用戶輸入所有請求的信息。簡單的Java停車場管理系統

public class Vehicle { 

    private String carBrand; 
    private String regPlate; 

    // default constructor 
    public Vehicle() { 
    } 

    // constructor 
    public Vehicle(String carBrand, String regPlate) { 
     this.carBrand = carBrand; 
     this.regPlate = regPlate; 
    } 

    //getters 
    public String getCarBrand() { 
     return carBrand; 
    } 

    public String getRegPlate() { 
     return regPlate; 
    } 

    //setters 
    public void setCarBrand(String carBrand) { 
     this.carBrand = carBrand; 
    } 

    public void setColor(String regPlate) { 
     this.regPlate = regPlate; 
    } 
} 

...

public class Main { 

    public static void main(String[] args) { 
     CarParkManager myCarPark = new CarParkManager(); 

     Scanner input = new Scanner(System.in); 
     int menu; 
     String model; 

     do { 
      System.out.println("WELCOME TO PARKING MANAGEMENT"); 
      System.out.println("1: To Park Vehicle"); 
      System.out.println("2: To Departure"); 
      System.out.println("3: Show All Perked Vehicles"); 
      System.out.println("0: To Exit"); 

      System.out.print("Enter your choice: "); 

      menu = input.nextInt(); 
      System.out.println(); 

      switch (menu) { 
       case 1: { 
        String vType; 

        System.out.println("Please choose The Vehicle type"); 
        System.out.println("C = Car"); 
        System.out.println("B = Motorbike"); 
        System.out.println("V = VAN"); 
        vType = input.next(); 
        if (vType.equals("C")) { 
         System.out.println("Enter Model"); 
         model = input.next(); 

         System.out.println("Enter Colour"); 
         String colour = input.next(); 

         System.out.println("Enter Reg Plate"); 
         String regPlate = input.next(); 

         System.out.println("Door Number"); 
         int doorNumber = input.nextInt(); 

        } else if (vType.equals("B")) { 

        } else if (vType.equals("V")) { 

        } 

        break; 
       } 
       case 2: { 

        break; 
       } 
       case 3: { 
        System.out.println("List of All Parked Vehicles : "); 
        myCarPark.printParkedVehicleDetails(); 

        break; 
       } 

       case 0: { 
        System.out.println("\nThank you!\n"); 
        break; 
       } 
       default: { 
        System.out.println("Invalid option!\n"); 
        break; 
       } 
      } 
     } while (menu != 0); 

    } 
} 

回答

3
  1. 問用戶他們想要創建
  2. 對車輛創建一個給定類型Vehcle
  3. 呼叫getDetailsFromUser什麼類型的車輛

特定的小類(範等)可以詢問用戶他們需要什麼樣的問題才能填充自己。