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

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

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

__2275 2016-03-08 15:58:21
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容量"); }}}
查看完整描述

1 回答

?
森特

TA贡献1条经验 获得超0个赞


接下来可以用foreach把carsForRent中的数据打印出来,但是要考虑到车种类的不同显示“载客量”or“载人数”。

查看完整回答
反对 回复 2016-04-14
  • 1 回答
  • 0 关注
  • 1247 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信