帮忙找错。感激不尽。
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 + "元。");
}
}
添加回答
举报
0/150
提交
取消