慕粉1731118495
2019-07-24 21:19:10浏览 896
父类
package dada;
public class Car {
int id;
String name;
int price;
int capacity;
int num;
public Car(int id,String name,int price,int capacity) {
this.id=id;
this.name=name;
this.price=price;
this.capacity=capacity;
}
public Car(int id,String name,int price,int capacity,int num) {
this.id=id;
this.name=name;
this.price=price;
this.capacity=capacity;
this.num=num;
this.num=num;
}
}
子类PersonCar(客车)
package dada;
public class PersonCar extends Car{
public PersonCar(int id, String name, int price, int capacity) {
super(id, name, price, capacity);
}
}
子类GoodsCar(货车)
package dada;
public class GoodsCar extends PersonCar {
public GoodsCar(int id, String name, int price, int capacity) {
super(id, name, price, capacity);
}
}
子类Pk(皮卡)
package dada;
public class Pk extends Car {
public Pk(int id, String name, int price, int capacity,int num) {
super(id, name, price, capacity,num);
}
}
main():
package dada;
import java.util.*;
public class Dada {
public static void main(String[] args) {
Car car1=new PersonCar(1, "奥迪", 500, 4);
Car car2=new PersonCar(2, "马自达", 400, 4);
Car car3=new PersonCar(3, "金龙", 800, 20);
Car car4=new GoodsCar(4, "松花江", 400, 4);
Car car5=new GoodsCar(5, "依维柯", 1000, 20);
Car car6=new Pk(6, "皮卡", 450,4,2);
System.out.println("欢迎使用哒哒租车系统:"+"\n"+"您是否要租车:1是0否");
Scanner scan=new Scanner(System.in);
int zu=scan.nextInt();
if(zu==1){
System.out.println("您可租车的类型及其价目表:"+"\n"+"序号"+"\t"+"汽车名称"+"\t"+"租金"+"\t"+"容量");
System.out.println(car1.id+"\t"+car1.name+"\t"+car1.price+"/天"+"\t"+"载客:"+car1.capacity+"人");
System.out.println(car2.id+"\t"+car2.name+"\t"+car2.price+"/天"+"\t"+"载客:"+car2.capacity+"人");
System.out.println(car3.id+"\t"+car3.name+"\t"+car3.price+"/天"+"\t"+"载客:"+car3.capacity+"人");
System.out.println(car4.id+"\t"+car4.name+"\t"+car4.price+"/天"+"\t"+"载货:"+car4.capacity+"吨");
System.out.println(car5.id+"\t"+car5.name+"\t"+car5.price+"/天"+"\t"+"载货:"+car5.capacity+"吨");
System.out.println(car6.id+"\t"+car6.name+"\t"+car6.price+"/天"+"\t"+"载人:"+car6.capacity+"人,"+"载货:"+car6.num+"吨");
System.out.println("请输入您要租车数量:");
int shu=scan.nextInt();
int[] list=new int[shu];
for(int a=0;a<shu;a++) {
System.out.println("请输入第"+(a+1)+"辆车的序号:");
int xu=scan.nextInt();
list[a]=xu;
}
System.out.println("选的车序号"+Arrays.toString(list));
System.out.println("请输入租车天数:");
int tian=scan.nextInt();
System.out.println("您的账单:");
System.out.println("可载人的车有:");
int q = 0,w = 0,e = 0,r = 0,s = 0,d = 0,f = 0,z = 0,x=0,c=0,v=0,b=0,n=0,p=0,l=0;
for(int i=0;i<shu;i++){
if(list[i]==1) {
System.out.print("奥迪"+"\t");
q=car1.capacity;
z=car1.price;
}else if(list[i]==2) {
System.out.print("马自达"+"\t");
w=car2.capacity;
x=car2.price;
}else if(list[i]==3) {
System.out.print("金龙"+"\t");
e=car3.capacity;
c=car3.price;
}else if(list[i]==6) {
System.out.print("皮卡"+"\t");
r=car6.capacity;
v=car6.price;
}
}
p=z+x+c+v;
System.out.println("可载人:"+(q+w+e+r)+"人");
System.out.println("可载货的车有:");
for(int i=0;i<shu;i++) {
if(list[i]==4) {
System.out.print("松花江"+"\t");
s=car4.capacity;
b=car4.price;
}else if(list[i]==5) {
System.out.print("依维柯"+"\t");
d=car5.capacity;
n=car5.price;
}else if(list[i]==6) {
System.out.print("皮卡"+"\t");
f=car6.num;
}
}
l=b+n;
System.out.println("可载货:"+(s+d+f)+"吨");
System.out.println("租车总价格:"+(p+l)*tian+"元");
}else{
System.out.println("感谢使用");
}
}
}