package java2.chapter61;
import java.util.Scanner;
public class Test {
static boolean step1 = true;
static boolean step2 = true;
static boolean yesOrNo = false;
static int number = 0;
static Auto au = new Auto();
static CarAudi cA = new CarAudi("奥迪A4","小轿车",500,4);
static Auto cB = new CarBWM("宝马X1","小轿车",600,4);
static Truck gt = new Truck("依维柯01","货车",1000,2,10);
static Auto gp = new Pick_up("皮卡雪6","货车",450,4,1);
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:1是0否");
input1Method();//调用方法1
if(yesOrNo){
System.out.println("\n您可租车的类型及价目表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1. 奥迪A4 500元/天 载人:4人");
System.out.println("2. 宝马X1 550元/天 载人:4人");
System.out.println("3. 依维柯01 1000元/天 载货:20吨");
System.out.println("4. 皮卡雪6 450元/天 载人:4人 载货:2吨");
System.out.println("\n请输入您要租车的序号:");
Test.input2Method();//调用方法2,可以用本类名.方法 调用
System.out.println("\n请输入您要租该车多少天");
input3Method();
}
}
static public void input1Method() { //是否租车
while (step1) {
String input1 = sc.next();
switch (input1) {
case "1":
System.out.println("租车");
step1 = false;
yesOrNo = true;
break;
case "0":
System.out.println("不租车");
step1 = false;
yesOrNo = false;
break;
default:
System.out.println("输入无效,请重新输入");
step1 = true;
yesOrNo = false;
break;
}
}
}
static public void input2Method() { //选择车型
while (step2) {
String input2 = sc.next();
switch (input2) {
case "1":
cA.printPrice();
number = cA.getPrice();
step2 = false;
break;
case "2":
cB.printPrice();
number = cB.getPrice();
step2 = false;
break;
case "3":
gt.printPrice();
number = gt.getPrice();
step2 = false;
break;
case "4":
gp.printPrice();
number = gp.getPrice();
step2 = false;
break;
default:
System.out.println("输入有误,请重新输入");
step2 = true;
break;
}
}
}
static public void input3Method(){
int input3 = sc.nextInt();
number = input3*number;
System.out.println("总价钱是:"+number+"元人民币");
}
}
package java2.chapter61;
/*
*/
public class Auto {
private String type = "";//型号
private String name = "汽车";//类型
private int price = 10; //价格
private int num = 0;//载客人数
private int much = 0;//多少天
public String getTypt(){
return type;
}
public void setType(String type){
this.type = type;
}
public int getMuch(){
return much;
}
public void setMuch(int much){
this.much = much;
}
public int getNum(){
return num;
}
public void setNum(int num){
this.num = num;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public void printPrice(){
System.out.println("型号:"+type);
System.out.println("类型:"+name);
System.out.println("租金:"+price+"元/天");
System.out.println("载客:"+num+"人");
}
}
package java2.chapter61;
/*
*/
public interface Goods_van {
void goodsVan();
}
package java2.chapter61;
/*
package java2.chapter61;
/*
package java2.chapter61;
/*
package java2.chapter61;
/*
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123