第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

代碼初步寫成這樣,希望能夠得到改進意見,謝謝

package com.demo;


import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;


public class Rental {

/**

* @param args

*/

public static void main(String[] args) {

System.out.println("歡迎使用答答租車系統(tǒng)!");

System.out.println("是否進入租車界面:");

System.out.println("1:進入 ? 0:退出");

Scanner putInScanner = new Scanner(System.in);

int putIn = putInScanner.nextInt();

if (putIn==1) {

System.out.println("可選擇車的類型及其價目:");

System.out.println("序號"+"\t"+"汽車名稱"+"\t\t"+"租金(元/天)"+"\t"+"載人量(人)"+"\t"+"載貨量(噸)");

Car[] cars = {new Coach(1, "奧迪A4", 500, 4,0),new Coach(2, "馬自達6", 400, 4,0)

,new PickUP(3, "皮卡雪6", 450, 4,2),new Coach(4, "金龍", 800, 20,0)

,new Truck(5,"松花江",400,0,4),new Truck(6,"依維柯",1000,0,20)};

//顯示價目表

for (Car car : cars) {

System.out.println(car.getId()+"\t"+car.getCarName()+"\t\t"+car.getCarRent()+"\t\t"+

car.getNumber()+"\t\t"+car.getCargoes());

}

System.out.println("請輸入租車的數(shù)目:");

List<Car> carList = new ArrayList<Car>();

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

carList.add(cars[i]);

}

int money = 0;//總錢數(shù)

int amount = putInScanner.nextInt();

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

int oneMoney = 0;//單個的錢數(shù)

System.out.println("請輸入第"+(i+1)+"輛車的序號");

int num = putInScanner.nextInt();

System.out.println("該車使用幾天:");

int day = putInScanner.nextInt();

System.out.println("已成功添加:"+carList.get(num-1).getCarName());

oneMoney = carList.get(num-1).getCarRent()*day + oneMoney;

System.out.println("該車花費"+oneMoney+"元");

money = money + oneMoney;

}

System.out.println("總計金額:"+money+"元");

System.out.println("感謝您的使用,再見!");

} else {

System.out.println("已退出租車系統(tǒng)!");

}


}


}

package com.demo;


/**

?* 抽象類:車

?* @author Administrator

?*

?*/

public class Car {

private int id;//序號

private int number;//載人量

private int cargoes;//載貨量

private String carName;//車名

private int carRent;//租金

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}


public int getNumber() {

return number;

}

public void setNumber(int number) {

this.number = number;

}


public int getCargoes() {

return cargoes;

}

public void setCargoes(int cargoes) {

this.cargoes = cargoes;

}


public String getCarName() {

return carName;

}

public void setCarName(String carName) {

this.carName = carName;

}


public int getCarRent() {

return carRent;

}

public void setCarRent(int carRent) {

this.carRent = carRent;

}


//id:序號;carName:汽車名稱;rent:租金;number:載人量;cargoes:載貨量

public Car(int id,String carName,int rent,int number,int cargoes){

this.setId(id);

this.setCarName(carName);

this.setCarRent(rent);

this.setCargoes(cargoes);

this.setNumber(number);

}


}

package com.demo;


/**

?* 貨車

?* @author Administrator

?*

?*/

public class Truck extends Car{


public Truck(int id, String carName, int rent, int number, int cargoes) {

super(id, carName, rent, number, cargoes);

this.setId(id);

this.setCarName(carName);

this.setCarRent(rent);

this.setCargoes(cargoes);

this.setNumber(number);

}


}

package com.demo;


/**

?* 客車

?* @author Administrator

?*

?*/

public class Coach extends Car {


public Coach(int id, String carName, int rent, int number, int cargoes) {

super(id, carName, rent, number, cargoes);

this.setId(id);

this.setCarName(carName);

this.setCarRent(rent);

this.setCargoes(cargoes);

this.setNumber(number);

}


}

package com.demo;


/**

?* 皮卡

?* @author Administrator

?*

?*/

public class PickUP extends Car {


public PickUP(int id, String carName, int rent, int number, int cargoes) {

super(id, carName, rent, number, cargoes);

this.setId(id);

this.setCarName(carName);

this.setCarRent(rent);

this.setCargoes(cargoes);

this.setNumber(number);

}

}


正在回答

1 回答

輸入超出范圍的情況沒有考慮

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

代碼初步寫成這樣,希望能夠得到改進意見,謝謝

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號