Car.java
package com.kj;
public class Car {
public int Carnum;
public String Carname;//汽车名字
public int Carvalue;//汽车价格
public int loadpeople;//载客量
public int loadgoods;//载货量
//获取车的编号
public int getCarnum(){
return Carnum;
}
//获取车的名字
public String getCarname(){
return Carname;
}
//获取车的价格
public int getCarvalue(){
return Carvalue;
}
//获取车的载客量
public int getloadpeople(){
return loadpeople;
}
//获取车的载货量
public int getloadgoods(){
return loadgoods;
}
}
peoplecar.java
package com.kj;
public class peoplecar extends Car {
public peoplecar(int Carnum,String Carname,int Carvalue,int Carloadpeople){
this.Carnum=Carnum;
this.Carname=Carname;
this.Carvalue=Carvalue;
this.loadpeople=Carloadpeople;
}
}
goodscar.java
package com.kj;
public class goodscar extends Car {
public goodscar(int Carnum,String Carname,int Carvalue,int Carloadgoods){
this.Carnum=Carnum;
this.Carname=Carname;
this.Carvalue=Carvalue;
this.loadgoods=Carloadgoods;
}
}
pickup.java
package com.kj;
public class pickup extends Car {
public pickup(int Carnum,String Carname,int Carvalue,int Carloadpeople,int Carloadgoods){
this.Carnum=Carnum;
this.Carname=Carname;
this.Carvalue=Carvalue;
this.loadpeople=Carloadpeople;
this.loadgoods=Carloadgoods;
}
}
initial.java
package com.kj;
import java.util.Scanner;
public class initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:1是 0否");
//定义数组,实例化车的对象
Car[] car={
new peoplecar(1,"奥迪A4",500,4),
new peoplecar(2,"马自达6",400,4),
new pickup(3,"皮卡雪6",450,4,2),
new peoplecar(4,"金龙",800,20),
new goodscar(5,"松花江",400,4),
new goodscar(6,"依维柯",1000,20)
};
Scanner input =new Scanner(System.in);
int num =input.nextInt();
if(num == 0){
System.out.println("不租车,正在退出系统!");
System.exit(0);
}
if(num != 1){
System.out.println("输入有误,正在退出系统!");
System.exit(0);
}
if(num == 1){
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1 奥迪A4 500元/天 载人:4人");
System.out.println("2 马自达6 400元/天 载人:4人");
System.out.println("3 皮卡雪6 450元/天 载人:2人 载货:4吨");
System.out.println("4 金龙 400元/天 载人:20人");
System.out.println("5 松花江 400元/天 载货:4吨");
System.out.println("6 依维柯 1000元/天 载货:20吨");
System.out.println("请输入您要租汽车的数量:");
int num1=input.nextInt();
int price=0;
Car[] carlist=new Car[num1];
for(int i=0;i<num1;i++){
System.out.println("请输入第"+ (i+1) +"辆车的序号:");
int j=input.nextInt();
carlist[i]=car[j-1];
price+=carlist[i].getCarvalue();
}
System.out.println("请输入租车天数:");
int days=input.nextInt();
price*=days;//租车价格
System.out.println("您的账单:");
System.out.println("***可载人的车有:");
int loadpeoplenum=0;
for(int i=0;i<num1;i++){
if(carlist[i] instanceof peoplecar carlist[i] instanceof pickup){//如果租的车辆里有peoplecar类或pickup类,就可以载人
System.out.print(carlist[i].getCarname() + "\t");
loadpeoplenum+=carlist[i].getloadpeople();
}
}
System.out.println("共载人:" + loadpeoplenum + "人");
System.out.println("载货的车有:");
int loadgoodsnum=0;
for(int i=0;i<num1;i++){
if(carlist[i] instanceof goodscar carlist[i] instanceof pickup){////如果租的车辆里有goodscar类或pickup类,就可以载货
System.out.print(carlist[i].getCarname() + "\t");
loadgoodsnum+=carlist[i].getloadgoods();
}
}
System.out.println("共载货:" + loadgoodsnum + "吨");
System.out.println("租车总价格:" + price + "元");
}
}
}
点击查看更多内容
57人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦