亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

嚶嚶嚶,第一次寫好難啊

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下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號