JAVA汽车租赁系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
super(no,brand); this.seatCount = seatCount; }
//获取座位数 public int getSeat(){
return seatCount; }
//计算租金 public int calRent(int days){
int rent = 0; if(seatCount <= 16){
//构造方法 public Car(){
} public Car(String no, String brand, String type){
super(no,brand); this.type = type; }
//设置轿车的型号 public void setType(String type){
package RentCar;
public class Truck extends MotoVehicle { private int weight; //吨位
public Truck(){
} public Truck(String no, String brand,int weight){
super(no,brand);
do{ System.out.print("请输入要租赁的汽车类型(1.轿车 2.客车):");
motoType = input.nextInt();
int random = (int)(Math.random()*(99999-10000)+10000); switch(motoType){ case 1:
return brand; }
//计算租金的抽象方法 public abstract int calRent(int days); }
…………………………………………………………………………………………………………… package RentCar; import java.util.Scanner;
System.out.print("请输入要租赁的汽车品牌(1.黄海
//根据选择得到汽车品牌
if(input.nextInt() ==1){
brand = "黄海";
}else{
brand = "金龙";
}
System.out.print("请输入客车的座位数:");
seat = input.nextInt();
2.丰田):");
} //实例化一个轿车对象,并添加到moto数组中 for(int i = 0 ; i < moto.length ;i ++){
if(moto[i] == null){ moto[i] = new Car(no,brand,type); break;
} }
break;
case 2: no = "粤A" + random;
//构造方法 public MotoVehicle(){
}
public MotoVehicle(String no, String brand){ this.no = no; this.brand = brand;
}
//返回机动车辆的牌照 public String getNo(){
return no; } //返回机动车辆的品牌 public String getBrand(){
no = "粤A" + random; //车辆牌照
System.out.print("请输入要租赁的汽车品牌(1.宝马 if(input.nextInt() == 1){
brand = "宝马"; type = "320i"; }else{ brand = "丰田"; type = "RAV4";
public int calcTotalRent(MotoVehicle[] moto, int days){ int rent = 0 ;
for(int i = 0 ;i < moto.length; i++){ if(moto[i]!=null){ rent = rent + moto[i].calRent(days); }
} } System.out.println("客户名:"+customer.getName()+",租赁天数:"+days+", 总费用:"+customer.calcTotalRent(moto, days)); } }
……………………………………………………………………………………………………………
this.weight = weight; }
public int getWeight(){ return weight;
}
public int calRent(int days){ int rent = 0;
rent = weight * 50 * days;
return rent; } }
MotoVehicle[] moto = new MotoVehicle[10]; Customer customer = new Customer("小明");
System.out.println("欢迎来到汽车租赁公司!");
System.out.print("请输入要租赁的天数:"); days = input.nextInt();
} }
break; } System.out.print("是否继续租车?(y/n):"); answer = input.next();
}while(answer.equals("y"));
System.out.println("汽车牌号\t汽车品牌"); for(int i = 0 ; i < moto.length ;i ++){
rent = days * 500; }else if("丰田".equals(getBrand())){
if(type.equals("GL8")){ rent = days * 600;
}else{ rent = days * 300;
} } return rent; } }
…………………………………………………………………………………………………………… package RentCar;
public class Test { public static void main(String[] args){ Scanner input = new Scanner(System.in); int days = 0; //租赁的天数 int motoType ; //汽车大类型 String brand ; //汽车品牌 String type = null; //汽车具体类型 int seat; //座位数 String no; //拍照 String answer; //是否继续
package RentCar;
public class Bus extends MotoVehicle{ private int seatCount; //构造方法 public Bus(){
} public Bus(String no, String brand, int seatCount){
this.type = type; }//返回轿车型号 public String getType(){
return type; } //实现父类抽象方法,计算租金 public int calRent(int days){
int rent = 0; if("宝马".equals(getBrand())){
}
return rent; } }
……………………………………………………………………………………………………………
package RentCar;
public abstract class MotoVehicle { private String no; //车牌号 private String brand; //品牌
if(moto[i] != null){ if(moto[i] instanceof Car){ Car c = (Car)moto[i]; System.out.println(c.getNo()+"\t"+c.getBrand()); }else{ Bus b = (Bus)moto[i]; System.out.println(b.getNo()+"\t"+b.getBrand()); }
public class Customer { private String name;
public Customer(){
} public Customer(String name){
this.name = name; }
public String getName(){ return name;
}
rent = 800 * days; }else{
rent = 1500 * days; }
return rent; } }
……………………………………………………………………………………………………………
package RentCar;
public class Car extends MotoVehicle { private String type; // 轿车的型号
//汽车座位数
2.金龙):");
பைடு நூலகம்
//实例化一个轿车对象,并添加到moto数组中 for(int i = 0 ; i < moto.length ;i ++){
if(moto[i] == null){ moto[i] = new Bus(no,brand,seat); //实例化一个汽车对
象 break;
相关文档
最新文档