亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

做得不好,沒用到接口。

package com.yesijie;

import java.util.Scanner;

public class Mainprogram {


public static void main(String[] args) {

// TODO Auto-generated method stub

? ? ? ? ? ?Welcome welcome=new Welcome();

? ? ? ? ? ?welcome.welPrint();

? ? ? ? ? ?welcome.choose();

? ? ? ? ? ?

? ? ? ? ? ?

? ? ? ? ? ?Salooncar jianianhua=new Salooncar();

? ? ? ? ? ?jianianhua.setPassengerNum(5);

? ? ? ? ? ?jianianhua.setName("嘉年華");

? ? ? ? ? ?jianianhua.setInventory(12);

? ? ? ? ? ?jianianhua.setPrice(120);

? ? ? ? ? ?jianianhua.setCargoWeight(0);

? ? ? ? ? ?

? ? ? ? ? ?Salooncar leikesasi=new Salooncar();

? ? ? ? ? ?leikesasi.setPassengerNum(4);

? ? ? ? ? ?leikesasi.setName("雷克薩斯");

? ? ? ? ? ?leikesasi.setInventory(5);

? ? ? ? ? ?leikesasi.setPrice(270);

? ? ? ? ? ?leikesasi.setCargoWeight(0);

? ? ? ? ? ?

? ? ? ? ? ?Truck jinbei=new Truck();

? ? ? ? ? ?jinbei.setCargoWeight(10);

? ? ? ? ? ?jinbei.setName("金杯");

? ? ? ? ? ?jinbei.setInventory(12);

? ? ? ? ? ?jinbei.setPrice(90);

? ? ? ? ? ?jinbei.setPassengerNum(0);

? ? ? ? ? ?

? ? ? ? ? ?Truck lishi=new Truck();

? ? ? ? ? ?lishi.setCargoWeight(15);

? ? ? ? ? ?lishi.setName("力獅");

? ? ? ? ? ?lishi.setInventory(3);

? ? ? ? ? ?lishi.setPrice(110);

? ? ? ? ? ?lishi.setPassengerNum(0);

? ? ? ? ? ?

? ? ? ? ? ?Picard daoqi=new Picard();

? ? ? ? ? ?daoqi.setPassengerNum(4);

? ? ? ? ? ?daoqi.setCargoWeight(5);

? ? ? ? ? ?daoqi.setName("道奇");

? ? ? ? ? ?daoqi.setInventory(4);

? ? ? ? ? ?daoqi.setPrice(240);

? ? ? ? ? ?

? ? ? ? ? ?Cars cars=new Cars();

? ? ? ? ? ?Cars []carType={jianianhua,leikesasi,jinbei,lishi,daoqi};

? ? ? ? ? ?

? ? ? ? ? ?System.out.println("序號 ? ? ?車型 ? ? ?載客量/載貨量 ? ? 庫存 ? ? 租金");

? ? ? ? ? ?for(int i=0;i<carType.length;i++){//output the information

? ? ? ? ? ? ? ?if(carType[i].getCargoWeight()==0){

? ? ? ? ? ? ? ? System.out.println((i+1)+" ? ? "+carType[i].getName()+" ? ? ? ? "+

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getPassengerNum()+"人 ? ? ? ?"+

? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getInventory()+" ? ? "+

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getPrice());

? ? ? ? ? ? ? ?}//end if

? ? ? ? ? ? ? ?else if(carType[i].getPassengerNum()==0){

? ? ? ? ? ? ? ? System.out.println((i+1)+" ? ? "+carType[i].getName()+" ? ? ? ? "+

? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getCargoWeight()+"噸 ? ? ? ?"+

? ? ? ? ? ? ? ?carType[i].getInventory()+" ? ? "+

? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getPrice());

? ? ? ? ? ? ? ?}//end else if

? ? ? ? ? ? ? ?else {

? ? ? ? ? ? ? ? System.out.println((i+1)+" ? ? "+carType[i].getName()+" ? ? ? ? "+

? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getPassengerNum()+"人"+carType[i].getCargoWeight()

? ? ? ? ? ? ? ? ? ? ? ? ? ?+"噸 ? ? ? "+

? ? ? ? ? ? ? ?carType[i].getInventory()+" ? ? "+

? ? ? ? ? ? ? ? ? ? ? ? ? ?carType[i].getPrice());

? ? ? ? ? ? ? ?}//end else

? ? ? ? ? ?}//end for

? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ??

? ? int carsNumber1;

? ? int totalPeople=0;

? ? int totalWeight=0;

? ? int totalMoney=0;

? ? Scanner input=new Scanner(System.in);

? ? System.out.print("請輸入您需要的車輛數量:");

? ? int carNumber=input.nextInt(); //number of cars customer needs

? ??

? ??

? ?

? ? for(int i=0;i<carNumber;i++){

? ? System.out.println("請輸入第"+(i+1)+"倆車的序號:");

? ? carsNumber1=input.nextInt();

? ? System.out.println("請輸入需要租借的天數:");

? ? ? ? int days=input.nextInt();

? ? ? ? totalPeople+=carType[carsNumber1-1].getPassengerNum();

? ? ? ? totalWeight+=carType[carsNumber1-1].getCargoWeight();

? ? ? ? totalMoney+=carType[carsNumber1-1].getPrice()*days;

? ? }//end for

? ? System.out.println("您的總載人數為"+totalPeople+"人");

? ? System.out.println("您的總載貨量為"+totalWeight+"噸");

? ? System.out.println("您的總租金為"+totalMoney+"元");

? ? System.out.println("Thanks for choosing us!");

? ??? ??

}//end main()



}


//car類

package com.yesijie;


public class Cars {

private int passengerNum;

private int cargoWeight;

private int price;

private int inventory;

private String name;

public void setPassengerNum(int passengerNum){

this.passengerNum=passengerNum;

? ? }

public int getPassengerNum(){

return passengerNum;

}

public void setCargoWeight(int cargoWeight){

this.cargoWeight=cargoWeight;

? ? }

public int getCargoWeight(){

return cargoWeight;

? ? }

public void setPrice(int price){

this.price=price;

? ? }

public int getPrice(){

return price;

? ? }

public void setInventory(int inventory){

this.inventory=inventory;

? ? }

public int getInventory(){

return inventory;

? ? }

public void setName(String name){

this.name=name;

? ? }

public String getName(){

return name;

? ? }

}


//皮卡子類

package com.yesijie;


public class Picard extends Cars {


}



//轎車類

package com.yesijie;


public class Salooncar extends Cars {

? ? ??

? ? ??

}



//貨車類

package com.yesijie;


public class Truck extends Cars {


}



//歡迎界面

package com.yesijie;

import java.util.Scanner;


public class Welcome {

public void welPrint(){

System.out.println("歡迎使用達達租車系統!");

System.out.println("請輸入數字選擇:1.進入系統 ? 2.離開系統");

}

? ? public void choose(){

? ? Scanner input=new Scanner(System.in);

? ? int i=input.nextInt();//輸入的數字

? ? if(i==1){

? ? System.out.print("請輸入姓名:");

? ? String name=input.next();

? ? System.out.print("請輸入您的性別:1.男士 ? ?2.女士");

? ? int sex=input.nextInt();

? ? if(sex==1){

? ? System.out.println("歡迎"+name+"先生"+"使用達達租車系統");

? ? }

? ? else if(sex==2){

? ? System.out.println("歡迎"+name+"女士"+"使用達達租車系統");

? ? }

? ? else {

? ? System.out.println("請輸入正確的性別!");

? ? welPrint();

? ? choose(); ? ?

? ? }// end else

? ?

? ? }// end if

? ? else if(i==2){

? ? System.out.println("再見!");

? ? }

? ? else{

? ? System.out.println("請輸入正確的數字:");

? ? welPrint();

? ? choose();

? ? }//end else

? ? }//end choose

? ??

? ??

}//end class Welcome

? ? ? ??

? ? ?



正在回答

1 回答

還好吧,,并不復雜

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

做得不好,沒用到接口。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號