重新来下
import java.util.Scanner; public class Car { public String name; public int money; public int people; public int things; public double thing; public Car(String name, int money, int people){ this.name=name; this.money=money; this.people=people; System.out.println( name + " " + money + "元/天" + " " + "载人:" + people + "人"); } public Car (String name, int money, int people, int things){ this.name=name; this.money=money; this.people=people; this.things=things; System.out.println( name + " " + money + "元/天" + " " + "载人:" + people + "人" + " " + "载货" + things + "吨" ); } public Car (String name, int money, double thing){ this.name=name; this.money=money; this.thing=thing; System.out.println( name + " " + money + "元/天" + " " + "载货:" + thing + "吨" ); } }
import java.util.Scanner;
public class InitialCar {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("欢迎使用嗒嗒租车系统");
System.out.println("你是否想要租车:1是 0否");
Scanner scanner =new Scanner(System.in);
int a=scanner.nextInt();
if(a==1){
System.out.println("你可租车的类型及其价目表:");
System.out.println("序号 " + "汽车名称 " + "租金 " + "容量 ");
Car car1=new Car("1. 奥迪A4", 500, 4);
Car car2=new Car("2. 马自达6", 400, 4);
Car car3=new Car("3. 皮卡", 450, 4,2);
Car car4=new Car("4. 金龙32", 800, 20);
Car car5=new Car("5. 松花江", 400, 4.0);
Car car6=new Car("6. 依擒科", 1000, 20.0);
System.out.println("请输入你要租的汽车数量");
Scanner sc =new Scanner(System.in);
int b=sc.nextInt();
int price=0;
int sum=0;
int weight=0;
String logo=" ";
String logo1=" ";
for(int i=1; i<=b; i++){
System.out.println("请输入第" + i + "辆车的序号");
Scanner scnn =new Scanner(System.in);
int c=scnn.nextInt();
switch (c){
case 1:
logo="奥迪A4";
price=500;
sum=4;
break;
case 2:
logo="马自达6";
price=400;
sum=4;
break;
case 3:
logo="皮卡";
price=450;
sum=4;
weight=2;
logo1="皮卡";
break;
case 4:
logo="金龙32";
price=800;
sum=20;
break;
case 5:
logo1="松花江";
price=400;
weight=4;
break;
case 6:
logo1="依擒科";
price=1000;
weight=20;
break;
}
logo += logo;
sum += sum ;
weight +=weight;
price +=price;
logo1 += logo1;
}
System.out.println("请输入租车天数");
Scanner day =new Scanner(System.in);
int days=day.nextInt();
System.out.println("你的账单:");
System.out.println("*****可载人的车有:");
System.out.println(logo + " 共载人:" + sum);
System.out.println("*****可载货的车有:" );
System.out.println(logo1 + " 共载货:" + weight);
System.out.println("租车总价格: " + price*days + "元");
}else{
System.out.println("你已退出!");
}
}
}
运行结果是乱的,不知道哪里出了问题
望高手指点