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