为了账号安全,请及时绑定邮箱和手机立即绑定

嘤嘤嘤,第一次写好难啊

public abstract class Car {

         private String name;

         private int rent;

        

         public Car(String name,int rent) {

                 this.name = name;

                 this.rent = rent;

         }

         public abstract void printContent(int i) ;

         public String getName() {

                  return name;

         }

         public void setName(String name) {

                 this.name = name;

         }

         public int getRent() {

                 return rent;

         }

         public void setRent(int rent) {

                  this.rent = rent;

         }       

}

public class PassengerCar extends Car{

         private int mannedCapacity;

         public PassengerCar(String name,int mannedCapacity,int rent) {

                  super(name,rent);

                  this.mannedCapacity = mannedCapacity;

         }

         public void printContent(int i) {

                  System.out.println((i+1)+"\t"+super.getName()+"\t"+super.getRent()+"\t载人:"+mannedCapacity+"人");

         }

         public int getMannedCapacity() {

                  return mannedCapacity;

         }

         public void setMannedCapacity(int mannedCapacity) {

                  this.mannedCapacity = mannedCapacity;

         }

}


public class TruckCar extends Car{

         private int carryCapacity;

         public TruckCar(String name,int carryCapacity,int rent) {

                  super(name,rent);

                 this.carryCapacity = carryCapacity;

         }

         public void printContent(int i) {

                 System.out.println((i+1)+"\t"+super.getName()+"\t"+super.getRent()+"\t载人:"+carryCapacity+"人");

         }

         public int getCarryCapacity() {

                  return carryCapacity;

         }

         public void setCarryCapacity(int carryCapacity) {

                  this.carryCapacity = carryCapacity;

         }

}

public class PickupTruck extends Car{

         private int mannedCapacity;

         private int carryCapacity;

         public PickupTruck(String name,int carryCapacity,int mannedCapacity,int rent) {

                  super(name,rent);

                  this.mannedCapacity = mannedCapacity;

                 this.carryCapacity = carryCapacity;

         }

         public void printContent(int i) {

                 System.out.println((i+1)+"\t"+super.getName()+"\t"+super.getRent()+"\t载人:"+mannedCapacity+"人"+",

                                                载货:"+carryCapacity+"吨");

         }

        

         public int getMannedCapacity() {

                  return mannedCapacity;

         }

         public void setMannedCapacity(int mannedCapacity) {

                  this.mannedCapacity = mannedCapacity;

         }

         public int getCarryCapacity() {

                  return carryCapacity;

         }

         public void setCarryCapacity(int carryCapacity) {

                 this.carryCapacity = carryCapacity;

         }

}

import java.util.Scanner;


public class RentCarManger {

         Car[] rentalCars = new Car[6];

         int rentedCarNum = 0;

         Car[] rentedBills = new Car[6]; 

         int rentedDay = 0;

         int rentedPrice = 0;

         Scanner sc = new Scanner(System.in);

         public void initial() {

                     rentalCars[0] = new PassengerCar("奥迪A4", 4, 500);

                     rentalCars[1] = new PassengerCar("马自达6", 4, 400);

                     rentalCars[2] = new PickupTruck("皮卡雪6", 2, 4, 450);

                     rentalCars[3] = new PassengerCar("金龙", 20, 800);

                     rentalCars[4] = new TruckCar("松花江", 4, 400);

                     rentalCars[5] = new TruckCar("依维柯", 20, 1000);

         }

         public void rentCar() {

                     initial();

                     System.out.print("欢迎使用答答租车系统:\n您是否要租车:(1是 0否)");

                     int answer = sc.nextInt();

                     if(answer==1) {

                                 System.out.println("**************************");

                                 carMenu();

                                 System.out.println("**************************");

                                 rentOperater();

                                 System.out.println("**************************");

                                 showBill();

                     }else{

                     return;

                     }

         }

         public void carMenu() {

                     System.out.println("您可租车的类型及其价目表:");

                     System.out.println("序号\t汽车名称\t租金\t容量");

                     for(int i=0;i<rentalCars.length;i++) {

                     rentalCars[i].printContent(i);

                     }

         }        

         public void rentOperater() {

                     System.out.print("请输入您要租的汽车的数量:");

                     int carNum = sc.nextInt();

                     for(int i=0;i<carNum;i++) {

                                  System.out.print("请输入您选择的第"+(i+1)+"辆车所对应的序号:");

                                 int num = sc.nextInt();

                                  rentedBills[i] = rentalCars[num-1];

                     }

                     rentedCarNum = carNum;

                     System.out.print("请输入租车天数:");

                     rentedDay = sc.nextInt();

         }

         public void showBill() {

                     System.out.println("您的账单:");

                     int sumPeople = 0;

                     int sumGoods = 0;

                     System.out.println("***可载人的车有:");

                     for(int i=0;i<rentedCarNum;i++) {

                                 if(rentedBills[i] instanceof PassengerCar) {

                                             PassengerCar pasCar = (PassengerCar)rentedBills[i];

                                             sumPeople += pasCar.getMannedCapacity();

                                             rentedPrice += pasCar.getRent();

                                             System.out.print(rentedBills[i].getName()+"\t");

                                 }

                                 if(rentedBills[i] instanceof PickupTruck) {

                                             PickupTruck picCar = (PickupTruck)rentedBills[i];

                                             sumPeople += picCar.getMannedCapacity();

                                             System.out.print(picCar.getName()+"\t");

                                 }

                     }

                     System.out.println("共载人:"+sumPeople+"人");

                     System.out.println("***可载货的车有:");

                     for(int i=0;i<rentedCarNum;i++) {

                                 if(rentedBills[i] instanceof TruckCar) {

                                             TruckCar truCar = (TruckCar)rentedBills[i];

                                             sumGoods += truCar.getCarryCapacity();

                                             rentedPrice += truCar.getRent();

                                             System.out.print(truCar.getName()+"\t");

                                 }

                                 if(rentedBills[i] instanceof PickupTruck) {

                                             PickupTruck picCar = (PickupTruck)rentedBills[i];

                                             sumGoods += picCar.getCarryCapacity();

                                             rentedPrice += picCar.getRent();

                                             System.out.print(picCar.getName()+"\t");

                                 }

                     }

                     System.out.println("共载货:"+sumGoods+"吨");

                     System.out.println("***租车总价格:"+(rentedPrice*rentedDay)+"元");

                     }

}

public class TestRentCarSys {

         public static void main(String[] args) {

                 RentCarManger rcmgr = new RentCarManger();

                 rcmgr.rentCar();

         }

}


正在回答

3 回答

怎么长吗


0 回复 有任何疑惑可以回复我~

我自己写的比你短很多,我自己写都我都不想回头看。。。。。你这。太厉害了。

0 回复 有任何疑惑可以回复我~

好多好多啊



0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

嘤嘤嘤,第一次写好难啊

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信