二嗨租车系统java_Java第二季-嗒嗒租车系统

import java.util.Scanner;

public class Test {

public static void main(String[] args){

Car[] cars = {new PassengerCar("奥迪A4",4,500),

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

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

new PassengerCar("金龙",20,800),

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

new Truck("依维合",20,100)};

Scanner input = new Scanner(System.in);

System.out.println("***您是否要租车 (任意数.是 0.否)");

int inp = input.nextInt();

if(inp != 0){

System.out.println("您可租车的类型和价格");

System.out.println("序号 汽车 名称 租金 功能");

for(int i=1;i

System.out.println("序号"+i+" "+cars[i-1].toString());

}

}else{

System.out.println("欢迎下次再来");

System.exit(0);

}

System.out.println("预定数量");

int num = input.nextInt();//编号

int passengerSum = 0; //载客人数

int priceSum = 0; //价钱

int tonnageSum = 0; //拉货吨数

for(int i=1;i

System.out.println("请输入第"+i+"辆要预定车辆的序号");

int on=input.nextInt();

passengerSum += cars[i-1].getPassenger() ;

priceSum += cars[i-1].getPrice();

tonnageSum += cars[i-1].getTonnage();

}

System.out.println("一共需要"+priceSum+"元/天"+" "+"共载货量:"+tonnageSum+"吨 "+"共载客量:"+ passengerSum+"人");

}

}

public abstract class Car {

private String name; //车名

private int number; //编号

private int passenger; //载客人数

private int price; //价钱

private int tonnage; //拉货吨数

/**

@return the name

*/

public String getName() {

return name;

}

/**

@param name the name to set

*/

public void setName(String name) {

this.name = name;

}

/**

@return the number

*/

public int getNumber() {

return number;

}

/**

@param number the number to set

*/

public void setNumber(int number) {

this.number = number;

}

/**

@return the passenger

*/

public int getPassenger() {

return passenger;

}

/**

@param passenger the passenger to set

*/

public void setPassenger(int passenger) {

this.passenger = passenger;

}

/**

@return the price

*/

public int getPrice() {

return price;

}

/**

@param price the price to set

*/

public void setPrice(int price) {

this.price = price;

}

/**

@return the tonnage

*/

public int getTonnage() {

return tonnage;

}

/**

@param tonnage the tonnage to set

*/

public void setTonnage(int tonnage) {

this.tonnage = tonnage;

}

}

public class PassengerCar extends Car {

public PassengerCar(String name, int passenger, int price) {

// TODO Auto-generated constructor stub

this.setName(name);

this.setPassenger(passenger);

this.setPrice(price);

}

public String toString() {

return this.getName()+"----"+this.getPrice()+"元/天---- 载客"+this.getPassenger()+"人"; }

}

public class PickUp extends Car {

public PickUp(String name, int passenger, int price) {

// TODO Auto-generated constructor stub

this.setName(name);

this.setPassenger(passenger);

this.setPrice(price);

}

public PickUp(String name, int passenger, int tonnage,int price) {

// TODO Auto-generated constructor stub

this.setName(name);

this.setPassenger(passenger);

this.setPrice(price);

this.setTonnage(tonnage);;

}

public String toString() {

return this.getName()+"----"+this.getPrice()+"元/天---- 载客"+this.getPassenger()+"人---"+this.getTonnage()+"吨";

}

}

public class Truck extends Car {

public Truck(String name, int passenger, int price) {

// TODO Auto-generated constructor stub

this.setName(name);

this.setPassenger(passenger);

this.setPrice(price);

}

/* (non-Javadoc)

* @see java.lang.Object#toString()

*/

public String toString() {

return this.getName()+"----"+this.getPrice()+"元/天---- 载客"+this.getPassenger()+"人";

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值