//父类
package didi;
public class Didi {
public String name;
public double rentm;
public int take;
public int ton;
public int rentsum;
public int getRentsum() {
return rentsum;
}
public void setRentsum(int rentsum) {
this.rentsum = rentsum;
}
public void Didi(String name,double rentm,int take){
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getRentm() {
return rentm;
}
public void setRentm(double rentm) {
this.rentm = rentm;
}
public int getTake() {
return take;
}
public void setTake(int take) {
this.take = take;
}
public int getTon() {
return ton;
}
public void setTon(int ton) {
this.ton = ton;
}
}
//货车类
package didi;
public class CurrentCar extends Didi {
public String name;
public double rentm;
public int ton;
public int rentsum;
public int getRentsum() {
return rentsum;
}
public void setRentsum(int rentsum) {
this.rentsum = rentsum;
}
public CurrentCar(String name,double rentm,int ton){
this.name=name;
this.rentm=rentm;
this.ton=ton;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getRentm() {
return rentm;
}
public void setRentm(double rentm) {
this.rentm = rentm;
}
public int getTon() {
return ton;
}
public void setTon(int ton) {
this.ton = ton;
}
}
//载人车类
package didi;
public class PassengerCar extends Didi {
public String name;
public double rentm;
public int take;
public int rentsum;
public int getRentsum() {
return rentsum;
}
public void setRentsum(int rentsum) {
this.rentsum = rentsum;
}
public PassengerCar(String name,double rentm,int take){
this.name=name;
this.rentm=rentm;
this.take=take;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getRentm() {
return rentm;
}
public void setRentm(double rentm) {
this.rentm = rentm;
}
public int getTake() {
return take;
}
public void setTake(int take) {
this.take = take;
}
}
//皮卡类
package didi;
public class PickUp extends Didi {
public String name;
public double rentm;
public int take;
public int ton;
public int rentsum;
public int getRentsum() {
return rentsum;
}
public void setRentsum(int rentsum) {
this.rentsum = rentsum;
}
public PickUp(String name, double rentm, int take,int ton) {
// TODO Auto-generated constructor stub
this.name=name;
this.rentm=rentm;
this.take=take;
this.ton=ton;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getRentm() {
return rentm;
}
public void setRentm(double rentm) {
this.rentm = rentm;
}
public int getTake() {
return take;
}
public void setTake(int take) {
this.take = take;
}
public int getTon() {
return ton;
}
public void setTon(int ton) {
this.ton = ton;
}
}
//main 函数类
package didi;
import java.util.Scanner;
public class Initial {
static int is=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Initial it=new Initial();
System.out.println("请问您是否需要租车?");
System.out.println("输入:1进入挑选 输入0:退出");
do{
Scanner sc=new Scanner(System.in);
int isof=sc.nextInt();
if(isof==0){
System.out.println("欢迎您下次光临!");
break;
}else if(isof==1){
System.out.println("请挑选你想选择的车辆!");
is=isof;
it.test();
break;
}else{
System.out.println("输入有误,请重新输入!");
continue;
}
}while(true);
}
public void test(){
Didi[] carsForRent={new PassengerCar("奥迪A4",500,4),new PassengerCar("马自达6",500,4),new PickUp("皮卡雪6",450,4,2),
new PassengerCar("金龙",800,20),new CurrentCar("松花江",400,4),new CurrentCar("依维柯",1000,20) };
int i=1;
if(is==1){
for(Didi currentCar:carsForRent){
if(currentCar instanceof PassengerCar){
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+"载人:"+currentCar.getTake()+"人");
i++;
}
else if(currentCar instanceof PickUp){
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+"载人:"+currentCar.getTake()+"人"+"载货:"+currentCar.getTon()+"吨");
i++;
}else{
System.out.println(""+i+"\t"+currentCar.getName()+"\t"+currentCar.getRentm()+"元/天"+"\t"+"载货:"+currentCar.getTon()+"吨");
i++;
}
}
}
double money=0;
do{
System.out.println("请输入你想要租车的序号(选购完成请输入0):");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n==0){
System.out.println("欢迎您下次光临!");
System.out.println("**租车总价格:"+money+"元");
System.out.println("**可载人的车有:");
int sumper=0;
for(int x=0;x<6;x++){
if(carsForRent[x].getRentsum()>0&&carsForRent[x].getTake()>0){
System.out.print(carsForRent[x].getName()+"x"+carsForRent[x].getRentsum());
sumper=sumper+carsForRent[x].getRentsum()*carsForRent[x].getTake();
}
}
if(sumper>0){
System.out.println("\t"+"可载人: "+sumper+"人");
}else{
System.out.println("无车可载人!");
}
int ton=0;
System.out.println("**可载货的车有:");
for(int x=0;x<6;x++){
if(carsForRent[x].getRentsum()>0&&carsForRent[x].getTon()>0){
System.out.print(carsForRent[x].getName()+"x"+carsForRent[x].getRentsum());
ton=ton+carsForRent[x].getRentsum()*carsForRent[x].getTon();
}
}
if(ton>0){
System.out.println("\t"+"可载货:"+ton+"吨");
}else{
System.out.println("无车可载货!");
}
break;
}else if(n==1||n==2||n==3||n==4||n==5||n==6)
{
switch (n){
case 1:
System.out.println("请输入你想要租车的数量:");
int sum=sc.nextInt();
carsForRent[n-1].setRentsum(sum);
double m1=500*sum;
System.out.println("请输入你想要租用的天数:");
money=money+m1*sc.nextInt();
break;
case 2:
System.out.println("请输入你想要租车的数量:");
sum=sc.nextInt();
carsForRent[n-1].setRentsum(sum);
m1=400*sum;
System.out.println("请输入你想要租用的天数:");
money=money+m1*sc.nextInt();break;
case 3:
System.out.println("请输入你想要租车的数量:");
sum=sc.nextInt();
carsForRent[n-1].setRentsum(sum);
m1=450*sum;
System.out.println("请输入你想要租用的天数:");
money=money+m1*sc.nextInt();break;
case 4:
System.out.println("请输入你想要租车的数量:");
sum=sc.nextInt();
carsForRent[n-1].setRentsum(sum);
m1=800*sum;
System.out.println("请输入你想要租用的天数:");
money=money+m1*sc.nextInt();break;
case 5:
System.out.println("请输入你想要租车的数量:");
sum=sc.nextInt();
carsForRent[n-1].setRentsum(sum);
m1=400*sum;
System.out.println("请输入你想要租用的天数:");
money=money+m1*sc.nextInt();break;
case 6:
System.out.println("请输入你想要租车的数量:");
sum=sc.nextInt();
carsForRent[n-1].setRentsum(sum);
m1=1000*sum;
System.out.println("请输入你想要租用的天数:");
money=money+m1*sc.nextInt();break;
}
}else{
System.out.println("输入有误,请重新输入!");
continue;
}
}while(true);
}
}
``
点击查看更多内容
51人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦