永远不会输如果不计成败
2019-09-19 16:44
public class Car {
private String name;
private double price;
private int guest;
double goods;
public Car(String name,double price,int guest,double goods) {
this.name=name;
this.price=price;
this.guest=guest;
this.goods=goods;
}
public String getname() {
return name;
}
public double getprice() {
return price;
}
public int getguest() {
return guest;
}
public double getgoods() {
return goods;
}
}
import java.util.Scanner;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double price=0;
double guest=0;
double goods=0;
int d=0;
Car[] CarList= {
new Car("奥迪",2000,5,0),
new Car("宝马",2500,5,0),
new Car("五菱宏光",800,12,0),
new Car("法拉利",8000,2,0),
new Car("小卡车",2000,0,5),
new Car("大卡车",5000,0,15),
new Car("皮卡",1000,2,2),
};
System.out.println("欢迎来到答答租车!");
System.out.println("租车请输入1,退出请输入任意键");
String scanf=sc.next().toString();
if(scanf.equals("1")) {
System.out.println("以下是车辆列表:");
for(int i=0;i<CarList.length;i++) {
System.out.println("序列号:"+i+"\t"+CarList[i].getname()+"\t"+CarList[i].getprice()+"\t"+CarList[i].getguest()+"\t"+CarList[i].getgoods());
}
System.out.println("请输入需要的车辆的序列号并使用逗号隔开:");
String str=sc.next().toString();
String[] arr=str.split(",");
if(arr.length>0){
for(int i=0;i<arr.length;i++) {
String b=arr[i];
int c=0;
if(b!=null || b.length() != 0) {
for(int j=0;j<b.length();j++) {
if(b.charAt(j)<'0'||b.charAt(j)>'9')
{
c++;
break;
}
}
if(c==0) {
int a=Integer.parseInt(arr[i]);
if(a<CarList.length) {
price+=CarList[Integer.parseInt(arr[i])].getprice();
guest+=CarList[Integer.parseInt(arr[i])].getguest();
goods+=CarList[Integer.parseInt(arr[i])].getgoods();
}else {
d++;
break;
}
}
}else {
d++;
}
}
if(d==0) {
System.out.println("以下是您租车的列表:");
for(int i=0;i<arr.length;i++) {
int b=Integer.parseInt(arr[i]);
System.out.println("序列号:"+i+"\t"+CarList[i].getname()+"\t"+CarList[i].getprice()+"\t"+CarList[i].getguest()+"\t"+CarList[i].getgoods());
}
System.out.println("您的订单总价为:"+price+"\t"+"总载客量为:"+guest+"\t"+"总载货量为:"+goods);
System.out.println("欢迎再次光临!");
}else {
System.out.println("输入的参数有误!");
}
}else {
System.out.println("输入的参数有误!");
}
}else {
System.out.println("欢迎再次光临!");
}
}
}
有什么毛病吗?
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题