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

有谁知道main方法中这个载货量或者载重量如何输出显示出来?System.out.println(car.getNo()+"号车,"+car.getName()+",一天租价格:"+car.getPrice()+",载客量:");

Car.java代码

public class Car {

private int no;

private String name;

private double price;

public int getNo() {

return no;

}



public void setNo(int no) {

this.no = no;

}



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 Car(int no, String name, double price) {

super();

this.no = no;

this.name = name;

this.price = price;

}



public Car() {

super();

}


}


PassengerCar .java代码

public class PassengerCar extends Car {

private double passengerCability;


public double getPassengerCability() {

return passengerCability;

}


public void setPassengerCability(double passengerCability) {

this.passengerCability = passengerCability;

}


public PassengerCar(int no, String name, double price,

double passengerCability) {

super(no, name, price);

this.passengerCability = passengerCability;

}

}





import java.util.Scanner;


public class Initinal {

public static void main(String[] args) {

Car c1 = new PassengerCar(1,"班车",200.0,20);

Car c2 = new PassengerCar(2,"客车",350.5,35);

Car c3 = new Trunk(3,"大货车",500.0,5);

Car c4 = new Trunk(4,"小货车",300.0,3);

Car c5 = new PickUp(5,"皮卡车",250.0,10,2);

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

System.out.println("你要租车吗?租车输入1,否则输入0:");

Scanner scan = new Scanner(System.in);

String choice = scan.next();

if("1".equals(choice)){

System.out.println("现在所有的车辆有:");

for(Car car:carAll){

if(car instanceof PassengerCar){

System.out.println(car.getNo()+"号车,"+car.getName()+",一天租价格:"+car.getPrice()+",载客量:");

}

if(car instanceof Trunk){

System.out.println(car.getNo()+"号车,"+car.getName()+",一天租价格:"+car.getPrice()+",载货量:");

}

if(car instanceof PickUp){

System.out.println(car.getNo()+"号车,"+car.getName()+",一天租价格:"+car.getPrice()+",载客量:"+",载货量:");

}

}

System.out.println("请输入您要租车的数量:");

int num = scan.nextInt();

int[] nums = new int[num];

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

System.out.println("请选择您要选择租的车的序号:");

nums[i] = scan.nextInt();

}

double sum =0;

System.out.println("您的账单如下:");

for(Car car:carAll){

for(int numAll:nums){

if(car.getNo()==numAll){

System.out.println(car.getNo()+"号车,"+car.getName()+",一天租价格:"+car.getPrice());

sum+=car.getPrice();

}

}

}

System.out.println("总价格为:"+sum+"元");

}else{

System.out.println("谢谢使用!");

}

}


}


正在回答

1 回答

没看懂你的问题是要干什么啊

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

举报

0/150
提交
取消

有谁知道main方法中这个载货量或者载重量如何输出显示出来?System.out.println(car.getNo()+"号车,"+car.getName()+",一天租价格:"+car.getPrice()+",载客量:");

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