首页 > 代码库 > 汽车租货系统
汽车租货系统
//父类
public abstract class Superclass {
public double money;// 单价
private double moneys;// 总价
private int sky;// 天数
public String info;// 车型和车牌
private String discount;// 折扣
/*
* get和set天数
*/
public int getSky() {
return sky;
}
public void setSky(double sky) {
if (sky > 0) {
this.sky = (int)sky;
if(sky!=this.sky){
this.sky++;
}
} else {
System.out.println("输入错误");
}
}
/*
* get和set单价
*/
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
/*
* get和set总价
*/
public double getMoneys() {
return moneys;
}
public void setMoneys(double moneys) {
this.moneys = moneys;
}
/*
* get和set折扣
*/
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
/*
* 选择车型
*/
public String getInfo(int i) {
return null;
}
/*
* 日租价格
*/
public double getMoney(int i) {
return i ;
}
/*
* 轿车总价(sky)意思是天数
*/
public abstract void sumMoneys() ;
/*
* 显示借出的天数和打几折
*/
public abstract void showDiscount();
/*
* 给客户显示租金和车型
*/
public abstract void showCar();
/*
* 输出信息
*/
public abstract void showInfo() ;
}
//汽车继承父类
public class CarDemo extends Superclass{
/*
* 选择车型
*/
public String getInfo(int i) {// 信息
String[] limousine = { "宝马X6", "宝马550i", "别克林荫大道", "别克GL8" };// 车型
String[] tag = { "京NY28588", "京CNY3284", "京NT37465", "京NT96968" };// 牌照\
return info = "你选择的车型是:" + limousine[i] + "车牌号是:" + tag[i];
}
/*
* 日租价格
*/
public double getMoney(int i) {
double[] money = { 800, 600, 300, 600 };
return this.money = money[i];
}
/*
* 轿车总价(sky)意思是天数
*/
public void sumMoneys() {
if (getSky() > 0 && getSky() < 7) {
this.setMoneys(this.getMoney() * getSky());
} else if (getSky() >= 7 && getSky() < 30) {
this.setMoneys((this.getMoney() * 0.9) * getSky());
} else if (getSky() >= 30 && getSky() < 150) {
this.setMoneys((this.getMoney() * 0.8) * getSky());
} else if (getSky() >= 150) {
this.setMoneys((this.getMoney() * 0.7) * getSky());
}
}
/*
* 显示借出的天数和打几折
*/
public void showDiscount() {
sumMoneys();
if (getSky()> 0 && getSky() < 7) {
setDiscount(getSky() + "天小于7天按原价处理");
} else if (getSky()>= 7 && getSky()< 30) {
setDiscount(getSky() + "天大于等于七天小于三十天打九折");
} else if (getSky()>= 30 && getSky() < 150) {
setDiscount(getSky() + "天大于等于三十天小于一百五十天打八折");
} else if (getSky() >= 150) {
setDiscount(getSky() + "天大于等于一百五十天打七折");
}
}
public void showCar(){
System.out.println(info+"\t 一天的价格是:"+getMoney());
}
/*
* 输出信息
*/
public void showInfo() {
System.out.println(info + "\t一天价格为:" + getMoney() + "元\t" + this.getDiscount()
+ "\t应付:" + this.getMoneys());
}
}
//实例化汽车类
public class Output {
public void newObject() {
Scanner input = new Scanner(System.in);
Superclass car = new CarDemo();
System.out.println("选择轿车成功");
System.out.println("1.宝马X6\t2.宝马550i\t3.别克林荫大道\t4.别克GL8");
try {
int select = input.nextInt() - 1;
car.getInfo(select);
car.getMoney(select);
car.showCar();
System.out.println("请输入天数:");
double sc = input.nextDouble();
if (sc > 0) {
car.setSky(sc);
car.getSky();
car.showDiscount();
car.showInfo();
} else {
System.out.println("输入错误");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("请重新输入");
new Output().newObject();
}
}
}
//客车类继承汽车类
public class CarDemo1 extends CarDemo{
public String getInfo(int i) {// 信息
String[] limousine = { "金杯16座", "金杯34座", "金龙16座", "金龙34座" };// 车型
String[] tag = { "京6566754", "京8696998", "京8696997", "京9696996" };// 牌照\
return info = "你选择的车型是:" + limousine[i] + "车牌号是:" + tag[i];
}
public double getMoney(int i) {//单价
double[] money = { 800, 1500, 800,1500 };
return super.money=money[i];
}
public void sumMoneys() {
if (getSky() > 0 && getSky() < 3) {
this.setMoneys(this.getMoney() * getSky());
} else if (getSky() >= 3 && getSky() < 7) {
this.setMoneys((this.getMoney() * 0.9) * getSky());
} else if (getSky() >=7 && getSky() < 30) {
this.setMoneys((this.getMoney() * 0.8) * getSky());
} else if (getSky() >= 30&&getSky() < 150) {
this.setMoneys((this.getMoney() * 0.7) * getSky());
}else if (getSky() >=150) {
this.setMoneys((this.getMoney() * 0.6) * getSky());
}
}
public void showDiscount() {
sumMoneys();
if (getSky() > 0 && getSky() < 3) {
setDiscount(getSky() + "天小于3天按原价处理");
} else if (getSky() >= 3 && getSky() < 7) {
setDiscount(getSky() + "天大于等于3天小于7天打九折");
} else if (getSky() >=7 && getSky() < 30) {
setDiscount(getSky() + "天大于等于7天小于30天打八折");
} else if (getSky() >= 30&&getSky() < 150) {
setDiscount(getSky() + "天大于等于30天小于150天打七折");
}else if (getSky() >=150) {
setDiscount(getSky() + "天大于等于一百五十天打6折");
}
}
}
//实例化客车类
public class Test_Coach {
public void show_Coach(){
Scanner input = new Scanner(System.in);
CarDemo1 car1 = new CarDemo1();
System.out.println("选择客车成功");
System.out.println("1.金杯16座\t2.金杯34座\t3.金龙16座\t4.金龙34座");
try {
int select = input.nextInt()-1;
car1.getInfo(select);
car1.getMoney(select);
car1.showCar();
System.out.println("请输入天数:");
double sc = input.nextDouble();
if (sc > 0) {
car1.setSky(sc);
car1.showDiscount();
car1.showInfo();
}else{
System.out.println("输入错误");
}
} catch (Exception e) {
//e.printStackTrace();
System.err.println("请重新输入");
new Test_Coach().show_Coach();
}
}
}
//测试类
public class Test_Car {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("欢迎使用汽车租售系统!");
System.out.println("1.轿车\t2.客车");
boolean panDuan=true;
while(panDuan==true){
String judge=input.next();
switch(judge){
//轿车
case "1":
panDuan=false;
new Output().newObject();
break;
case "2":
//客车
panDuan=false;
new Test_Coach().show_Coach();
break;
default:
System.out.println("输入错误,请重新输入");
}
}
System.out.println("谢谢使用");
}
}
汽车租货系统