为了账号安全,请及时绑定邮箱和手机立即绑定

*求告知怎么得到总载人数和总租金!!!!

//答答租车系统

/*

  定义父类

 */

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
提交
取消

*求告知怎么得到总载人数和总租金!!!!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信