請(qǐng)老師幫我看看我的代碼,最后幾行有個(gè)問題請(qǐng)幫我解決。謝謝了
-----------------------------------------------------------------
package transportSystem; //父類
public abstract class transportSystem {
public abstract void type();
public int cost(int newday, int type) {
// TODO Auto-generated method stub
return 0;
}
public int cost(int newday) {
// TODO Auto-generated method stub
return 0;
}
}
-----------------------------------------------------------------------
package transportSystem; ? //子類 ? truck
public class truck extends transportSystem {
int price=1000;
int price2=1800;
int day;
int type;
@Override
public void type() {
// TODO Auto-generated method stub
System.out.println("4 輕卡東風(fēng) ?"+price+"/天 ? 可載人數(shù):2人 ? 載重:25T");
System.out.println("5 重卡斯太爾 ?"+price2+"/天 ? 可載人數(shù):2人 ? ?載重:50T");
}
@Override
public ?int cost(int newday,int type) {//對(duì)應(yīng)租賃天數(shù),租賃車型,租賃數(shù)量
this.day=newday;
this.type=type;
int cost2=price2*day;
int cost=price*day;
if(type==4)
{
System.out.println("租賃輕卡東風(fēng)"+day+"天總的花費(fèi)是:"+cost);
}
if(type==5)
{
System.out.println("租賃重卡斯太爾"+day+"天總的花費(fèi)是:"+cost2);
}
// TODO Auto-generated method stub
return 0;
}
}
package transportSystem; ? //子類 ? bus
public class bus extends transportSystem {
int price=250;
int price2=450;
int day;
int type;
@Override
public void type() {
// TODO Auto-generated method stub
System.out.println("1 北京大眾 ?"+price+"/天 ? 可載人數(shù):4人 ?");
System.out.println("2 寶馬5系 ?"+price2+"/天 ? 可載人數(shù):4人 ?");
}
@Override
public ?int cost(int newday,int type) {//對(duì)應(yīng)租賃天數(shù),租賃車型,租賃數(shù)量
this.day=newday;
this.type=type;
int cost2=price2*day;
int cost=price*day;
if(type==1)
{
System.out.println("租賃北京大眾"+day+"天總的花費(fèi)是:"+cost);
}
if(type==2)
{
System.out.println("租賃寶馬5系"+day+"天總的花費(fèi)是:"+cost2);
}
// TODO Auto-generated method stub
return 0;
}
--------------------------------------------------------------------
package transportSystem;????????//子類pKa
public class pKa extends transportSystem {
int price=300;
int day;
@Override
public void type()?
{
// TODO Auto-generated method stub
System.out.println("3 三菱皮卡 ?"+price+"/天 ? 可載人數(shù):4人 ? ?載重:15T");
}
@Override
public int ?cost(int newday) {
this.day=newday;
int cost=day*price;
System.out.println("租賃三菱皮卡"+day+"天總的花費(fèi)是:"+cost);
return 0;
// TODO Auto-generated method stub
}
}
----------------------------------------------------------------------------
package transportSystem;
import java.util.*;
public class Initial { ?//接收測(cè)試
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
System.out.println("歡迎來到中國(guó)通運(yùn)租賃服務(wù)!繼續(xù)服務(wù)請(qǐng)輸入1,終止服務(wù)請(qǐng)輸入0");
int num=in.nextInt();
int numcar ;
int gDay;
//int[] car=new int[]{1,2,3,4,5};//"北京大眾","寶馬5系","三菱皮卡","輕卡東風(fēng)","重卡斯太爾"
if(num==1){
System.out.println("感謝您使用中國(guó)通云服務(wù),以下是服務(wù)菜單,請(qǐng)輸入您需要租賃汽車的數(shù)量");
transportSystem a=new bus();
transportSystem b=new pKa();
transportSystem c=new truck();
a.type();
b.type();
c.type();
int put=in.nextInt();
for(int i=1;i<=put;i++)//輸入需要汽車數(shù)量的編號(hào)循環(huán)操作
{
System.out.println("請(qǐng)輸入第"+i+"輛的車輛序號(hào)");
numcar=in.nextInt();
System.out.println("請(qǐng)輸入租賃的天數(shù)");
gDay=in.nextInt();
if(numcar==1||numcar==2)//輸入序號(hào)確認(rèn)租賃車輛型號(hào)
{
a.cost(gDay,numcar);//計(jì)算該型號(hào)費(fèi)用
}
if(numcar==3)//輸入序號(hào)確認(rèn)租賃車輛型號(hào)
{
b.cost(gDay);//計(jì)算該型號(hào)費(fèi)用
}
if(numcar==4||numcar==5)//輸入序號(hào)確認(rèn)租賃車輛型號(hào)
{
c.cost(gDay,numcar);//計(jì)算該型號(hào)費(fèi)用
}
//合并總計(jì)金額該如何進(jìn)行操作呢? 到這步我卡主了,后續(xù)完全銜接不了。怪自己知識(shí)有限?
}System.out.println("感謝您使用中國(guó)通云租賃服務(wù),,歡迎再次光臨,祝你一帆風(fēng)順!");
}
else
{
System.out.println("感謝您對(duì)中國(guó)通云的支持,期待您再次光臨!");
}
}
}
2015-12-25
寫幾個(gè)個(gè)return,把返回的數(shù)相加,計(jì)算總價(jià)
2015-12-25
合并全部加起來不就OK了么
2015-12-25
這是什么問題呢!