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

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

怎么把這種固定車輛變成可添加的呢? 是直接在數(shù)組上面加? 還是就是我覺得我直接這樣寫的代碼不太嚴謹,怎么修改呢?

package com.dadazhuche;
import com.car.*;
import java.util.*;

public class test {

?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?Car[] che= {new Passeng("奧迪A4",500,4),new Passeng("馬自達6",400,4),new Passeng("金龍",800,20)
?? ??? ??? ??? ?,new Pika("皮卡雪",450,4,2),new Carry("松花江",400,4),new Carry("依維柯",1000,20)};
?? ??? ?System.out.println("是否要租車:1:是,0:否");
?? ??? ?Scanner o=new Scanner(System.in);
?? ??? ?if(o.nextInt()==1) {
?? ??? ??? ?System.out.println("序號\t汽車名稱\t金額\t\t容量");
?? ??? ??? ?for(int i=0;i<che.length;i++) {
?? ??? ??? ??? ?System.out.println((i+1)+che[i].toString());
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else {
?? ??? ??? ?System.out.println("歡迎再來");
?? ??? ?}
?? ??? ?System.out.println("請輸入要租車的數(shù)量");
?? ??? ?Scanner p=new Scanner(System.in);
?? ??? ?int e=p.nextInt();
?? ??? ?if(e>0) {
?? ??? ??? ?System.out.println("???????????? ");
?? ??? ??? ?System.out.println("輸入要租的天數(shù)");
?? ??? ??? ?Scanner s=new Scanner(System.in);
?? ??? ??? ?int j =s.nextInt();
?? ??? ??? ?int a=0;
?? ??? ??? ?if(j>0) {
?? ??? ??? ??? ?for(int i=1;i<=e;i++) {
?? ??? ??? ??? ??? ?System.out.println("輸入序號"+i+"車");
?? ??? ??? ??? ??? ?Scanner w=new Scanner(System.in);
?? ??? ??? ??? ??? ?int k=w.nextInt();
?? ??? ??? ??? ??? ?a+=che[k-1].cost(j);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?System.out.println("價格為"+a+"元");
?? ??? ??? ?}
?? ??? ?}
?? ?}
}




父類car

package com.car;

public class Car {

?? ?public int cost(int j){
?? ??? ?return 0;
?? ?}
}


三大子類

package com.car;

public class Carry extends Car {
?? ?String name;
?? ?int price;
?? ?int weigh;
?? ?public Carry(String name,int price,int weigh) {
?? ??? ?this.name=name;
?? ??? ?this.price=price;
?? ??? ?this.weigh=weigh;
?? ?}
?? ?public int cost(int j){
?? ??? ?int sum=this.price*j;
?? ??? ?return sum;
?? ?}
?? ?@Override
?? ?public String toString() {
?? ??? ?return "\t"+name + "\t" + price+"元/天\t"+ "\t載貨:"+weigh+"噸? ";
?? ?}
?? ?
}



package com.car;

public class Passeng extends Car {
?? ?String name;
?? ?int price;
?? ?int capacity;
?? ?public Passeng(String name,int price,int capacity) {
?? ??? ?this.name=name;
?? ??? ?this.price=price;
?? ??? ?this.capacity=capacity;
?? ?}
?? ?public int cost(int j){
?? ??? ?int sum=this.price*j;
?? ??? ?return sum;
?? ?}
?? ?public String toString() {
?? ??? ?return "\t"+name + "\t" + price +"元/天\t"+ "\t載人:"+capacity+"人 ";
?? ?}
}



package com.car;

public class Pika extends Car {
?? ?String name;
?? ?int price;
?? ?int weigh;
?? ?int capacity;
?? ?public Pika(String name,int price,int capacity,int weigh) {
?? ??? ?this.name=name;
?? ??? ?this.price=price;
?? ??? ?this.weigh=weigh;
?? ??? ?this.capacity=capacity;
?? ?}
?? ?public int cost(int j){
?? ??? ?int sum=this.price*j;
?? ??? ?return sum;
?? ?}

?? ?public String toString() {
?? ??? ?return "\t"+name + "\t" + price+"元/天\t" + "\t載人:"+capacity+"人 載貨: "+weigh+"噸";
?? ?}
?? ?

}







正在回答

1 回答

public class EasycarTest {


public static void main(String[] args) {

// TODO Auto-generated method stub

Car[] car=new Car[10];

car[0]=new PassengerCar("奧迪A4",500,4);

car[1]=new PassengerCar("馬自達6",400,4);

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

car[3]=new PassengerCar("金龍? ? ? ? ? ",800,20);

car[4]=new Truck("松花江",400,4);

car[5]=new Truck("依維柯",1000,20);

/*

如果要從界面輸入就需要做界面錄入的代碼了.僅供參考



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

舉報

0/150
提交
取消

怎么把這種固定車輛變成可添加的呢? 是直接在數(shù)組上面加? 還是就是我覺得我直接這樣寫的代碼不太嚴謹,怎么修改呢?

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

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

幫助反饋 APP下載

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

公眾號

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