请老师帮我看看我的代码,最后几行有个问题请帮我解决。谢谢了
-----------------------------------------------------------------
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("感谢您对中国通云的支持,期待您再次光临!");
}
}
}