*求告知怎么得到總載人數(shù)和總租金!?。?!
//答答租車(chē)系統(tǒng)
/*
? 定義父類(lèi)
?*/
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;
}
}
/*
? 定義子類(lèi)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 + "噸");
}
}
/*
? 定義子類(lèi)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 + "人");
}
}
/*
? 定義子類(lèi)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 + "噸");
}
}
/*
? 測(cè)試類(lèi)
?*/
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,"馬自達(dá)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("******歡迎使用答答租車(chē)系統(tǒng)******");
System.out.println("您是否要租車(chē):1是 0否");
Scanner input = new Scanner(System.in);
int ifRent = input.nextInt();
if(ifRent == 1) {
System.out.println("您可租車(chē)的類(lèi)型及價(jià)目表:");
System.out.println("序號(hào)\t汽車(chē)名稱(chēng)\t租金\t\t容量");
c1.getInfo();
c2.getInfo();
c3.getInfo();
c4.getInfo();
c5.getInfo();
c6.getInfo();
}else if(ifRent == 0) {
System.out.println("*****系統(tǒng)正在退出*****");
}else {
System.out.println("請(qǐng)輸入1(是)/0(否)");
}
System.out.println("請(qǐng)輸入您要租汽車(chē)的數(shù)量:");
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("請(qǐng)輸入第" + (m + 1) + "輛車(chē)的序號(hào):");
Scanner input3 = new Scanner(System.in);
int xuhao = input3.nextInt();
zCar[m] = cars[xuhao - 1];
System.out.println("請(qǐng)輸入租車(chē)天數(shù):");
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("一共租車(chē)" + num + "輛");
System.out.println("可載" + sumPeople + "人");
System.out.println("可載" + sumCapacity + "噸");
System.out.println("您需要支付" + num + "元");
System.out.println("感謝本次使用!歡迎再次使用本公司答答租車(chē)系統(tǒng)!");
}
}
******歡迎使用答答租車(chē)系統(tǒng)******
您是否要租車(chē):1是 0否
1
您可租車(chē)的類(lèi)型及價(jià)目表:
序號(hào) 汽車(chē)名稱(chēng) 租金 容量
1. 奧迪A4 500.0元/天 載客量:4人
2. 馬自達(dá)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噸
請(qǐng)輸入您要租汽車(chē)的數(shù)量:
3
請(qǐng)輸入第1輛車(chē)的序號(hào):
1
請(qǐng)輸入租車(chē)天數(shù):
2
請(qǐng)輸入第2輛車(chē)的序號(hào):
3
請(qǐng)輸入租車(chē)天數(shù):
1
請(qǐng)輸入第3輛車(chē)的序號(hào):
5
請(qǐng)輸入租車(chē)天數(shù):
4
》》》》您的賬單如下《《《《
一共租車(chē)3輛
可載0人
可載6.0噸
您需要支付3元
感謝本次使用!歡迎再次使用本公司答答租車(chē)系統(tǒng)!
2019-05-18
本人小白,剛學(xué)java一個(gè)月,求大神給出詳細(xì)解釋。。。