幫忙找錯。感激不盡。
package cn.com.didizuchexitong;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("歡迎使用答答租車系統:您是否要租車:1.是 0.否");
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
while(true){
if(choice!=0 && choice!=1){
System.out.println("您輸入有誤,請重新輸入。");
}else{
break;
}
choice = input.nextInt();
}
if(choice==1){
System.out.println("您可租車的類型及其價目表");
System.out.println("序號" + "\t" + "汽車名稱" + "\t\t" + "租金" + "\t\t" + "容量");
Vehicle[] v = {new Car("奧迪A4",500,4),new Car("馬自達6",400,4),new PickUp("皮卡雪6",450,4,2),
new Car("金龍",800,20),new Truck("松花江",400,4),new Truck("依維柯",1000,20)};
for (int i = 0 ; i<v.length; i++) {
System.out.print(i+1);
v[i].dayIn();
}
}else{
System.exit(0);
}
System.out.println("請輸入您要租車的數量:");
int num = input.nextInt();
Vehicle[] v1 = new Vehicle[num];
for(int i = 0 ; i<num; i++){
System.out.println("請輸入第" + (i + 1) + "輛車的序號:");
int number = input.nextInt();
v1[i] = v1[number-1];
}
System.out.println("請輸入租車天數:");
int day = input.nextInt();
System.out.println("您的賬單:");
int sum = 0;
int zairenshu = 0;
int zaihuoshu = 0;
for(int j = 0 ; j<v1.length; j++){
if(v1[j] instanceof Car){
Car c = (Car)v1[j];
sum = sum + c.getMoney()*day;
zairenshu = zairenshu + c.getCarload();
}if(v1[j] instanceof Truck){
Truck t = (Truck)v1[j];
sum = sum + t.getMoney()*day;
zaihuoshu = zaihuoshu + t.getFreight();
}if(v1[j] instanceof PickUp){
PickUp pu = (PickUp)v1[j];
sum = sum + pu.getMoney()*day;
zairenshu = zairenshu + pu.getCarload();
zaihuoshu = zaihuoshu + pu.getFreight();
}
}
System.out.println("可載人的車:");
for(int k = 0 ; k<v1.length; k++){
if(v1[k] instanceof Car || v1[k] instanceof PickUp){
System.out.println(v1[k].getName() +"\t");
}
}
System.out.println("總載人數:" + zairenshu + "人");
System.out.println("可載貨的車:");
for(int n = 0 ; n<v1.length; n++){
if(v1[n] instanceof Truck || v1[n] instanceof PickUp){
System.out.println(v1[n].getName() +"\t");
}
}
System.out.println("總載貨數:" + zaihuoshu + "噸");
System.out.println("總租金為:" + sum + "元。");
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("歡迎使用答答租車系統:您是否要租車:1.是 0.否");
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
while(true){
if(choice!=0 && choice!=1){
System.out.println("您輸入有誤,請重新輸入。");
}else{
break;
}
choice = input.nextInt();
}
if(choice==1){
System.out.println("您可租車的類型及其價目表");
System.out.println("序號" + "\t" + "汽車名稱" + "\t\t" + "租金" + "\t\t" + "容量");
Vehicle[] v = {new Car("奧迪A4",500,4),new Car("馬自達6",400,4),new PickUp("皮卡雪6",450,4,2),
new Car("金龍",800,20),new Truck("松花江",400,4),new Truck("依維柯",1000,20)};
for (int i = 0 ; i<v.length; i++) {
System.out.print(i+1);
v[i].dayIn();
}
}else{
System.exit(0);
}
System.out.println("請輸入您要租車的數量:");
int num = input.nextInt();
Vehicle[] v1 = new Vehicle[num];
for(int i = 0 ; i<num; i++){
System.out.println("請輸入第" + (i + 1) + "輛車的序號:");
int number = input.nextInt();
v1[i] = v1[number-1];
}
System.out.println("請輸入租車天數:");
int day = input.nextInt();
System.out.println("您的賬單:");
int sum = 0;
int zairenshu = 0;
int zaihuoshu = 0;
for(int j = 0 ; j<v1.length; j++){
if(v1[j] instanceof Car){
Car c = (Car)v1[j];
sum = sum + c.getMoney()*day;
zairenshu = zairenshu + c.getCarload();
}if(v1[j] instanceof Truck){
Truck t = (Truck)v1[j];
sum = sum + t.getMoney()*day;
zaihuoshu = zaihuoshu + t.getFreight();
}if(v1[j] instanceof PickUp){
PickUp pu = (PickUp)v1[j];
sum = sum + pu.getMoney()*day;
zairenshu = zairenshu + pu.getCarload();
zaihuoshu = zaihuoshu + pu.getFreight();
}
}
System.out.println("可載人的車:");
for(int k = 0 ; k<v1.length; k++){
if(v1[k] instanceof Car || v1[k] instanceof PickUp){
System.out.println(v1[k].getName() +"\t");
}
}
System.out.println("總載人數:" + zairenshu + "人");
System.out.println("可載貨的車:");
for(int n = 0 ; n<v1.length; n++){
if(v1[n] instanceof Truck || v1[n] instanceof PickUp){
System.out.println(v1[n].getName() +"\t");
}
}
System.out.println("總載貨數:" + zaihuoshu + "噸");
System.out.println("總租金為:" + sum + "元。");
}
}
這個才是需要找錯的。。。。
java2016817
2016-08-20 22:16:37