上代码
import java.util.Scanner;
class Car {
private String plate;
private String brand;
private int dayrent;
public Car(String plate, String brand, int dayrent) {
this.plate = plate;
this.brand = brand;
this.dayrent = dayrent;
}
public Car() {
}
public String getPlate() {
return plate;
}
public void setPlate(String plate) {
this.plate = plate;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getDayrent() {
return dayrent;
}
public void setDayrent(int dayrent) {
this.dayrent = dayrent;
}
}
class jiaoCar extends car.Car {
private String type;
private String arr[][];
public jiaoCar(String plate, String brand, int dayrent,String type) {
super(plate, brand, dayrent);
this.type=type;
}
public jiaoCar() {
}
public void cost(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入您要租赁的天数");
int days=sc.nextInt();
System.out.println("分配给您的汽车牌号是:"+this.getPlate());
if (days>7&&days<=30){
System.out.println("您需要支付的费用是:"+days*0.9*this.getDayrent()+"元");
}else if (days>30&&days<150){
System.out.println("您需要支付的费用是:"+days*0.8*this.getDayrent()+"元");
}else if (days>150){
System.out.println("您需要支付的费用是:"+days*0.7*this.getDayrent()+"元");
}else if (days>0&&days<=7){
System.out.println("您需要支付的费用是:"+days*this.getDayrent()+"元");
}else {
System.out.println("输入错误,系统崩溃鸟!");
return;
}
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
class keCar extends car.Car {
private int seat;
public keCar(String plate, String brand, int dayrent, int seat) {
super(plate, brand, dayrent);
this.seat = seat;
}
public void cost(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入您要租赁的天数");
int days=sc.nextInt();
System.out.println("分配给您的汽车牌号是:"+this.getPlate());
if (days>7&&days<=30){
System.out.println("您需要支付的费用是:"+days*0.8*this.getDayrent()+"元");
}else if (days>30&&days<150){
System.out.println("您需要支付的费用是:"+days*0.7*this.getDayrent()+"元");
}else if (days>150){
System.out.println("您需要支付的费用是:"+days*0.6*this.getDayrent()+"元");
}else if (days>0&&days<=3){
System.out.println("您需要支付的费用是:"+days*this.getDayrent()+"元");
}else if (days>3&&days<=7){
System.out.println("您需要支付的费用是:"+days*0.9*this.getDayrent()+"元");
}
else {
System.out.println("输入错误,系统崩溃鸟!");
return;
}
}
public int getSeat() {
return seat;
}
public void setSeat(int seat) {
this.seat = seat;
}
}
class Test {
public static void main(String[] args) {
car.jiaoCar[]a=new car.jiaoCar[4];
a[0]= new car.jiaoCar("京NY28588", "宝马", 800, "X6");
a[1]= new car.jiaoCar("京CNY3284", "宝马", 600, "550i");
a[2]= new car.jiaoCar("京NT37465", "别克", 300, "林荫大道");
a[3]= new car.jiaoCar("京NT96968", "别克", 600, "GL8");
car.keCar[]b=new car.keCar[4];
b[0]=new car.keCar("京6565655","金杯", 800,16);
b[1]=new car.keCar("京1324678","金龙", 800,16);
b[2]=new car.keCar("京4567521","金杯", 1500,34);
b[3]=new car.keCar("京4567848","金龙", 1500,34);
System.out.println("********************欢迎光临秋名山守望者汽车租赁公司*********************\n1、轿车 2、客车");
Scanner sc=new Scanner(System.in);
System.out.println("请选择你要租赁的汽车类型:");
int type=sc.nextInt();
if (type==1){
System.out.println("请选择您要租赁的汽车品牌:\n1、别克 2、宝马");
int brand=sc.nextInt();
if (brand==2){
System.out.println("请选择您要租赁的汽车型号:\n1、X6 2、550i");
int type1=sc.nextInt();
if (type1==1){
a[0].cost();
}
else if (type1==2){
a[1].cost();
}
else {
System.out.println("别瞎几把输");
}
}else if (brand==1){
System.out.println("请选择您要租赁的汽车型号:\n1、林荫大道 2、GL8");
int type1=sc.nextInt();
if (type1==1){
a[2].cost();
}
else if (type1==2){
a[3].cost();
}
else {
System.out.println("别瞎几把输");
}
}else {
System.out.println("别瞎几把输");
}
}else if (type==2){
System.out.println("请选择您要租赁的客车品牌:\n1、金杯 2、金龙");
int brand=sc.nextInt();
if (brand==1){
System.out.println("请选择您要租赁的客车座数:\n1、16座 2、34座");
int type1=sc.nextInt();
if (type1==1){
b[0].cost();
}
else if (type1==2){
b[2].cost();
}
else {
System.out.println("别瞎几把输");
}
}else if (brand==2){
System.out.println("请选择您要租赁的客车座数:\n1、16座 2、34座");
int type1=sc.nextInt();
if (type1==1){
b[1].cost();
}
else if (type1==2){
b[3].cost();
}
else {
System.out.println("别瞎几把输");
}
}else {
System.out.println("别瞎几把输");
}
}
}
}