參考了其余小伙伴的,然后花了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("請輸入你要租的車的數(shù)量:");
Scanner input=new Scanner(System.in);
int[] a=new int[200] ?;
for(int i=0;i<c.length;i++){
System.out.println("請輸入您對第"+(i+1)+"種車需要的數(shù)量:");
int q=input.nextInt();
a[i]=q*c[i].rent;
}
System.out.println("請輸入租車天數(shù):");
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
挺好的,,,很厲害的
2016-10-11
載人能載物的子類少了個 this.goods=goods;
2016-10-07
for(int i=0;i<c.length;i++){
System.out.println("請輸入您對第"+(i+1)+"種車需要的數(shù)量:");
int q=input.nextInt();
a[i]=q*c[i].rent;
}
哥哥? 這個? a[i]=q*c[i].rent;? 是什么意思啊
??
}
2016-05-14
你主函數(shù)里的問題是car是一個數(shù)組,需要a[i]=num*car[i].rent 你先試試看,行不行,再回復我
2016-05-14
為什么我會出現(xiàn)這些問題呢?能不能幫忙解答下?
我就是參考你的代碼進行編寫的,可是出現(xiàn)了這兩類問題,小白不知道怎么改正;