我写的源码,欢迎交流
package com.imooc;
import java.util.Scanner;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input =new Scanner(System.in);
System.out.println("**********欢迎使用哒哒租车系统******");
System.out.println("您是否要租车:1.是 0.否");
int a=input.nextInt();
if(a==1){
}else{
System.exit(0);
}
System.out.println("序号 汽车名称 租金 容量");
Car[] carrent={new PassageCar(1,"奥迪a6",500,4),
new PassageCar(2,"马自达6",400,4),
new Pika(3,"皮卡雪6",450,4),
new PassageCar(4,"金龙",800,20),
new WeightCar(5,"松花江",400,4),
new WeightCar(6,"依维柯",1000,20)};
System.out.println("请输入您要租车的序号:");
int b=input.nextInt();
System.out.println("请输入您要租车的数量:");
int c=input.nextInt();
System.out.println("请输入您要租车的天数");
int d=input.nextInt();
while(true){
try{
switch(b){
case 1:
int count1=500*c*d;
System.out.println("您选择了奥迪a6,共承载"+c*4+"人");
System.out.println("您的账单:"+count1);
break;
case 2:
int count2 =400*c*d;
System.out.println("您选择了马自达6,共承载"+c*4+"人");
System.out.println("您的账单:"+count2);
break;
case 3:
int count3 =450*c*d;
System.out.println("您选择了皮卡雪,共承载"+c*4+"人");
System.out.println("您的账单:"+count3);
break;
case 4:
int count4 =800*c*d;
System.out.println("您选择了金龙,共承载"+c*20+"人");
System.out.println("您的账单:"+count4);
break;
case 5:
int count5 =400*c*d;
System.out.println("您选择了松花江,共承载"+c*4+"吨货物");
System.out.println("您的账单:"+count5);
break;
case 6:
int count6 =1000*c*d;
System.out.println("您选择了依维柯,共承载"+c*20+"吨货物");
System.out.println("您的账单:"+count6);
break;
}}catch(Exception e){
if(b==7){
System.out.println("您的输入有误,请从新输入:");}
}
System.exit(0);
}
}}
package com.imooc;
public class Car {
public int sno;
public String name;
public float price;
public int num;
}
package com.imooc;
public class PassageCar extends Car {
public PassageCar(){}
public PassageCar(int sno,String name,float price,int num){
this.sno=sno;
this.name=name;
this.price=price;
this.num=num;
System.out.println(sno+"\t"+name+"\t"+price+"/天"+"\t"+num+"人/位");
}
}
package com.imooc;
public class Pika extends Car{
public Pika(){}
public Pika(int sno,String name,float price,int num){
this.sno=sno;
this.name=name;
this.price=price;
this.num=num;
System.out.println(sno+"\t"+name+"\t"+price+"/天"+"\t"+num+"人/4吨");
}
}
package com.imooc;
public class WeightCar extends Car {
public WeightCar(){}
public WeightCar(int sno,String name,float price,int num){
this.sno=sno;
this.name=name;
this.price=price;
this.num=num;
System.out.println(sno+"\t"+name+"\t"+price+"/天"+"\t"+num+"吨");
}
}