猿问

往下不知道咋写啦,请帮忙看下,答答租车系统

package com.imooc.zuche;


import java.util.Scanner;


class passengerCar extends Car{//载客车

private double peopleCapacity;

public passengerCar(String name,double rent,double peopleCapacity){

this.name=name;

this.rent=rent;

this.peopleCapacity=peopleCapacity;

}

public double getPeopleCapacity() {

return peopleCapacity;

}

public void setPeopleCapacity(double peopleCapacity) {

this.peopleCapacity = peopleCapacity;

}

}

class PickUp extends Car{//皮卡

private double cargoCapacity;//载客量

private double peopleCapacity;//载货量

public PickUp(String name,double rent,double cargoCapacity,double peopleCapacity){

this.name=name;

this.rent=rent;

this.cargoCapacity=cargoCapacity;

this.peopleCapacity=peopleCapacity;

}

public double getCargoCapacity() {

return cargoCapacity;

}

public void setCargoCapacity(double cargoCapacity) {

this.cargoCapacity = cargoCapacity;

}

public double getPeopleCapacity() {

return peopleCapacity;

}

public void setPeopleCapacity(double peopleCapacity) {

this.peopleCapacity = peopleCapacity;

}

}

class Truck extends Car{//货车

private double cargoCapacity;

public Truck(String name,double rent,double cargoCapacity){

this.name=name;

this.rent=rent;

this.cargoCapacity=cargoCapacity;

}

public double getCargoCapacity() {

return cargoCapacity;

}

public void setCargoCapacity(double cargoCapacity) {

this.cargoCapacity = cargoCapacity;

}

}

class tes{


public static void main(String[] args) {

Car[] carsForRent={//定义车辆类型

new passengerCar("奥迪A4",500,4),

new passengerCar("马自达6",400,4),

new PickUp("皮卡6",450,4,2),

new Truck("松花江",400,4),

new Truck("斯太尔",1000,20)

};

System.out.println("欢迎使用答答租车系统");

System.out.println("您是否要租车:1.租车  2.退出");

Scanner scan=new Scanner(System.in);

String input=scan.next();

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

System.out.println("您可租车的类型及其价目表");

System.out.println("序号\t名称\t租金\t容量");

}

}

}


__2275
浏览 1249回答 1
1回答

森特

接下来可以用foreach把carsForRent中的数据打印出来,但是要考虑到车种类的不同显示“载客量”or“载人数”。
随时随地看视频慕课网APP

相关分类

Java
我要回答