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

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

*求告知怎么得到總載人數和總租金?。。。?/h1>

//答答租車系統

/*

? 定義父類

?*/

package com.sy.interfaces.dada;


public class Car {

int id;

String name;

double price;

int peopleNum;

double capacity;

public Car() {


}

public Car(int id, String name, double price, int peopleNum, double capacity) {

super();

this.id = id;

this.name = name;

this.price = price;

this.peopleNum = peopleNum;

this.capacity = capacity;

}


public void setId(int id) {

this.id = id;

}

public int getId() {

return id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public void getInfo() {

System.out.println(id + "." + "\t" + name + "\t" + price + "元/天");

}

public int getPeopleNum() {

// TODO Auto-generated method stub

return 0;

}

public double getCapacity() {

return capacity;

}

public void setCapacity(double capacity) {

this.capacity = capacity;

}

public void setPeopleNum(int peopleNum) {

this.peopleNum = peopleNum;

}

}

/*

? 定義子類PiKa

?*/


package com.sy.interfaces.dada;


public? class PiKa extends Car {

public PiKa(int id, String name, int price, int peopleNum, int capacity) {

super(id, name, price, peopleNum, capacity);

}

public void getInfo() {

System.out.println(id + "." + "\t" + name + "\t" + price + "元/天" + "天\t載客量:" + peopleNum + "人"

+ "載貨量:" + capacity + "噸");

}

}

/*

? 定義子類Bus

?*/


package com.sy.interfaces.dada;


public class Bus extends Car {

public Bus(int id,String name,double price,int peopleNum) {

this.id = id;

this.name = name;

this.price = price;

this.peopleNum = peopleNum;

}

public void getInfo() {

System.out.println(id + "." + "\t" + name + "\t" + price + "元/天\t載客量:" + peopleNum + "人");

}


}

/*

? 定義子類CaChe

?*/


package com.sy.interfaces.dada;


public class CaChe extends Car {

public CaChe(int id,String name,double price,double capacity) {

this.id = id;

this.name = name;

this.price = price;

this.capacity = capacity;

}

public void getInfo() {

System.out.println(id + "." + "\t" + name + "\t" + price + "元/天\t載貨量:" + capacity + "噸");

}

}

/*

? 測試類

?*/

package com.sy.interfaces.dada;


import java.util.*;


import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;


public class TestDada {


public static void main(String[] args) {

Car c1 = new Bus(1,"奧迪A4",500,4);

Car c2 = new Bus(2,"馬自達6",400,4);

Car c3 = new PiKa(3,"皮卡雪6",450,4,2);

Car c4 = new Bus(4,"金龍",800,20);

Car c5 = new CaChe(5,"松花江",400,4);

Car c6 = new CaChe(6,"依維柯",1000,20);

Car[] cars = {c1,c2,c3,c4,c5,c6};

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

System.out.println("您是否要租車:1是 0否");

Scanner input = new Scanner(System.in);

int ifRent = input.nextInt();

if(ifRent == 1) {

System.out.println("您可租車的類型及價目表:");

System.out.println("序號\t汽車名稱\t租金\t\t容量");

c1.getInfo();

c2.getInfo();

c3.getInfo();

c4.getInfo();

c5.getInfo();

c6.getInfo();

}else if(ifRent == 0) {

System.out.println("*****系統正在退出*****");

}else {

System.out.println("請輸入1(是)/0(否)");

}

System.out.println("請輸入您要租汽車的數量:");

Scanner input2 = new Scanner(System.in);

int num = input2.nextInt();

Car[] zCar = new Car[num];

double sumPrice=0;

int sumPeople=0;

double sumCapacity=0;

for(int m = 0;m < num;m++) {

System.out.println("請輸入第" + (m + 1) + "輛車的序號:");

Scanner input3 = new Scanner(System.in);

int xuhao = input3.nextInt();

zCar[m] = cars[xuhao - 1];

System.out.println("請輸入租車天數:");

Scanner input4 = new Scanner(System.in);

int days = input4.nextInt();

double prices = cars[xuhao - 1].getPrice() * days;

sumPrice += prices;

int peoples = cars[xuhao - 1].getPeopleNum();

sumPeople += peoples;

double capacitys = cars[xuhao - 1].getCapacity();

sumCapacity += capacitys;

}

System.out.println("》》》》您的賬單如下《《《《");

System.out.println("一共租車" + num + "輛");

System.out.println("可載" + sumPeople + "人");

System.out.println("可載" + sumCapacity + "噸");

System.out.println("您需要支付" + num + "元");

System.out.println("感謝本次使用!歡迎再次使用本公司答答租車系統!");

}

}




******歡迎使用答答租車系統******

您是否要租車:1是 0否

1

您可租車的類型及價目表:

序號 汽車名稱 租金 容量

1. 奧迪A4 500.0元/天 載客量:4人

2. 馬自達6 400.0元/天 載客量:4人

3. 皮卡雪6 450.0元/天 載客量:4人載貨量:2.0噸

4. 金龍 800.0元/天 載客量:20人

5. 松花江 400.0元/天 載貨量:4.0噸

6. 依維柯 1000.0元/天 載貨量:20.0噸

請輸入您要租汽車的數量:

3

請輸入第1輛車的序號:

1

請輸入租車天數:

2

請輸入第2輛車的序號:

3

請輸入租車天數:

1

請輸入第3輛車的序號:

5

請輸入租車天數:

4

》》》》您的賬單如下《《《《

一共租車3輛

可載0人

可載6.0噸

您需要支付3元

感謝本次使用!歡迎再次使用本公司答答租車系統!


正在回答

1 回答

本人小白,剛學java一個月,求大神給出詳細解釋。。。

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

四月kkk 提問者

是我自己智障了!?。∥易约旱母愣?但還是希望大神能給出簡單的方法
2019-05-18 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531144    人
  • 解答問題       6326    個

課程升級!以終為始告別枯燥,在開發和重構中體會Java面向對象編程的奧妙

進入課程

*求告知怎么得到總載人數和總租金!?。?!

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

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

幫助反饋 APP下載

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

公眾號

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