\车的抽象类
public abstract class Vehicle {
private String car;
private int price;
public String getcar(){
return car;
}
public void setcar(String car){
this.car=car;
}
public int getprice(){
return price;
}
public void setprice(int price){
this.price=price;
}
} package com.DADA;
\客车接口
public interface Izaike {
public void setzaikenum(int zaikenum);
public int getzaikenum();
} package com.DADA;
\货车接口
public interface Izaizong {
public void setzaizongnum(int zaizongnum);
public int getzaizongnum();
}
package com.DADA;
\皮卡接口 继承了货车和客车的接口
public interface Ipk extends Izaike,Izaizong{
package com.DADA;
\客车类
public class keche extends Vehicle implements Izaike {
private int zaikenum;
public keche(String car,int price,int zaikenum){
this.setcar(car);
this.setprice(price);
this.setzaikenum(zaikenum);
}
@Override
public void setzaikenum(int zaikenum) {
// TODO Auto-generated method stub
this.zaikenum=zaikenum;
}
@Override
public int getzaikenum() {
// TODO Auto-generated method stub
return zaikenum;
}
}
package com.DADA;
\货车类
public class huoche extends Vehicle implements Izaizong {
private int zaizongnum;
public huoche(String car,int price,int zaizongnum){
this.setcar(car);
this.setprice(price);
this.setzaizongnum(zaizongnum);
}
@Override
public void setzaizongnum(int zaizongnum) {
// TODO Auto-generated method stub
this.zaizongnum=zaizongnum;
}
@Override
public int getzaizongnum() {
// TODO Auto-generated method stub
return zaizongnum;
}
}
package com.DADA;
\皮卡类
public class PiKa extends Vehicle implements Ipk {
private int zaikenum;
private int zaizongnum;
public PiKa(String car,int price,int zaikenum,int zaizongnum){
this.setcar(car);
this.setprice(price);
this.setzaikenum(zaikenum);
this.setzaizongnum(zaizongnum);
}
@Override
public void setzaikenum(int zaikenum) {
// TODO Auto-generated method stub
this.zaikenum=zaikenum;
}
@Override
public int getzaikenum() {
// TODO Auto-generated method stub
return zaikenum;
}
@Override
public void setzaizongnum(int zaizongnum) {
// TODO Auto-generated method stub
this.zaizongnum=zaizongnum;
}
@Override
public int getzaizongnum() {
// TODO Auto-generated method stub
return zaizongnum;
}
}
package com.DADA;
import java.util.*;
\答答租车系统
public class DADASystem {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] sumzaike=new int[5];
double[] sumzaizong=new double[5];
double[] sumprice=new double[5];
String[] name=new String[5];
int[] n=new int[5];
int[] j=new int[5];
keche kcar1=new keche("小型客车",100,8);
keche kcar2=new keche("大型客车",300,20);
huoche hcar1=new huoche("小型货车",200,5);
huoche hcar2=new huoche("大型货车",500,20);
PiKa car=new PiKa("皮卡",300,4,2);
for(;;){
System.out.println("欢迎使用答答租车系统");
System.out.print("你是否要租车:1是 0否:");
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
if(choice==0){
System.out.println("欢迎下次使用!");
break;
}else if(choice==1){
System.out.println("你可租车的类型及其价格表:");
System.out.println("序号\t汽车种类\t价格(元/天)\t功能");
System.out.println("--------------------------------------");
System.out.println(1+"\t"+kcar1.getcar()+"\t"+" "+kcar1.getprice()+"\t\t"+"载人:"+kcar1.getzaikenum()+"人");
System.out.println(2+"\t"+kcar2.getcar()+"\t"+" "+kcar2.getprice()+"\t\t"+"载人:"+kcar2.getzaikenum()+"人");
System.out.println(3+"\t"+hcar1.getcar()+"\t"+" "+hcar1.getprice()+"\t\t"+"载重:"+hcar1.getzaizongnum()+"T");
System.out.println(4+"\t"+hcar2.getcar()+"\t"+" "+hcar2.getprice()+"\t\t"+"载重:"+hcar2.getzaizongnum()+"T");
System.out.println(5+"\t"+car.getcar()+"\t"+" "+car.getprice()+"\t\t"+"载人:"+car.getzaikenum()+"人"+""+"载重:"+car.getzaizongnum()+"T");
System.out.println("--------------------------------------");
System.out.println("接下来您将进行租车服务,如果租车完成请输入数字0结束!");
int i;
for(i=0;;i++){
System.out.print("请输入一种所需车的序号:");
int m = in.nextInt();
if(m==0){
System.out.println();
System.out.println("谢谢使用。");
in.close();
break;
}else if(m<0m>5){
System.out.println("指令有误!请输入正确的指令。");
i--;
continue;
}
switch(m){
case 1: name[i]=kcar1.getcar();
System.out.print("请输入该s车型您要租多少辆:");
n[i] = in.nextInt();
System.out.print("请输入该车型您要租多少天:");
j[i] = in.nextInt();
sumzaike[i]+=kcar1.getzaikenum()*n[i];
sumprice[i]+=kcar1.getprice()*n[i]*j[i];
break;
case 2: name[i]=kcar2.getcar();
System.out.print("请输入该车型您要租多少辆:");
n[i] = in.nextInt();
System.out.print("请输入该车型您要租多少天:");
j[i] = in.nextInt();
sumzaike[i]+=kcar1.getzaikenum()*n[i];
sumprice[i]+=kcar1.getprice()*n[i]*j[i];
break;
case 3: name[i]=hcar1.getcar();
System.out.print("请输入该车型您要租多少辆:");
n[i] = in.nextInt();
System.out.print("请输入该车型您要租多少天:");
j[i] = in.nextInt();
sumzaizong[i]+=hcar1.getzaizongnum();
sumprice[i]+=hcar1.getprice()*n[i]*j[i];
break;
case 4: name[i]=hcar1.getcar();
System.out.print("请输入该车型您要租多少辆:");
n[i] = in.nextInt();
System.out.print("请输入该车型您要租多少天:");
j[i] = in.nextInt();
sumzaizong[i]+=hcar1.getzaizongnum();
sumprice[i]+=hcar1.getprice()*n[i]*j[i];
break;
case 5: name[i]=car.getcar();
System.out.print("请输入该车型您要租多少辆:");
n[i] = in.nextInt();
System.out.print("请输入该车型您要租多少天:");
j[i] = in.nextInt();
sumzaike[i]+=car.getzaikenum()*n[i];
sumzaizong[i]+=car.getzaizongnum()*n[i];
sumprice[i]+=car.getprice()*n[i]*j[i];
break;
}
}
System.out.println();
System.out.println("----------------------------------------------");
System.out.println("你的订单:");
System.out.println("----------------------------------------------");
System.out.println("汽车名称\t数量(辆)\t天数(天)\t可载人数/重量\t总租金");
for(int l=0;l<i;l++){
System.out.println(name[l] + "\t"+" " + n[l] +"\t"+" "+ j[l] + "\t"+" " + sumzaike[l]+"/" +sumzaizong[l] + "\t\t" + sumprice[l]);
}
System.out.println("----------------------------------------------");
double sum=0;
for(double sumprices:sumprice){
sum+=sumprices;
}
System.out.println("\t\t\t\t总金额(¥):" + sum);
System.out.println("----------------------------------------------");
System.out.println();
System.out.println("感谢您使用答答租车系统!");
in.close();
break;
}else{
System.out.println("指令有误!请输入正确的指令。");
continue;
}
}
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章