主函数感觉很乱有很多瑕疵,没用接口
package com.shiyan08;
import java.util.Scanner;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Zuche[] cars={new Car(1,"奥迪A4",500,4),new Car(2,"马自达6",400,4),new Pika(3,"皮卡雪6",450,4,2),
new Car(4,"金龙",800,20),new Truck(5,"松花江",400,4),new Car(6,"依维柯",900,20)};
System.out.println("***欢迎使用租车系统***");
System.out.println("您是否要租车(1是 0否):");
Scanner input=new Scanner(System.in);
int x=input.nextInt();
if(x==1){
System.out.println("序号\t汽车名称\t租金\t\t载物 载人\t");
for(Zuche k:cars){
System.out.println(k.getOrder()+"\t"+k.getName()+"\t"+k.getMoney()+"元/天"+"\t"+k.getCapacity()+"吨 "+k.getPcapacity()+"人");
}
System.out.print("请输入您要租汽车数量:");
int shuliang=input.nextInt();
double summoney=0;
double zairen=0;
double zaihuo=0;
String c="";
String z="";
for(int k=1;k<=shuliang;k++){
System.out.print("请输入第"+k+"辆车的序号:");
int i=input.nextInt();
if(i>0&&i<=cars.length){
summoney=summoney+cars[i-1].getMoney();
zairen=zairen+cars[i-1].getPcapacity();
zaihuo=zaihuo+cars[i-1].getCapacity();
if(cars[i-1].type.equals("truck")||cars[i-1].type.equals("pika")){
c=c+cars[i-1].getName()+" ";
}
if(cars[i-1].type.equals("car")||cars[i-1].type.equals("pika")){
z=z+cars[i-1].getName()+" ";
}
continue;
}
else{
System.out.println("您输入的序号有误");
}
break;
}
System.out.println("***您的账单如下***");
System.out.println("消费总额"+summoney);
System.out.println("**可载客的车有**");
System.out.println(z+"\t\t可载人数"+zairen+"人");
System.out.println("**可载货车有**");
System.out.println(c+"\t\t可载货"+zaihuo+"吨");
}
else{
System.out.println("欢迎您再次光临");
}
System.out.println("欢迎您再次光临");
}
}
父类
package com.shiyan08;
public class Zuche {
int order;
String name;
double money;
double pcapacity;
double capacity;
public String type;
public int getOrder() {
return order;
}
public String getName() {
return name;
}
public double getMoney() {
return money;
}
public double getPcapacity() {
return pcapacity;
}
public double getCapacity() {
return capacity;
}
}
载客车
package com.shiyan08;
public class Car extends Zuche{
int order;
String name;
double money;
double pcapacity;
public Car(int order,String name, double money,double pcapacity){
this.order=order;
this.name=name;
this.money=money;
this.pcapacity=pcapacity;
type="car";
}
public int getOrder() {
return order;
}
public String getName() {
return name;
}
public double getMoney() {
return money;
}
public double getPcapacity() {
return pcapacity;
}
}
载货车
package com.shiyan08;
public class Truck extends Zuche{
int order;
String name;
double money;
double capacity;
public Truck(int order,String name, double money,double capacity){
this.order=order;
this.name=name;
this.money=money;
this.capacity=capacity;
type="truck";
}
public int getOrder(){
return order;
}
public String getName(){
return name;
}
public double getMoney(){
return money;
}
public double getCapacity(){
return capacity;
}
}
皮卡
package com.shiyan08;
public class Pika extends Zuche{
int order;
String name;
double money;
double pcapacity;
double capacity;
public Pika(int order,String name, double money,double pcapacity,double capacity){
this.order=order;
this.name=name;
this.money=money;
this.pcapacity=pcapacity;
this.capacity=capacity;
type="pika";
}
public int getOrder() {
return order;
}
public String getName() {
return name;
}
public double getMoney() {
return money;
}
public double getPcapacity() {
return pcapacity;
}
public double getCapacity() {
return capacity;
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦