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

参考了其余小伙伴的,然后花了6,7个小时做出来了,虽然时间久,但是我真的很开心

public class CarSystem {//这是一个父类

public String name;

public int rent;

public int people;

public int goods;

@Override

public String toString(){

return "车名"+name+" "+"租金"+rent+" "+"载人"+people+" "+"载物"+goods;

}

}


public class PassangerCar extends CarSystem {//这是能载人的子类

public PassangerCar(String name,int rent,int people){

this.name = name;

this.people = people;

this.rent = rent;

}

}

public class Trunk extends CarSystem {//这是载物的子类

public Trunk(String name,int rent,int goods){

this.name = name;

this.goods = goods;

this.rent = rent;

}

}

public class PickUp extends CarSystem {//这是能载人能载物的子类

public PickUp(String name,int rent,int people,int goods){

this.name = name;

this.people = people;

this.rent = rent;

}

}

import java.util.Scanner;//这是程序的入口

public class Initail {

public static void main(String[] args) {

CarSystem c[]={new PassangerCar("奥迪A4", 500, 4),

new PassangerCar("马自达6", 600, 4),

new PickUp("皮卡雪6", 450, 2, 4),

new PassangerCar("金龙", 800, 20),

new Trunk("松花江", 400, 4),

new Trunk("依维柯", 1000, 20)};

System.out.println("欢迎来到大大租车");

System.out.println("租车请按1走错请按0");

Scanner s=new Scanner(System.in);

int p=s.nextInt();

if(p==1){

System.out.println("您可以租车的类型及其价目表:");

for(int i=0;i<c.length;i++){

System.out.println("第"+(i+1)+"种车"+c[i]);

}

}else if(p==0){

System.out.println("谢谢点击");

}else{

System.out.println("输入错误");

}

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

Scanner input=new Scanner(System.in);

int[] a=new int[200]  ;

for(int i=0;i<c.length;i++){

System.out.println("请输入您对第"+(i+1)+"种车需要的数量:");

int q=input.nextInt();

a[i]=q*c[i].rent;

}

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

int t=input.nextInt();

System.out.println("您的账单:");

for(int i=0;i<c.length;i++){

System.out.println("租第"+(i+1)+"种车的费用是"+a[i]*t);

}

int sum=0;

for(int i=0;i<c.length;i++){

sum+=a[i]*t;

}

System.out.println("共计"+sum);

}

}


正在回答

5 回答

挺好的,,,很厉害的

1 回复 有任何疑惑可以回复我~
#1

木木和呆呆 提问者

非常感谢!
2016-05-14 回复 有任何疑惑可以回复我~

载人能载物的子类少了个 this.goods=goods;

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

for(int i=0;i<c.length;i++){

System.out.println("请输入您对第"+(i+1)+"种车需要的数量:");

int q=input.nextInt();

a[i]=q*c[i].rent;

}

哥哥  这个  a[i]=q*c[i].rent;  是什么意思啊

  

}

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

你主函数里的问题是car是一个数组,需要a[i]=num*car[i].rent 你先试试看,行不行,再回复我

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

为什么我会出现这些问题呢?能不能帮忙解答下?

573706c50001d14905000255.jpg

573706c500017bee05000399.jpg

我就是参考你的代码进行编写的,可是出现了这两类问题,小白不知道怎么改正;

0 回复 有任何疑惑可以回复我~
#1

爱学习的小灰

你的子类里面写错了吧
2016-06-20 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

参考了其余小伙伴的,然后花了6,7个小时做出来了,虽然时间久,但是我真的很开心

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号