package rent1;
public class Bus extends MotoVehicle {
private int seatCount;
//构造方法
public Bus(){
}
public Bus(String no, String brand, int seatCount){
super(no,brand);
this.seatCount = seatCount;
}
//获取座位数
public int getSeat(){
return seatCount;
}
//计算租金
public int calRent(int days){
int rent = 0;
if(seatCount <= 16){
rent = 800 * days;
}else{
rent = 1500 * days;
}
return rent;
}
}
private int seatCount;
//构造方法
public Bus(){
}
public Bus(String no, String brand, int seatCount){
super(no,brand);
this.seatCount = seatCount;
}
//获取座位数
public int getSeat(){
return seatCount;
}
//计算租金
public int calRent(int days){
int rent = 0;
if(seatCount <= 16){
rent = 800 * days;
}else{
rent = 1500 * days;
}
return rent;
}
}
----------------------------------------------------------------------------------------------------------------------------------
package rent1;
import com.rent.MotoVehicle;
public class Car extends MotoVehicle {
//定义类属性
private String type; //轿车型号
//构造方法
public Car(){
}
public Car(String no,String brand,String type){
super(no,brand);
this. type=(type);
}
//设置轿车型号
public void setType(String type) {
this.type = type;
}
//返回轿车型号
public String getType() {
return type;
}
//实现父类抽象方法,计算租金
public int calRent(int days){
int rent = 0;
if("玛莎拉蒂".equals(getBrand())){
rent = days*500;
}else if("广汽".equals(getBrand())){
if(type.equals("GL8")){
rent = days*600;
}else{
rent = days*300;
}
}
return rent;
}
}
//定义类属性
private String type; //轿车型号
//构造方法
public Car(){
}
public Car(String no,String brand,String type){
super(no,brand);
this. type=(type);
}
//设置轿车型号
public void setType(String type) {
this.type = type;
}
//返回轿车型号
public String getType() {
return type;
}
//实现父类抽象方法,计算租金
public int calRent(int days){
int rent = 0;
if("玛莎拉蒂".equals(getBrand())){
rent = days*500;
}else if("广汽".equals(getBrand())){
if(type.equals("GL8")){
rent = days*600;
}else{
rent = days*300;
}
}
return rent;
}
}
----------------------------------------------------------------------------------------------------------------------------------
package rent1;
/**
* MotoVehicle:机动车抽象类
* @author 水瓶
*
*/
public abstract class MotoVehicle {
private String no; //车牌号
private String brand; //品牌
//构造方法
public MotoVehicle(){
}
public MotoVehicle(String no, String brand){
this.no = no;
this.brand = brand;
}
//返回机动车辆的牌照
public String getNo(){
return no;
}
//返回机动车辆的品牌
public String getBrand(){
return brand;
}
//计算租金的抽象方法
public abstract int calRent(int days);
}
/**
* MotoVehicle:机动车抽象类
* @author 水瓶
*
*/
public abstract class MotoVehicle {
private String no; //车牌号
private String brand; //品牌
//构造方法
public MotoVehicle(){
}
public MotoVehicle(String no, String brand){
this.no = no;
this.brand = brand;
}
//返回机动车辆的牌照
public String getNo(){
return no;
}
//返回机动车辆的品牌
public String getBrand(){
return brand;
}
//计算租金的抽象方法
public abstract int calRent(int days);
}
----------------------------------------------------------------------------------------------------------------------------------
package rent1;
import java.util.Scanner;
public class Test {
/**
* @author 水瓶
* @param args
*/
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int days = 0; //租赁的天数
int motoType ; //汽车大类型
String brand ; //汽车品牌
int seat; //座位数
String no = null; //牌照
MotoVehicle[] moto = new MotoVehicle[10];
System.out.println("欢迎来到汽车租赁公司!");
System.out.println("请输入要租赁的天数:");
days = input.nextInt();
System.out.println("请输入要租赁的汽车类型(1.轿车 2.客车):");
motoType = input.nextInt();
int random = (int)(Math.random()*(99999-10000)+10000);
switch(motoType){
case 1:
no = "蒙D" + random; //车辆牌照
System.out.println("请输入要租赁的汽车品牌(1.宝马 2.丰田):");
if(input.nextInt() == 1){
brand = "玛莎拉蒂";
}else{
brand = "广汽";
break;
}
case 2:
no = "蒙D" + random;
System.out.println("请输入要租赁的汽车品牌(1.黄海 2.金龙):");
//根据选择得到汽车品牌
if(input.nextInt() ==1){
brand = "黄海";
}else{
brand = "金龙";
}
System.out.println("请输入客车的座位数:");
seat = input.nextInt(); //汽车座位数
for(int i = 0 ; i < moto.length ;i ++){
if(moto[i] == null){
moto[i] = new Bus(no,brand,seat); //实例化一个汽车对象
break;
}
}
}
System.out.println("租赁天数:"+days+"天\n租赁资金是:"+random+"元\n汽车牌照:"+no);
}
* @author 水瓶
* @param args
*/
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int days = 0; //租赁的天数
int motoType ; //汽车大类型
String brand ; //汽车品牌
int seat; //座位数
String no = null; //牌照
MotoVehicle[] moto = new MotoVehicle[10];
System.out.println("欢迎来到汽车租赁公司!");
System.out.println("请输入要租赁的天数:");
days = input.nextInt();
System.out.println("请输入要租赁的汽车类型(1.轿车 2.客车):");
motoType = input.nextInt();
int random = (int)(Math.random()*(99999-10000)+10000);
switch(motoType){
case 1:
no = "蒙D" + random; //车辆牌照
System.out.println("请输入要租赁的汽车品牌(1.宝马 2.丰田):");
if(input.nextInt() == 1){
brand = "玛莎拉蒂";
}else{
brand = "广汽";
break;
}
case 2:
no = "蒙D" + random;
System.out.println("请输入要租赁的汽车品牌(1.黄海 2.金龙):");
//根据选择得到汽车品牌
if(input.nextInt() ==1){
brand = "黄海";
}else{
brand = "金龙";
}
System.out.println("请输入客车的座位数:");
seat = input.nextInt(); //汽车座位数
for(int i = 0 ; i < moto.length ;i ++){
if(moto[i] == null){
moto[i] = new Bus(no,brand,seat); //实例化一个汽车对象
break;
}
}
}
System.out.println("租赁天数:"+days+"天\n租赁资金是:"+random+"元\n汽车牌照:"+no);
}
}