package AAA;
public class Bus extends Car {
public Bus(int number, String name, double price, String load) {
super(number, name, price, load);
// TODO Auto-generated constructor stub
}
}
public class Car {
public int number;
public String name;
public double price;
public String load;
public Car(int number,String name,double price,String load){
this.number=number;
this.name=name;
this.price=price;
this.load=load;
}
@Override
public String toString() {
return number+" "+name+" "+price+" "+load+" ";
}
}
import java.util.Arrays;
public class CarInfo {
public String[] title={"序号","车型","租金/天","承载"};
public Car[]car={new PrivateCar(1,"私家车1",100,"载人5人"),
new PrivateCar(2,"私家车2",200,"载客5人"),
new PickUp(3,"皮卡1",300,"载客两人,载货1吨"),
new Bus(4,"客车1",400,"载客30"),
new Bus(5,"客车2",500,"载客40") ,
new Truck(6,"卡车1",600,"载货50"),
new Truck(7,"卡车2",700,"载货60")};
public void CarInfo_Print(){
System.out.println("可供你选择的车辆信息:");
System.out.println(title[0]+" "+title[1]+" "+title[2]+" "+title[3]);
System.out.println();
for(int i=0;i<car.length;i++){
System.out.println(car[i]);
}
}
@Override
public String toString() {
return "CarInfo [car=" + Arrays.toString(car) + "]";
}
}
public class Cilent {
public int rentnumber;
public int []rentdays=new int[10];
public int []rentchoose=new int[10];
public double []price=new double[10];
public void rentcar(){
System.out.println("请输入你要租的车辆数");
Scanner input=new Scanner(System.in);
rentnumber=input.nextInt();
for(int i=0;i<rentnumber;i++){
System.out.println("请输入你要租的第"+(i+1)+"辆车的编号");
Scanner input2=new Scanner(System.in);
rentchoose[i]=input2.nextInt();
System.out.println("请输入你要租赁的天数");
Scanner input3=new Scanner(System.in);
rentdays[i]=input3.nextInt();
}
}
}
public class PickUp extends Car {
public PickUp(int number, String name, double price, String load) {
super(number, name, price, load);
// TODO Auto-generated constructor stub
}
}
public class PrivateCar extends Car {
public PrivateCar(int number, String name, double price, String load) {
super(number, name, price, load);
// TODO Auto-generated constructor stub
}
}
public class Truck extends Car {
public Truck(int number, String name, double price, String load) {
super(number, name, price, load);
// TODO Auto-generated constructor stub
}
}
import java.util.Scanner;
public class Welcome {
public static String name;
public int number;
public int hello(){
System.out.println("请问您是否要租车?");
System.out.println("若要租车请输入1,若不要请输入2");
Scanner input=new Scanner(System.in);
number=input.nextInt();
if(number==1){
System.out.println("您好,欢迎来到租车系统!请输入您的名字,我们将会为您创建订单");
Scanner input2=new Scanner(System.in);
name=input2.next();
}
return number;
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Welcome man =new Welcome();
if(man.hello()==1){
CarInfo a=new CarInfo();
a.CarInfo_Print();
Cilent aCilent=new Cilent();
aCilent.rentcar();
System.out.println(Welcome.name+"您好,"+"你的订单如下请确认");
System.out.println();
for(int i=0;i<aCilent.rentnumber;i++){
System.out.println("您的第"+(i+1)+"辆车为:");
System.out.println(a.car[aCilent.rentchoose[i]-1]);//为什么这里要-1???
System.out.println("您租赁的天数为:"+aCilent.rentdays[i]);
System.out.println();
System.out.println();
}
double Priceend=0;
for(int i=0;i<aCilent.rentnumber;i++){
aCilent.price[i]=(a.car[aCilent.rentchoose[i]-1].price);
Priceend+=(aCilent.price[i])*(aCilent.rentdays[i]);
}
System.out.println(Welcome.name+"您好,"+"租车总价如下请确认");
System.out.println(Priceend+"元");
System.out.println("谢谢使用租车系统");
}else{
System.out.println("谢谢使用租车系统");
}
}
}
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123