本文实例为大家分享了java实现汽车租赁系统的具体代码,供大家参考,具体内容如下 一、使用技术 javaSE 二、实现功能 汽车租赁系统 具体要求如下: 使用面向对象的知识实现一个汽车
本文实例为大家分享了java实现汽车租赁系统的具体代码,供大家参考,具体内容如下
一、使用技术
javaSE
二、实现功能
汽车租赁系统
具体要求如下:
使用面向对象的知识实现一个汽车租赁系统
1.汽车租赁信息表如下
2.类和属性
三、运行效果图
1.先创建一个汽车类作为父类,这里有汽车的公共属性:
public class Automobile {//汽车类 private String licensePlate;//车牌 private String brand;//品牌 private int rent;//租金 public Automobile() { } public Automobile(String licensePlate, String brand, int rent) { this.licensePlate = licensePlate; this.brand = brand; this.rent = rent; } public String getLicensePlate() { return licensePlate; } public void setLicensePlate(String licensePlate) { this.licensePlate = licensePlate; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public int getRent() { return rent; } public void setRent(int rent) { this.rent = rent; } }
2.创建一个轿车类,继承汽车类的属性
public class Car extends Automobile{//轿车 private String model;//型号 public Car(String model) { this.model = model; } public Car(String licensePlate, String brand, int rent, String model) { super(licensePlate, brand, rent); this.model = model; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } }
3.创建一个客车类,继承汽车类的属性
public class Passengercar extends Automobile{//客车 private String seatingCapacity;//座位数 public Passengercar(String seatingCapacity) { this.seatingCapacity = seatingCapacity; } public Passengercar(String licensePlate, String brand, int rent, String seatingCapacity) { super(licensePlate, brand, rent); this.seatingCapacity = seatingCapacity; } public String getSeatingCapacity() { return seatingCapacity; } public void setSeatingCapacity(String seatingCapacity) { this.seatingCapacity = seatingCapacity; } }
4.创建测试类,用于实现这个系统
import java.util.Scanner; public class TestAutomobile { public static void main(String[] args) { Car c1 = new Car("京NY28588", "宝马X6", 800, "1"); Car c2 = new Car("京CNY3284", "宝马550i", 600, "1"); Car c3 = new Car("京NT37465", "别克林荫大道", 300, "1"); Car c4 = new Car("京NT969968", "别克GL8", 600, "1"); Passengercar p1 = new Passengercar("京6566754", "金杯,16座", 800, "2"); Passengercar p2 = new Passengercar("京8696997", "金龙,16座", 800, "2"); Passengercar p3 = new Passengercar("京9696996", "金杯,34座", 1500, "2"); Passengercar p4 = new Passengercar("京8696998", "金龙,34座", 1500, "2"); Scanner sc = new Scanner(System.in); System.out.println("***********************欢迎光临秋名山守望者汽车租赁公司***********************"); while (true){ System.out.println("1、轿车 2、客车"); System.out.println("请选择你要租赁的汽车类型:"); String a=sc.next(); if (a.equals("1")){//轿车 System.out.println("请选择你要租赁的汽车品牌:1、别克 2、宝马"); String a1=sc.next(); if (a1.equals("2")){//宝马 System.out.println("请选择你要租赁的汽车类型:1、X6 2、550i"); String a2=sc.next(); if (a2.equals("2")){//550i System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+c2.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>7&&a3<=30){ System.out.println(c2.getRent()*a3*0.9+"元"); }else if(a3>30&&a3<=150){ System.out.println(c2.getRent()*a3*0.8+"元"); }else { System.out.println(c2.getRent()*a3*0.7+"元"); } }else {//x6 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+c1.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>7&&a3<=30){ System.out.println(c1.getRent()*a3*0.9+"元"); }else if(a3>30&&a3<=150){ System.out.println(c1.getRent()*a3*0.8+"元"); }else { System.out.println(c1.getRent()*a3*0.7+"元"); } } }else {//别克 System.out.println("请选择你要租赁的汽车类型:1、林荫大道 2、GL8"); String a2=sc.next(); if (a2.equals("2")){//GL8 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+c4.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>7&&a3<=30){ System.out.println(c4.getRent()*a3*0.9+"元"); }else if(a3>30&&a3<=150){ System.out.println(c4.getRent()*a3*0.8+"元"); }else { System.out.println(c4.getRent()*a3*0.7+"元"); } }else {//别克林荫大道 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+c3.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>7&&a3<=30){ System.out.println(c3.getRent()*a3*0.9+"元"); }else if(a3>30&&a3<=150){ System.out.println(c3.getRent()*a3*0.8+"元"); }else { System.out.println(c3.getRent()*a3*0.7+"元"); } } } /* Passengercar p1 = new Passengercar("京6566754", "金杯", 800, "2"); Passengercar p2 = new Passengercar("京8696997", "金龙", 800, "2"); Passengercar p3 = new Passengercar("京9696996", "金杯", 1500, "2"); Passengercar p4 = new Passengercar("京8696998", "金龙", 1500, "2"); */ }else {//客车 System.out.println("请选择你要租赁的汽车品牌:1、金龙 2、金杯"); String a1=sc.next(); if (a1.equals("1")){//金龙 System.out.println("请选择你要租赁的汽车座位数:1、16座 2、34座"); String a2=sc.next(); if (a2.equals("1")){//16座 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+p2.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>=3&&a3<7){ System.out.println(p2.getRent()*a3*0.9+"元"); }else if(a3>=7&&a3<30){ System.out.println(p2.getRent()*a3*0.8+"元"); }else if (a3>=30&&a3<150){ System.out.println(p2.getRent()*a3*0.7+"元"); }else { System.out.println(p2.getRent()*a3*0.6+"元"); } }else {//34 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+p4.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>=3&&a3<7){ System.out.println(p4.getRent()*a3*0.9+"元"); }else if(a3>=7&&a3<30){ System.out.println(p4.getRent()*a3*0.8+"元"); }else if (a3>=30&&a3<150){ System.out.println(p4.getRent()*a3*0.7+"元"); }else { System.out.println(p4.getRent()*a3*0.6+"元"); } } }else {//金杯 System.out.println("请选择你要租赁的汽车座位数:1、16座 2、34座"); String a2=sc.next(); if (a2.equals("1")){//16座 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+p1.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>=3&&a3<7){ System.out.println(p1.getRent()*a3*0.9+"元"); }else if(a3>=7&&a3<30){ System.out.println(p1.getRent()*a3*0.8+"元"); }else if (a3>=30&&a3<150){ System.out.println(p1.getRent()*a3*0.7+"元"); }else { System.out.println(p1.getRent()*a3*0.6+"元"); } }else {//34 System.out.println("请选择你要租赁的天数"); double a3=sc.nextInt(); System.out.println("分配给您的汽车牌号是:"+p3.getLicensePlate()); System.out.print("您需要支付的租赁费用是:"); if (a3>=3&&a3<7){ System.out.println(p3.getRent()*a3*0.9+"元"); }else if(a3>=7&&a3<30){ System.out.println(p3.getRent()*a3*0.8+"元"); }else if (a3>=30&&a3<150){ System.out.println(p3.getRent()*a3*0.7+"元"); }else { System.out.println(p3.getRent()*a3*0.6+"元"); } } } } System.out.println(); System.out.println(); System.out.println("是否还要继续选车 1继续 2终止"); String x=sc.next(); if (x.equals("2")){ System.out.println("欢迎下次光临!"); break; } System.out.println(); System.out.println(); } } }
1.轿车的实现
2.客车的实现
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。