demo
package dada;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("欢迎使用哒哒租车系统");
System.out.println("您是否要租车:1是 0否");
int s = sc.nextInt();
Car[] cars = {new Keche( 500, "奥迪A4",4),
new Keche( 400, "马自达6",5),
new Keche( 450, "金杯面包",21),
new Huoche( 800, "松花江",5),
new Huoche( 1100, "东风",20),
new Kehuoche( 500, "皮卡",3,8),};
if(s == 0){
System.out.println("谢谢使用");
}else{
System.out.println("价目表如下");
System.out.println("序号 车型 价格 容量");
for(int i = 1; i <= cars.length; i++) {
System.out.println("序号:" + (i) + " " + cars[i-1]);
}
}
int pricesum = 0;
int passengersum = 0;
double goodssum = 0;
System.out.println("请输入预订数量");
int sl = sc.nextInt();
for(int a = 1; a <= sl; a++){
System.out.println("请输入第" + a + "台车型序号");
int xh = sc.nextInt();
System.out.println("你选的第" + a + "辆是" + cars[xh-1]);
System.out.println("请输入预定天数");
int ts = sc.nextInt();
System.out.println("预定" + ts + "天");
System.out.println("预定中...");
pricesum = pricesum + cars[xh-1].getPrice()*ts;
passengersum += cars[xh-1].getPassengerLoad();
goodssum += cars[xh-1].getGoodsLoad();
}
System.out.println("价格合计:" + pricesum + ",载客量为:" + passengersum + ",载货量为:" + goodssum);
}
}
car
package dada;
public class Car {
private int price;
private String name;
private int passengerLoad; //载人量
private double goodsLoad; //
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPassengerLoad() {
return passengerLoad;
}
public void setPassergerLoad(int passengerLoad) {
this.passengerLoad = passengerLoad;
}
public double getGoodsLoad() {
return goodsLoad;
}
public void setGoodsLoad(double goodsLoad) {
this.goodsLoad = goodsLoad;
}
}
客车
package dada;
public class Keche extends Car {
public Keche(int price, String name, int passengerLoad) {
super();
this.setPrice(price);
this.setName(name);
this.setPassergerLoad(passengerLoad);
}
public String toString(){
return this.getName() + " " + this.getPrice() + "元/天 " + "载客" + this.getPassengerLoad() + "人";
}
}
货车
package dada;
public class Huoche extends Car {
public Huoche(int price, String name , double goodsLoad) {
super();
this.setPrice(price);
this.setName(name);
this.setGoodsLoad(goodsLoad);
}
public String toString(){
return this.getName() + " " + this.getPrice() + "元/天 " + "载货" +this.getGoodsLoad() + "吨";
}
}
皮卡
package dada;
public class Kehuoche extends Car {
public Kehuoche(int price, String name, int passengerLoad, double goodsLoad) {
super();
this.setPrice(price);
this.setName(name);
this.setPassergerLoad(passengerLoad);
this.setGoodsLoad(goodsLoad);
}
public String toString() {
return this.getName() + " " + this.getPrice() + "元/天 " + "载客" + this.getPassengerLoad() + "人/载货" + this.getGoodsLoad() + "吨";
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦