哥一无事处
2015-07-20 09:25
package P6; public class Car { String CarName; int CarNo; int CarMoney; int CarRongliang; public Car(String newName, int NewNo, int newMoney, int newRongliang) { CarName = newName; CarNo = NewNo; CarMoney = newMoney; CarRongliang = newRongliang; } public Car() { // TODO Auto-generated constructor stub } @Override public String toString() { return "Car [汽车品牌=" + CarName + ", 汽车编号=" + CarNo + ", 一天费用=" + CarMoney + ", 汽车容量=" + CarRongliang + "]"; } }
package P6;
import java.util.ArrayList;
import java.util.Scanner;
public class Manager {
public static void main(String[] args) {
Car l=new Car();
ArrayList<Car> ar = new ArrayList<Car>();
Car c1 = new Car("宝马", 1, 5000, 4);
Car c2=new Car("奔驰",2,4500,4);
Car c3=new Car("荣威",3,3000,6);
Car c4=new Car("大巴",4,4500,20);
Car c5=new Car("皮卡",5,3500,3);
ar.add(c1);
ar.add(c2);
ar.add(c3);
ar.add(c4);
ar.add(c5);
int flag=0;
System.out.println("欢迎使用哒哒租车系统,请问您是否租车?");
System.out.println("租车请选1,退出请选6");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if(a==1){
System.out.println(c1);
System.out.println(c2);
System.out.println(c3);
System.out.println(c4);
System.out.println(c5);
System.out.println("请选择车辆编号,退出请选6");
int c=s.nextInt();
for(int i=0;i<3;i++){
if(c<7&&c>0){
switch(c){
case 1:
System.out.println(c1);
break;
case 2:
System.out.println(c2);
break;
case 3:
System.out.println(c3);
break;
case 4:
System.out.println(c4);
break;
case 5:
System.out.println(c5);
break;
case 6:
i=6;
flag=1;
System.out.println("谢谢使用");
break;
}
for(int j = 0; j < ar.size(); j++) {
if(j == (c - 1)) { //c-1找到车对象的下标
l = ar.get(j);//l为创建的车的对象 找到选择的车的对象 取出
}
}
while(flag==0){
System.out.println("请输入要租用几天");
int d=s.nextInt();
for(int i1=0;i1<3;i1++){
while(d>30||d<0){
System.out.println("租借天数大于0且小于30");
System.out.println("请重新输入");
d=s.nextInt();
}
}
System.out.println("请确认租用天数");
int f=s.nextInt();
if(d==f){
i=6;
flag=1;
System.out.print("您应付的金额为:");
System.out.println(rmb(d,l));
int d8=rmb(d,l);
System.out.println("请付钱");
int d7=s.nextInt();
for(int k=0;k<3;k++){
if(d7==d8){
System.out.println("谢谢使用。");
k=5;
}else{
System.out.println("您输入的金额不正确,已退回");
if(k<2){
System.out.println("请重新输入");
d7=s.nextInt();
}
else{
System.out.println("您金额连续输入错误三次,已退出本系统,谢谢使用");
}
}
}
}
else
System.out.println("两次输入不一致");
}
}
else
{
if(i<2){
System.out.println("查找不到");
System.out.println("请重新输入");
c=s.nextInt();
}else{
i=5;
flag=1;
System.out.println("输入错误超过三次,退出本系统");
System.out.println("感谢使用");
}
}
}
}
else{
System.out.println("谢谢使用");
}
}
public static int rmb(int a,Car c){//Car c 为车的对象
int rmb=a*c.CarMoney;//c.CarMoney 调用车对象的Money
return rmb;
}
}
哈哈哈哈
Java入门第二季 升级版
530559 学习 · 6091 问题
相似问题