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

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

哎。這是我寫的 好吧我承認有抄的 有幾個子類還沒復制

package dadazuche;

import java.util.Scanner;

public class Initail {

public static void main(String[] args) {

Scanner input= new Scanner(System.in);

int rentsum = 0;

int i =0;

StringBuffer ?permessage = new StringBuffer();

StringBuffer ?goodsmessage = new StringBuffer();

int zairenshu=0;

int zaihuoshu=0;

System.out.println("歡迎使用答答租車系統:");

System.out.println("您是否要租車 :1 是 ? ?0 否");

int choose = input.nextInt();

Car cars[]={new Passenger("奧迪A4",500,4),new Passenger("馬自達6",400,4),new Pika("皮卡雪6",450,4,2),new Passenger("金龍",800,20),new Goods("松花江",400,4),new Goods("依維柯",1000,20)};

if(choose==0){

System.out.println("歡迎再次光臨!");

}

if (choose == 1){

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

}

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

System.out.print((i+1)+".\t");

if(cars[i] instanceof Passenger){

System.out.println(cars[i].name+"\t"+cars[i].rent+"元/天"+"\t"+"\t"+"載人:"+"\t"+cars[i].person+"人");}

if(cars[i] instanceof Goods){

System.out.println(cars[i].name+"\t"+cars[i].rent+"元/天 "+"\t"+"載貨:"+"\t"+cars[i].goods+"噸");}

if(cars[i] instanceof Pika){

System.out.println(cars[i].name+"\t"+cars[i].rent+"元/天"+"\t"+"\t"+"載人:"+"\t"+cars[i].person+"人"+"\t載貨:"+cars[i].goods+"噸");

}

}

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

int numberday=input.nextInt();

for (i=0;i<numberday;i++){

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

int xuhao = input.nextInt();

xuhao=xuhao-1;

if(cars[xuhao] instanceof Passenger){

rentsum+=cars[xuhao].rent;

permessage.append(cars[xuhao].name+"\t");

zairenshu+=cars[xuhao].person;

}

if(cars[xuhao] instanceof Goods){

rentsum+=cars[xuhao].rent;

goodsmessage.append(cars[xuhao].name+"\t");

zaihuoshu+=cars[xuhao].goods;

}

if(cars[xuhao] instanceof Pika){

rentsum+=cars[xuhao].rent;

permessage.append(cars[xuhao].name+"\t");

zairenshu+=cars[xuhao].person;

zaihuoshu+=cars[xuhao].goods;

}

}

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

int days=input.nextInt();

System.out.println("您的賬單:");

System.out.println("***可載人的車有:");

System.out.println(permessage+"可載人:"+zairenshu+"人");

System.out.println("***可載貨的車有:");

System.out.println(goodsmessage+"可載貨:"+zaihuoshu+"噸");

System.out.println("租車的總價格:"+rentsum*days);

}

}


正在回答

5 回答

哎 ? ?都是抄的 我只是分析了一下又自己編了一遍?

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

Pika 類

package dadazuche;


public class Pika extends Car {

public Pika(String name,int rent ,int person , int goods){

this.name=name;

this.rent = rent ;

this.person=person;

this.goods=goods;

}

}


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

Passenger 類

package dadazuche;


public class Passenger extends Car {

public Passenger(String name ,int rent ,int person){

this.name=name;

this.rent=rent;

this.person=person;

}

}


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

Goods類

package dadazuche;


public class Goods extends Car {

public Goods(String name,int rent,int goods){

this.name=name;

this.rent=rent;

this.goods=goods;

}

}

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

Car 類

package dadazuche;


public class Car {

protected String name;

protected int rent;

protected int person;

protected int goods;

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 int getPerson() {

return person;

}

public void setPerson(int person) {

this.person = person;

}

public int getGoods() {

return goods;

}

public void setGoods(int goods) {

this.goods = goods;

}

}

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

舉報

0/150
提交
取消

哎。這是我寫的 好吧我承認有抄的 有幾個子類還沒復制

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

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

公眾號

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