问答详情
源自:12-2 项目问题解析 1

参考了其余小伙伴的,然后花了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);

}

}


提问者:木木和呆呆 2016-05-14 14:42

个回答

  • Czjhit
    2016-05-14 16:01:55
    已采纳

    挺好的,,,很厉害的

  • Oldbig_Lin
    2016-10-11 16:40:43

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

  • 爱上明早
    2016-10-07 15:29:29

    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;  是什么意思啊

      

    }

  • 木木和呆呆
    2016-05-14 19:17:02

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

  • 慕粉七宝宝
    2016-05-14 19:07:25

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

    573706c50001d14905000255.jpg

    573706c500017bee05000399.jpg

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