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

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

終于寫完了,達達租車系統(tǒng),歡迎各位討論!

Car類


package com.dadacar;


public class Car {

private int number;//車輛編號

? ? private String name;//車名

? ? private double price;//租金

? ? public? Car(int number,String name ,double price) {

? ? this.number=number;

? ? this.name = name;

? ? this.price = price;

? ? }

? ? public int getNumber()

? ? {

? ? return number;

? ? }

? ? public String getName()

? ? {

? ? return name;

? ? }

? ? public double getPrice()

? ? {

? ? return price;

? ? }

? ? public String toString()

? ? {

? ? return? "車輛序號: "+number+'\t'+"車型: "+name+'\t'+"租金: "+price+'元'+'\t'+'\t';

? ? }

}

passengerCar類

package com.dadacar;


public class passengerCar extends Car {

? ?private int persons;//載人量

public passengerCar(int number,String name, double price, int persons) {

super(number,name, price);

this.persons=persons;

}

public int getPersons()?

{

return persons;

}

public String toString()

{

return super.toString()+"載客量: "+persons+'人';

}


}

pickCar類


package com.dadacar;


public class pickCar extends? Car{

? ?private int? persons;

? ?private double Capacity;

public pickCar(int number,String name, double price,double pickCapacity,int pickPersons) {

super(number,name, price);

// TODO Auto-generated constructor stub

this.Capacity=pickCapacity;

this.persons=pickPersons;

}

public int getPersons() {

return persons;

}

public double getCapacity() {

return Capacity;

}

public String toString()

? ?{

? ?return super.toString()+"載客量:"+Capacity+'噸'+'\t'+"載客量:"+persons+'人';

? ?}

}

TruckCar類


package com.dadacar;


public class TruckCar extends Car {

private double Capacity;//載貨量

public TruckCar(int number,String name,double price,double cargoCapacity)

{

super(number,name,price);

this.Capacity = cargoCapacity;

}

? ?public double getCapacity() {

return Capacity;

}

? ?public String toString()

? ?{

? ?return super.toString()+"載貨量:"+'\t'+Capacity+'噸';

? ?}

}

test類


package com.dadacar;

import java.lang.System;

import java.util.Scanner;


public class test {


public static void main(String[] args) {

// TODO Auto-generated method stub

? ? ? ?Car[] cars = new Car[5];

? ? ? ?cars[0]=new TruckCar(1,"重型卡車 ",460,4.5);

? ? ? ?cars[1]=new TruckCar(2,"輕型卡車 ",300,3.5);

? ? ? ?cars[2]=new passengerCar(3,"大客車",500,45);

? ? ? ?cars[3]=new passengerCar(4,"小客車",400,30);

? ? ? ?cars[4]=new pickCar(5,"皮卡",450,3.5,6);

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

System.out.println("請問您是否要租車?? 1.是? ?2.否");

Scanner s = new Scanner(System.in);

int yn =s.nextInt();

if(yn==1) {

/*顯示車輛類型*/

System.out.println("您可租車的類型及其價目表:");

System.out.println("序號" + '\t' + "汽車名稱" + '\t' + "租金" + '\t' +"容量"+'\t');

for(Car c :cars)?

System.out.println(c.toString());

double totalprice=0;//總金額

double totalPersons = 0;//總載客量

double totalCapicity=0;//總載物量

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

int sl=s.nextInt();

? ?Car[] rentCar = new Car[sl];

? ?for (int i = 0; i < sl; i++) {

? ? ? ? ? ? System.out.printf("請輸入第%d輛車的序號:",i+1);

? ? ? ? ? ?int num=s.nextInt();//捕捉用戶輸入車的序號并存入數(shù)組

? ? ? ? rentCar[i]=cars[num-1];

? ?}

? ?/*計算總?cè)藬?shù)和總載客量*/

? ?for(int i=0; i<sl;i++)

? ?{

? ?if(rentCar[i] instanceof passengerCar) {

? ?totalPersons += ((passengerCar)rentCar[i]).getPersons();

? ?}

? ?if(rentCar[i] instanceof TruckCar) {

? ?totalCapicity+=((TruckCar)rentCar[i]).getCapacity();

? ?}

? ? ? if(rentCar[i] instanceof pickCar) {

? ? totalPersons+=((pickCar)rentCar[i]).getPersons();

? ? ? ? totalCapicity+=((pickCar)rentCar[i]).getCapacity();

? ? ? ? }

? ?}

? ?/*計算總金額*/

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

? ?int days=s.nextInt();

? ?

? ? ? ? ? ? ? ?for(int i=0;i<sl;i++) {

? ? ? ? ? ? ? ?totalprice=totalprice+rentCar[i].getPrice()*days;

? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?/*顯示賬單*/

? ?System.out.println("********************您的賬單如下:******************** ");

? ?System.out.println(">>>>>>>已經(jīng)選擇載人車: ");

? ?for(int i=0;i<sl;i++) {

? ?if(rentCar[i].getNumber()>2) {

? ?System.out.println(rentCar[i].getName());

? ?}else {

? ?continue;

? ?}

? ?}

? ?System.out.println(">>>>>>>已經(jīng)選擇載貨車: ");

? ?for(int i=0;i<sl;i++) {

? ?if(rentCar[i].getNumber()<=2) {

? ?System.out.println(rentCar[i].getName());

? ?}else {

? ?continue;

? ?}

? ?}

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

? ?System.out.println("您所租借的車總載客量為: "+totalPersons+"人\t");

? ?System.out.println("您所租借的車總載貨量為: "+totalCapicity+"噸\t");

? ?System.out.println("總費用為"+totalprice+"元");

? ?

}else if(yn==0) {

s.close();

}

}

}

生成圖

https://img1.sycdn.imooc.com//5c50238f0001c98606530817.jpg

歡迎大家給出優(yōu)化意見。

正在回答

3 回答

https://img1.sycdn.imooc.com//5c88777f0001474d09120258.jpg處理輸入錯誤

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

我的寫法和你差不多,但是為啥rentCar[ ]這個數(shù)組就無法調(diào)用那些變量和方法

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

進入答租車系統(tǒng)輸入的是1和0之外的數(shù)會怎么樣呢

0 回復 有任何疑惑可以回復我~
#1

一葉知秋_見微知著

多一個else 加個提示就好,不要鉆牛角尖咯
2019-01-31 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531100    人
  • 解答問題       6280    個

課程升級!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會Java面向?qū)ο缶幊痰膴W妙

進入課程

終于寫完了,達達租車系統(tǒng),歡迎各位討論!

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

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

幫助反饋 APP下載

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

公眾號

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