//定义父类car
public class car {
String name;
int momey;
int people;
int cargo;
public String getname(){
return name;
}
public void setname(String name){
this.name=name;
}
public int getmomey(){
return momey;
}
public void setmomey(int momey){
this.momey=momey;
}
public int getpeople(){
return people;
}
public void setpeople(int people){
this.people=people;
}
public int getcargo(){
return cargo;
}
public void setcargo(int cargo){
this.cargo=cargo;
}
public void show(){
}
}
//载人类
public class passengerCar extends car {
public passengerCar(String a , int b ,int c){
this.setname(a);
this.setmomey(b);
this.setpeople(c);
}
public void show(){
System.out.println(getname()+"\t"+getmomey()+"元/天"+"\t"+"载人"+getpeople());
}
}
//皮卡
public class Pickup extends car {
public Pickup(String a,int b,int c,int d){
this.setname(a);
this.setmomey(b);
this.setpeople(d);
this.setcargo(c);
}
public void show(){
System.out.println(getname()+"\t"+getmomey()+"元/天"+"\t"+"载人"+getpeople()+"载货"+getcargo());
}
}
//载货类
public class Truck extends car {
public Truck(String a,int b,int c){
this.setname(a);
this.setmomey(b);
this.setcargo(c);
}
public void show(){
System.out.println(getname()+"\t"+getmomey()+"元/天"+"\t"+"载货"+getcargo());
}
}
//主程序
import java.util.Scanner;
public class test {
public static void main(String[]args){
car[] cars={new passengerCar("奥迪A6" , 500, 4),
new passengerCar("马自达6",400,4),
new Pickup("皮卡雪6",450,4,2),
new passengerCar("金龙",800,20),
new Truck("松花江",400,4),
new Truck("依维柯",1000,20)
};
Scanner reader=new Scanner(System.in);
System.out.println("欢迎使用哒哒租车系统:");
System.out.println("您是否要租车: 1是 0否");
int p=reader.nextInt();
if(p ==1){
System.out.println("您可租车的类型和租金价格表:");
System.out.println("序号"+"\t"+"汽车名称"+"\t"+" 租金"+"\t"+"容量");
for(int i=0;i<cars.length;i++){
System.out.print(i+1+"\t");
cars[i].show();
}
System.out.println("请输入您要租车的数量:");
int q=reader.nextInt();
int[] z=new int[q];
for(int i=0;i<q;i++){
System.out.println("请输入你要租用的车辆序号:");
int x=reader.nextInt();
z[i]=x;
}
System.out.println("您的账单:");
System.out.println("可载人的车有");
int r=0;
for(int i=0;i<z.length;i++){
if(z[i]==1 || z[i]==2 || z[i]==3 || z[i]==4){
System.out.print(cars[z[i]-1].getname()+" ");
r=r+cars[z[i]-1].getpeople();
}
}
System.out.println("总载客量:"+r);
System.out.println("可载货的车有:");
int h=0;
for(int i=0;i<z.length;i++){
if(z[i]==3 || z[i]==5 || z[i]==6){
System.out.print(cars[z[i]-1].getname()+" ");
h=h+cars[z[i]-1].getcargo();
}
}
System.out.println("总载货量:"+h);
System.out.println("请输入你要租的天数:");
int day=reader.nextInt();
int sum=0;
for(int i=0;i<z.length;i++){
sum=sum+cars[z[i]-1].getmomey()*day;
}
System.out.println("租车总价格:"+sum);
}else{
System.out.println("谢谢您的光临,欢迎下次再来!");
}
}
}
打开App,阅读手记