程序大体分三块:
车辆类、显示类、租赁类
租赁类(具体运行):
`package com.carrent;
import java.util.Scanner;
public class Rent {
private static Scanner input;
private static int s,m,n ;
public static void main(String[] args) {
// TODO Auto-generated method stub
input=new Scanner(System.in);
System.out.println("是否希望开始租赁选择:是则输入1,否则输入2:");
if(input.nextInt()==1){
Carlist aCarList =new Carlist();
aCarList.sort();//库存展示
//类型选择
System.out.println("请选择想要租赁的车型编号:");
s = input.nextInt();
switch (s) {
case 1:
System.out.println("您选择的是"+aCarList.carlists[0].getBrand()+"汽车");
break;
case 2:
System.out.println("您选择的是"+aCarList.carlists[1].getBrand()+"重型货车");
break;
case 3:
System.out.println("您选择的是"+aCarList.carlists[2].getBrand()+"轻型货车");
break;
case 4:
System.out.println("您选择的是"+aCarList.carlists[3].getBrand()+"皮卡车");
break;
case 5:
System.out.println("您选择的是"+aCarList.carlists[4].getBrand()+"轿车");
break;
default:
System.out.println("类型名不存在,出错。");
break;
}
System.out.println("请输入租赁数量:");
m = input.nextInt();
System.out.println("请输入租赁时间:(单位/天)");
n = input.nextInt();
System.out.println("是否确定租赁,是则输入1,否则0.");
if (input.nextInt()==1) {
YourRent[] your = {
new YourRent(aCarList,m,n,s-1)
};
System.out.println("您的租赁列表如下:");
System.out.println("\t型号"+"\t品牌"+"\t载货重"+"\t载客量"+"\t日租赁价格"+"\t待租数量"+"\t租赁时间");
for (YourRent x:your) {
x.show();
}
}else {
}
System.out.println("是否结束租赁系统:1表示继续租赁,0表示退出.");
System.exit(input.nextInt());
}
}
}
车辆父类:
package com.carrent;
public class Car {
private String name="车";
private String brand;
private int burden ;
private int busload;
private int price;
private int num;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getBurden() {
return burden;
}
public void setBurden(int burden) {
this.burden = burden;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
}
子类,轿车、公交、小货车、大卡车、皮卡:
轿车子类:
package com.carrent;
public class Sedan extends Car {
public Sedan(String aBrand, int aburden, int abusload, int aprice,int anum) {
this.setName("轿车");
this.setBrand(aBrand);
this.setBurden(aburden);
this.setBusload(abusload);
this.setPrice(aprice);
this.setNum(anum);
}
}
公交子类:
package com.carrent;
public class Bus extends Car {
public Bus(String aBrand, int aburden, int abusload, int aprice,int anum) {
this.setName("公交");
this.setBrand(aBrand);
this.setBurden(aburden);
this.setBusload(abusload);
this.setPrice(aprice);
this.setNum(anum);
}
}
小货车:
package com.carrent;
public class LightTruck extends Car {
public LightTruck(String aBrand, int aburden, int abusload, int aprice,int anum) {
this.setName("轻型货车");
this.setBrand(aBrand);
this.setBurden(aburden);
this.setBusload(abusload);
this.setPrice(aprice);
this.setNum(anum);
}
}
大卡车:
package com.carrent;
public class HeavyTruck extends Car {
public HeavyTruck(String aBrand, int aburden, int abusload, int aprice,int anum) {
this.setName("重型货车");
this.setBrand(aBrand);
this.setBurden(aburden);
this.setBusload(abusload);
this.setPrice(aprice);
this.setNum(anum);
}
}
皮卡子类:
package com.carrent;
public class PickUp extends Car{
public PickUp(String aBrand, int aburden, int abusload, int aprice,int anum) {
this.setName("皮卡");
this.setBrand(aBrand);
this.setBurden(aburden);
this.setBusload(abusload);
this.setPrice(aprice);
this.setNum(anum);
}
}
列表显示类,库存列表,客户租赁表:
库存显示类:
package com.carrent;
public class Carlist {
Car[] carlists ={
new Bus("YUTONG",0,24,3500,12),new HeavyTruck("解放",20,2,5000,5),
new LightTruck("长安之星", 4, 2, 2000,6),
new PickUp("Ford福特", 3, 5, 3000,7),new Sedan("大众", 0, 5,2000,2)
};
public void sort(){
System.out.println("待租车辆列表:");
System.out.println("\t型号"+"\t品牌"+"\t载货重"+"\t载客量"+"\t日租赁价格"+"\t待租数量");
int i = 1;
for(Car x:carlists)
{
System.out.print(i+".\t"+x.getName());
System.out.print("\t"+x.getBrand());
System.out.print("\t"+x.getBurden()+"吨");
System.out.print("\t"+x.getBusload()+"人");
System.out.print("\t"+x.getPrice()+"$");
System.out.println("\t"+x.getNum()+"辆");
i++;
}
}
}
客户租赁类:
package com.carrent;
/*
- 个人租赁列表
*/
public class YourRent {
String name;
String brand;
int burden ;
int busload;
int price;
int rentNum;
int rentDay;
public YourRent(Carlist a,int x,int y,int z) {
// TODO Auto-generated constructor stub
//aCarList.carlists[0].brand;
name = a.carlists[z].getName();
brand = a.carlists[z].getBrand();
burden = a.carlists[z].getBurden();
busload = a.carlists[z].getBusload();
price = a.carlists[z].getPrice();
rentNum = x;
rentDay = y;
}
public void show() {
System.out.print("\t"+this.name);
System.out.print("\t"+this.brand);
System.out.print("\t"+this.burden+"吨");
System.out.print("\t"+this.busload+"人");
System.out.print("\t"+this.price+"$");
System.out.print("\t"+this.rentNum+"辆");
System.out.println("\t"+this.rentDay+"天");
}
}
`
共同学习,写下你的评论
评论加载中...
作者其他优质文章