package dadarent;import java.util.Scanner;public class DadaRentSystem { public static void main(String[] args) { // TODO 自动生成的方法存根 System.out.println("欢迎使用答答租车系统:"); System.out.println("您是否要租车:1是 0否"); Scanner ipt = new Scanner (System.in); int yn = ipt.nextInt(); if (yn==0){ ipt.close(); return; } else{ System.out.println("您可租车的类型及其价目表:"); System.out.println("序号 汽车名称 租金 容量"); AudiA4 aud = new AudiA4(); Mazda6 maz = new Mazda6(); ChevroletPickup6 chv = new ChevroletPickup6(); Kinglong klg = new Kinglong(); HAMCSungari sgr = new HAMCSungari(); Iveco ivc = new Iveco(); System.out.println(aud.num()+". "+aud.type()+" "+aud.price()+"元/天 "+"载人:"+aud.PassengerCapacity()+"人"); System.out.println(maz.num()+". "+maz.type()+" "+maz.price()+"元/天 "+"载人:"+maz.PassengerCapacity()+"人"); System.out.println(chv.num()+". "+chv.type()+" "+chv.price()+"元/天 "+"载人:"+chv.PassengerCapacity()+"人 "+"载货:"+chv.CargoCapacity()+"吨"); System.out.println(klg.num()+". "+klg.type()+" "+klg.price()+"元/天 "+"载人:"+klg.PassengerCapacity()+"人"); System.out.println(sgr.num()+". "+sgr.type()+" "+sgr.price()+"元/天 "+"载货:"+sgr.CargoCapacity()+"吨"); System.out.println(ivc.num()+". "+ivc.type()+" "+ivc.price()+"元/天 "+"载货:"+ivc.CargoCapacity()+"吨"); System.out.println("请输入您要租汽车的数量:"); int n = ipt.nextInt(); String carriage = "" , lorry = ""; int passenger = 0 , vehicleNum = 0; double cargo = 0.0 , price = 0.0; for (int i = 1 ; i <= n ; i++ ){ System.out.println("请输入第"+i+"辆车的序号:"); vehicleNum = ipt.nextInt(); switch (vehicleNum){ case 1: carriage = carriage + " " + aud.type(); passenger = passenger + aud.PassengerCapacity(); price = price + aud.price(); break; case 2: carriage = carriage + " " + maz.type(); passenger = passenger + maz.PassengerCapacity(); price = price + maz.price(); break; case 3: carriage = carriage + " " + chv.type(); lorry = lorry + " " + chv.type(); passenger = passenger + chv.PassengerCapacity(); cargo = cargo + chv.CargoCapacity(); price = price + chv.price(); break; case 4: carriage = carriage + " " + klg.type(); passenger = passenger + klg.PassengerCapacity(); price = price + klg.price(); break; case 5: lorry = lorry + " " + sgr.type(); cargo = cargo + sgr.CargoCapacity(); price = price + sgr.price(); break; case 6: lorry = lorry + " " + ivc.type(); cargo = cargo + ivc.CargoCapacity(); price = price + ivc.price(); break; default: System.out.println("错误输入"); break; } } System.out.println("请输入租车天数:"); int day = ipt.nextInt(); price = price * day; ipt.close(); System.out.println("您的账单:"); System.out.println("***可载人的车有:"); System.out.println(carriage+" 共载人:"+passenger+"人"); System.out.println("***载货的车有:"); System.out.println(lorry+" 共载货:"+cargo+"吨"); System.out.println("租车总价格:"+price+"元"); } return; }}
package dadarent;
public abstract class Vehicle {
public abstract int num();
public abstract String type();
public abstract double price();
}
package dadarent;
public interface IPassengerCap {
public abstract int PassengerCapacity ();
}
package dadarent;
public interface ICargoCap {
public abstract double CargoCapacity ();
}
package dadarent;
public class AudiA4 extends Vehicle implements IPassengerCap {
@Override
public int PassengerCapacity() {
// TODO 自动生成的方法存根
return 4;
}
@Override
public String type() {
// TODO 自动生成的方法存根
return "奥迪A4";
}
@Override
public double price() {
// TODO 自动生成的方法存根
return 500.0;
}
@Override
public int num() {
// TODO 自动生成的方法存根
return 1;
}
}
package dadarent;
public class Mazda6 extends Vehicle implements IPassengerCap {
@Override
public int PassengerCapacity() {
// TODO 自动生成的方法存根
return 4;
}
@Override
public String type() {
// TODO 自动生成的方法存根
return "马自达6";
}
@Override
public double price() {
// TODO 自动生成的方法存根
return 400.0;
}
@Override
public int num() {
// TODO 自动生成的方法存根
return 2;
}
}
package dadarent;
public class ChevroletPickup6 extends Vehicle implements IPassengerCap, ICargoCap {
@Override
public double CargoCapacity() {
// TODO 自动生成的方法存根
return 2.0;
}
@Override
public int PassengerCapacity() {
// TODO 自动生成的方法存根
return 4;
}
@Override
public String type() {
// TODO 自动生成的方法存根
return "皮卡雪6";
}
@Override
public double price() {
// TODO 自动生成的方法存根
return 450.0;
}
@Override
public int num() {
// TODO 自动生成的方法存根
return 3;
}
}
package dadarent;
public class Kinglong extends Vehicle implements IPassengerCap {
@Override
public int PassengerCapacity() {
// TODO 自动生成的方法存根
return 20;
}
@Override
public String type() {
// TODO 自动生成的方法存根
return " 金龙";
}
@Override
public double price() {
// TODO 自动生成的方法存根
return 800.0;
}
@Override
public int num() {
// TODO 自动生成的方法存根
return 4;
}
}
package dadarent;
public class HAMCSungari extends Vehicle implements ICargoCap {
@Override
public double CargoCapacity() {
// TODO 自动生成的方法存根
return 4.0;
}
@Override
public String type() {
// TODO 自动生成的方法存根
return " 松花江";
}
@Override
public double price() {
// TODO 自动生成的方法存根
return 400.0;
}
@Override
public int num() {
// TODO 自动生成的方法存根
return 5;
}
}
package dadarent;
public class Iveco extends Vehicle implements ICargoCap {
@Override
public double CargoCapacity() {
// TODO 自动生成的方法存根
return 20.0;
}
@Override
public String type() {
// TODO 自动生成的方法存根
return " 依维柯";
}
@Override
public double price() {
// TODO 自动生成的方法存根
return 1000.0;
}
@Override
public int num() {
// TODO 自动生成的方法存根
return 6;
}
}
package dadarent; import java.util.Scanner; public class DadaRentSystem { public static void main(String[] args) { // TODO 自动生成的方法存根 System.out.println("欢迎使用答答租车系统:"); System.out.println("您是否要租车:1是 0否"); Scanner ipt = new Scanner (System.in); int yn = ipt.nextInt(); if (yn==0){ ipt.close(); return; } else{ System.out.println("您可租车的类型及其价目表:"); System.out.println("序号 汽车名称 租金 容量"); AudiA4 aud = new AudiA4(); Mazda6 maz = new Mazda6(); ChevroletPickup6 chv = new ChevroletPickup6(); Kinglong klg = new Kinglong(); HAMCSungari sgr = new HAMCSungari(); Iveco ivc = new Iveco(); System.out.println(aud.num()+". "+aud.type()+" "+aud.price()+"元/天 "+"载人:"+aud.PassengerCapacity()+"人"); System.out.println(maz.num()+". "+maz.type()+" "+maz.price()+"元/天 "+"载人:"+maz.PassengerCapacity()+"人"); System.out.println(chv.num()+". "+chv.type()+" "+chv.price()+"元/天 "+"载人:"+chv.PassengerCapacity()+"人 "+"载货:"+chv.CargoCapacity()+"吨"); System.out.println(klg.num()+". "+klg.type()+" "+klg.price()+"元/天 "+"载人:"+klg.PassengerCapacity()+"人"); System.out.println(sgr.num()+". "+sgr.type()+" "+sgr.price()+"元/天 "+"载货:"+sgr.CargoCapacity()+"吨"); System.out.println(ivc.num()+". "+ivc.type()+" "+ivc.price()+"元/天 "+"载货:"+ivc.CargoCapacity()+"吨"); System.out.println("请输入您要租汽车的数量:"); int n = ipt.nextInt(); String carriage = "" , lorry = ""; int passenger = 0 , vehicleNum = 0; double cargo = 0.0 , price = 0.0; for (int i = 1 ; i <= n ; i++ ){ System.out.println("请输入第"+i+"辆车的序号:"); vehicleNum = ipt.nextInt(); switch (vehicleNum){ case 1: carriage = carriage + " " + aud.type(); passenger = passenger + aud.PassengerCapacity(); price = price + aud.price(); break; case 2: carriage = carriage + " " + maz.type(); passenger = passenger + maz.PassengerCapacity(); price = price + maz.price(); break; case 3: carriage = carriage + " " + chv.type(); lorry = lorry + " " + chv.type(); passenger = passenger + chv.PassengerCapacity(); cargo = cargo + chv.CargoCapacity(); price = price + chv.price(); break; case 4: carriage = carriage + " " + klg.type(); passenger = passenger + klg.PassengerCapacity(); price = price + klg.price(); break; case 5: lorry = lorry + " " + sgr.type(); cargo = cargo + sgr.CargoCapacity(); price = price + sgr.price(); break; case 6: lorry = lorry + " " + ivc.type(); cargo = cargo + ivc.CargoCapacity(); price = price + ivc.price(); break; default: System.out.println("错误输入"); break; } } System.out.println("请输入租车天数:"); int day = ipt.nextInt(); price = price * day; ipt.close(); System.out.println("您的账单:"); System.out.println("***可载人的车有:"); System.out.println(carriage+" 共载人:"+passenger+"人"); System.out.println("***载货的车有:"); System.out.println(lorry+" 共载货:"+cargo+"吨"); System.out.println("租车总价格:"+price+"元"); } return; } }