哒哒租车系统上线啦!!!求指点
package Dadacar; public interface Laden {//载货量接口 public double Ccy (double T_ccy); }
package Dadacar; public interface Passenger {//载客量接口 public int Cpy (int T_cpy); }
package Dadacar; public class Machine {//交通工具父类 static int Capacity; static double CargoCapacity; static String Model; }
package Dadacar; //客车子类 public class Coach extends Machine implements Passenger { public static String mod(String T_model){ Machine.Model = T_model; return Model; } public int Cpy(int T_cpy) { Machine.Capacity = T_cpy; return Capacity; } public void S_coach(){ System.out.println(Coach.mod("小型客车")); Passenger S_c = new Coach(); System.out.println("载货量为:"+S_c.Cpy(5)+"人"); System.out.println("200元/天"); } public void B_coach(){ System.out.println(Coach.mod("大型客车")); Passenger B_c = new Coach(); System.out.println("载货量为:"+B_c.Cpy(50)+"人"); System.out.println("800元/天"); } }
package Dadacar; //货车子类 public class Truck extends Machine implements Laden{ @Override public double Ccy(double T_ccy) { // TODO 自动生成的方法存根 Machine.CargoCapacity = T_ccy; return CargoCapacity; } public static String mod(String T_model){ Machine.Model = T_model; return Model; } public void S_truck(){ System.out.println(Truck.mod("小型货车")); Laden S_l = new Truck(); System.out.println("载货量为:"+S_l.Ccy(5.0)+"T"); System.out.println("500元/天"); } public void B_truck(){ System.out.println(Truck.mod("大型货车")); Laden B_l = new Truck(); System.out.println("载货量为:"+B_l.Ccy(25.0)+"T"); System.out.println("1500元/天"); } }
package Dadacar; //皮卡子类 public class Pickup extends Machine implements Passenger, Laden { public static String mod(String T_model){ Machine.Model = T_model; return Model; } public double Ccy(double T_ccy) { Machine.CargoCapacity = T_ccy; return CargoCapacity; } public int Cpy(int T_cpy) { Machine.Capacity = T_cpy; return Capacity; } public void Pickup(){ System.out.println(Pickup.mod("皮卡")); Laden P_l = new Pickup(); System.out.println("载货量为:"+P_l.Ccy(1.0)+"T"); Passenger P_p = new Pickup(); System.out.println("载客量为:"+P_p.Cpy(5)+"人"); System.out.println("700元/天"); } }
package Dadacar; import java.util.Scanner; //调试mian函数 public class Debugging { static int days; public static int Daynum(int newday){ Scanner PutIn = new Scanner(System.in); System.out.println("是否需要购买此车Y/N"); String Put = PutIn.nextLine(); char In = Put.charAt(0); if(In=='Y'||In=='y'){ System.out.println("请输入租车天数"); newday =PutIn.nextInt(); if(newday>30){System.out.println("您输入的数量不能大于30"); newday = 0;} Debugging.days = 0; days = newday; return days;}else{return 0;} } public static void main(String[] args) { System.out.println("是否进入租车系统Y/N"); Scanner GetInto = new Scanner(System.in); String Get =GetInto.nextLine(); char Into = Get.charAt(0); if(Into=='Y'||Into=='y'){ int money = 0; Truck T_truck = new Truck(); Coach T_coach = new Coach(); Pickup T_pickup = new Pickup(); int num = 0; do{ System.out.println("你可以租用的车子有:"); System.out.println("您当前需要支付金额是"+money+"元"); System.out.println("1.小型货车"); System.out.println("2.大型货车"); System.out.println("3。小型客车"); System.out.println("4.大型客车"); System.out.println("5.皮卡"); System.out.println("0.结算金额"); System.out.println("请输入你要租用的汽车编号"); int Number = GetInto.nextInt(); switch(Number){ case 1:T_truck.S_truck(); Debugging.Daynum(0); money = money+(500*days); break; case 2:T_truck.B_truck(); Debugging.Daynum(0); money = money+(1500*days); break; case 3:T_coach.S_coach(); Debugging.Daynum(0); money = money+(2500*days); break; case 4:T_coach.B_coach(); Debugging.Daynum(0); money = money+(800*days); break; case 5:T_pickup.Pickup(); Debugging.Daynum(0); money = money+(700*days); break; case 0:System.out.println("已退出选车"); num=num+1; break; } }while(num==0); System.out.println("您租车的费用总共是"+money); }else if(Into=='N'||Into=='n'){ System.out.println("退出租车系统!"); } else { System.out.println("输入错误,自动退出"); } } }
老师给的那个我没看清楚,就根据自己这几天学的写了一下