package com.earl;
//父类
public class Car {
private String name;
private int price;
private int personcapitation;
private int productioncapitation;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getPersoncapitation() {
return personcapitation;
}
public void setPersoncapitation(int personcapitation) {
this.personcapitation = personcapitation;
}
public int getProductioncapitation() {
return productioncapitation;
}
public void setProductioncapitation(int productioncapitation) {
this.productioncapitation = productioncapitation;
}
}
package com.earl;
//轿车子类
public class Jiaocar extends Car {
public Jiaocar(String name,int price,int personcapitation){
setName(name);
setPrice(price);
setPersoncapitation(personcapitation);
}
}
package com.earl;
//货车子类
public class Huocar extends Car {
public Huocar(String name,int price,int productioncapitation){
setName(name);
setPrice(price);
setProductioncapitation(productioncapitation);
}
}
package com.earl;
//皮卡子类
public class Picar extends Car {
public Picar(String name,int price,int personcapitation,int productioncapitation){
setName(name);
setPrice(price);
setPersoncapitation(personcapitation);
setProductioncapitation(productioncapitation);
}
}
package com.earl;
import java.util.Scanner;
import java.util.Arrays;
public class Test {
private static int[][] rentdata=new int[4][2];
private static int pricesum;
private static int personsum;
private static int productionsum;
static Scanner keyin=new Scanner(System.in);
public static void main(String[] args) {
//车辆数据
Car[] cardata={new Jiaocar("奥迪",500,4),new Jiaocar("马自达6",400,4),new Picar("皮卡雪6",450,4,2),new Jiaocar("金龙",800,20),new Huocar("松花江",400,4),new Huocar("依维柯",1000,25)};
//欢迎信息
System.out.println("欢迎使用嗒嗒租车服务!");
System.out.println("是否需要租车? 1是 0否");
String key=keyin.next();
//System.out.println(key);
if(key.equals("1")){//需要租车
//显示车辆信息
System.out.println("序号 名称 价格(Y) 载客(P) 载货(T)");
for(int i=1;i<=cardata.length;i++){
System.out.print(i+" ");
System.out.print(cardata[i-1].getName()+" ");
System.out.print(cardata[i-1].getPrice()+" ");
System.out.print(cardata[i-1].getPersoncapitation()+" ");
System.out.println(cardata[i-1].getProductioncapitation());
}
//选择车辆
for(int i=0;i<4;i++){
//选择车辆序号
System.out.println("请输入租用的第"+(i+1)+"辆车序号:");
rentdata[i][0]=keyin.nextInt();
if(rentdata[i][0]<1||rentdata[i][0]>6){
System.out.println("只能输入1-6");
i--;
continue;
}
//选择使用天数
if(i==3){
for(int j=0;j<4;j++){
System.out.println("请输入租用的第"+(j+1)+"辆车使用天数:");
rentdata[j][1]=keyin.nextInt();
if(rentdata[j][1]<1||rentdata[j][1]>100){
System.out.println("只能输入1-100");
j--;
continue;
}
}
//确认选择的车子
System.out.println("***************************已选中车辆***************************");
System.out.println("序号 名称 价格(Y) 载客(P) 载货(T) 租用天数(D)");
for(int j=1;j<=4;j++){
System.out.print(j+" ");
System.out.print(cardata[rentdata[j-1][0]-1].getName()+" ");
System.out.print(cardata[rentdata[j-1][0]-1].getPrice()+" ");
System.out.print(cardata[rentdata[j-1][0]-1].getPersoncapitation()+" ");
System.out.print(cardata[rentdata[j-1][0]-1].getProductioncapitation()+" ");
System.out.println(rentdata[j-1][1]);
//计算总载人、载货、价格
pricesum+=cardata[rentdata[j-1][0]-1].getPrice()*rentdata[j-1][1];
personsum+=cardata[rentdata[j-1][0]-1].getPersoncapitation();
productionsum+=cardata[rentdata[j-1][0]-1].getProductioncapitation();
}
System.out.println("****************************************************************");
System.out.println("共可载人:"+personsum);
System.out.println("共可载货:"+productionsum);
System.out.println("总价:"+pricesum);
System.out.println("****************************************************************");
System.out.println("是否确认?1确认 0重选");
//输入确认或重选
key=keyin.next();
if(key.equals("0")){
i=-1;
pricesum=0;
personsum=0;
productionsum=0;
continue;
}else{
System.out.println("感谢使用!");
}
}
}
}else if(key.equals("0")){//不租车
System.out.println("谢谢使用!");
}else{
System.out.println("输入错误!");
}
}
}