为了账号安全,请及时绑定邮箱和手机立即绑定

java问题求大神解决!(目测应该是我的主程序中数组赋值调用那一块的问题)

标签:
Java

哇,很难受,做了整整一天最后还是有问题,有大神能帮我看看哪里出错了吗

che父类

package zuche;

public abstract class che {
public abstract void num(int nums);
public abstract String id();
public abstract int price();
public abstract int nongliang();
public abstract int huowu() ;
}

a子类
package zuche;

public class a extends che {

@Override
public void num(int nums) {
    // TODO Auto-generated method stub

  System.out.print(nums);
}

@Override
public String id() {
    // TODO Auto-generated method stub
    String name="奥迪A4";

System.out.print(" 奥迪A4 ");
return name;
}

@Override
public int price() {
    // TODO Auto-generated method stub
    int p1=500;
    System.out.print(     p1+"/天   ");
    return p1;
}

@Override
public int nongliang() {
    // TODO Auto-generated method stub
    int person=4;

System.out.print(" 载人:"+person+"人");
return person;
}

@Override
public int huowu() {
    // TODO Auto-generated method stub
    return 0;
}

}

b子类
package zuche;

public class b extends che {

@Override
public void num(int nums) {
    // TODO Auto-generated method stub
    System.out.print(nums);
}

@Override
public String id() {
    // TODO Auto-generated method stub
    String name="马自达6";
    System.out.print("     马自达6     ");
    return name;
}

@Override
public int price() {
    // TODO Auto-generated method stub
    int p1=400;
    System.out.print(     p1+"/天   ");
    return p1;
}

@Override
public int nongliang() {
    // TODO Auto-generated method stub
    int person=4;
      System.out.print("   载人:"+person+"人");
        return  person;
}

@Override
public int huowu() {
    // TODO Auto-generated method stub
    return 0;
}

}
c子类
package zuche;

public class c extends che {

@Override
public void num(int nums) {
    // TODO Auto-generated method stub
    System.out.print(nums);
}

@Override
public String id() {
    // TODO Auto-generated method stub
    String name="皮卡雪6";
    System.out.print("     皮卡雪6     ");
    return name;
}

@Override
public int price() {
    // TODO Auto-generated method stub
    int p1=450;
    System.out.print(     p1+"/天   ");
    return p1;
}

@Override
public int nongliang() {
    // TODO Auto-generated method stub
    int person=4;

      System.out.print("   载人:"+person+"人");
        return  person;
}

public int huowu(){

    int weight=2; 
    System.out.print("    载货:"+weight+"吨");

    return weight;
}

}

主程序
package zuche;
import java.util.Scanner;

public class intial {
public static void main(String[] args) {
System.out.println("欢迎使用吴彦祖的租车系统:");
System.out.println("您是否要租车:1是 其他否");
Scanner input=new Scanner(System.in);
int i=input.nextInt();
if(i==1){

       System.out.println("租车信息:");
       System.out.println("序号    汽车名称       租金         容量");

  che  c1=new a();
  c1.num(1);
  c1.id();
  c1.price();
  c1.nongliang();

  System.out.println();

  che  c2=new b();
  c2.num(1);
  c2.id();
  c2.price();
  c2.nongliang();
  System.out.println();

  che  c3=new c();
  c3.num(1);
  c3.id();
  c3.price();
  c3.nongliang();
  c3.huowu();
  System.out.println();

  System.out.println("输入你的租车数量:");

   int m=input.nextInt();

   int sum=0;
   String zairen[]=new String[]{};
   int ren=0;
   String zaihuo[]=new String[]{};
   int huo=0;
  for(int x=0;x<m;x++){
      System.out.println("输入第"+(x+1)+"辆车的序号:");
      int m2=input.nextInt();
      int numm=0;
      int huoo=0;
      switch(m2){

      case 1:
          che a=new a();
          zairen[x]=a.id();
          ren=a.nongliang()+ren;
          huo=a.huowu()+huo;
          numm=numm+1;

          sum=a.price()+sum;
       break;

      case 2:
          che b=new b();
          zairen[x]=b.id();
          ren=b.nongliang()+ren;
          huo=b.huowu()+huo;
          numm=numm+1;
          sum=b.price()+sum;
       break;

      case 3:
          che c=new c();
          zaihuo[x]=c.id();
          ren=c.nongliang()+ren;
          huo=c.huowu()+huo;
          huo=huo+1;
          sum=c.price()+sum;
       break;
          }

  }
  System.out.println("输入租车天数:");

   int t=input.nextInt(); 
   sum=sum*t;

   System.out.println("***可载人的车有:");
   System.out.print(zairen[2]+"    共载人:"+ren);
   System.out.println("***可载客的车有:");
   System.out.print(zaihuo[1]+"    共载货:"+huo);
   System.out.println("***总租车金额:"+sum+"元");
   }else{

       System.out.println("谢谢惠顾");
   }

}
}

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消