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

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

研究了兩天的代碼,求大神指點

//父類

package com.tow;


public abstract class Car {

int number;

String name;

float price;

public Car(int number,String name,float price){

this.number=number;

this.name=name;

this.price=price;

}

? ? @Override

public String toString() {

return number+"\t"+name+"\t"+price+"\n";

}


public int getCarcapacity() {

// TODO Auto-generated method stub

return 0;

}


public int getTrackcapacity() {

// TODO Auto-generated method stub

return 0;

}


? ??

}

//子類1

package com.tow;


public class Cars extends Car {

private int Carcapacity;

public Cars(int number, String name, float price,int Carcapacity) {

super(number, name, price);

this.setCarcapacity(Carcapacity);

// TODO Auto-generated constructor stub

}


public int getCarcapacity() {

return Carcapacity;

}


public void setCarcapacity(int carcapacity) {

Carcapacity = carcapacity;

}


@Override

public String toString() {

return number+"\t"+name+"\t"+price+"\t\t"+Carcapacity+"\n";

}


}

//子類2

package com.tow;


public class Track extends Car {

private int Trackcapacity;

public Track(int number, String name, float price,int Trackcapacity) {

super(number, name, price);

this.setTrackcapacity(Trackcapacity);

// TODO Auto-generated constructor stub

}



public int getTrackcapacity() {

return Trackcapacity;

}


public void setTrackcapacity(int trackcapacity) {

Trackcapacity = trackcapacity;

}


@Override

public String toString() {

return number+"\t"+name+"\t"+price+"\t\t\t"+Trackcapacity+"\n";

}


}

//子類3

package com.tow;


public class Pickup extends Car {

private int Carcapacity;

private int Trackcapacity;

public Pickup(int number, String name, float price,int Carcapacity,int Trackcapacity) {

super(number, name, price);

this.setCarcapacity(Carcapacity);

this.setTrackcapacity(Trackcapacity);

// TODO Auto-generated constructor stub

}

public int getCarcapacity() {

return Carcapacity;

}

public void setCarcapacity(int carcapacity) {

Carcapacity = carcapacity;

}

public int getTrackcapacity() {

return Trackcapacity;

}

public void setTrackcapacity(int trackcapacity) {

Trackcapacity = trackcapacity;

}

@Override

public String toString() {

return number+"\t"+name+"\t"+price+"\t\t"+Carcapacity+"\t"+Trackcapacity+"\n";

}


}

//測試類

package com.tow;

import java.util.*;

public class Initail {


public static void main(String[] args) {

// TODO Auto-generated method stub

? ? @SuppressWarnings("resource")

Scanner input=new Scanner (System.in);

? ? System.out.println("##歡迎使用DADA租車系統##");

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

? ? int choice=input.nextInt();

? ? switch(choice){

? ? case 1:

? ? System.out.println("下面是租車信息:");

? ? System.out.println("序號"+"\t"+"車型"+"\t"+"單價(天/元)"+"\t"+"載客以及載貨量(t)");

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

? ? news[0]=new Cars(1,"奧迪A8",800,5);

? ? news[1]=new Cars(2,"金龍大巴",700,50);

? ? news[2]=new Track(3,"金杯",400,45);

? ? news[3]=new Track(4,"東風悅達",650,70);

? ? news[4]=new Pickup(5,"皮卡",500,4,60);

? ? System.out.println(Arrays.toString(news));

? ? System.out.print("請您輸入租賃天數:");

? ? ?int day=input.nextInt();

? ? ?System.out.println("租用:"+day+"天");

? ? ?System.out.println("請您根據車型序號選擇車型,輸入“8”結束");

? ? ?int[] rent=new int[6];

? ? for(int i=1;i<6;i++){

? ?

? ? ? ? System.out.print("請輸入您要選擇的車型:");

? ? ? ? ? int score1=input.nextInt();

? ? ? ? ? if(score1==8){

? ? ? ? break;

? ? ? ? ? }else{

? ? ? ? ? ?System.out.print("請輸入您要組的數量:");

? ? ? ? ? ?int score2=input.nextInt();

? ? ? ? ? ?float sum=news[score1-1].price*day;

? ? ? ? ? ?System.out.println("車型:"+news[score1-1].name+"\t"+score2+"輛"+"\t"+"合計"+sum+"元");?

? ? ? ? ? ?float sum2=0;

? ? ? ? ? ?sum2=sum+sum2;

? ? ? ? ? ?System.out.println("總計:"+sum2);

? ? ? ? ? ?rent[score1]=score2;

? ? }

? ? ? ? ??

? ? }

? ?

? ? System.out.println("如下是您的租車信息,請您核對:");

? ? float sum=0;

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

? ? if(rent[i]!=0){

? ? System.out.println(news[i-1].name+":\t"+rent[i]+"輛"+"\t"+"單價(元/天):"+rent[i]*news[i-1].price+"\t\t"+"載客量:"+"\t"+rent[i]*news[i-1].getCarcapacity()+"人"+

? ? ? ? "\t"+"載重量:"+rent[i]*news[i-1].getTrackcapacity()+"噸"+"\t"+"合計:"+rent[i]*(rent[i]*news[i-1].price)*day+"元");

? ? sum+=rent[i]*rent[i]*news[i-1].price*day;

? ? }

? ?

? ? }

? ? System.out.println("租車總費用:"+sum+"元");

? ? break;

? ? case 2:

? ? System.out.println("歡迎使用,再見!");

? ? break;

? ? default:

? ? System.out.println("您的輸入有誤,請重新輸入!");

? ? }

? ??

}


}


正在回答

1 回答

可以去面試去了

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

舉報

0/150
提交
取消

研究了兩天的代碼,求大神指點

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

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

幫助反饋 APP下載

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

公眾號

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