package dd;
import java.util.Scanner;
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AllCar[] count={new car("奥迪A4",500,4),new car("大众",500,4),new Bus("巴士",600,12),new BigCar("东风",1000,2,10)};
int sum=0;//载人数
String name1="",name2="";
int money=0,day=0,again=0;
System.out.println("欢迎使用安达租车系统");
System.out.println("租车请按 1,退出请按0.");
int input=new Scanner(System.in).nextInt();
while(input>1){
System.out.println("输入不符合要求,请您从新输入");
input=new Scanner(System.in).nextInt();
}
if(input==1){
System.out.println("当前显示是可租车的详细信息:");
System.out.println("序号\t"+"车名\t"+"载人数\t"+"租金(元/天)\t"+"载货量\t");
for(int i=0;i<count.length;i++){
if(count[i] instanceof car){ System.out.println(i+1+"\t"+count[i].getXinghao()+"\t"+count[i].getZaikeliang()+"\t"+count[i].getZujin()+"\t\t"+count[i].getZaihuoliang());
}else if(count[i]instanceof Bus){
System.out.println(i+1+"\t"+count[i].getXinghao()+"\t"+count[i].getZaikeliang()+"\t"+count[i].getZujin()+"\t\t"+count[i].getZaihuoliang());
}else{ System.out.println(i+1+"\t"+count[i].getXinghao()+"\t"+count[i].getZaikeliang()+"\t"+count[i].getZujin()+"\t\t"+count[i].getZaihuoliang());
}
}
System.out.println("请输入您要租车的数量");
int countInput=new Scanner(System.in).nextInt();
for(int i=1;i<=countInput;i++){
System.out.println("请输入您要租的第"+i+"辆车");
int ci=new Scanner(System.in).nextInt();
if(count[ci-1] instanceof car){
name1=count[ci-1].getXinghao()+"\t"+name1;
sum+=count[ci-1].getZaikeliang();
money+=count[ci-1].getZujin();
}else if(count[ci-1] instanceof BigCar){
name2=count[ci-1].getXinghao()+"\t"+name2;
again+=count[ci-1].getZaihuoliang();
sum+=count[ci-1].getZaikeliang();
money+=count[ci-1].getZujin();
}else if(count[ci-1] instanceof Bus){
name1=count[ci-1].getXinghao()+"\t"+name1;
sum+=count[ci-1].getZaikeliang();
money+=count[ci-1].getZujin();
}
}
System.out.println("请输入租车天数");
day=new Scanner(System.in).nextInt();
if(day>0){
money=day*money;
}else{
System.out.println("最低租一天,请重新输入");
day=new Scanner(System.in).nextInt();
}
System.out.println("您的订单如下:");
if("".equals(name1)!=true){
System.out.println("可载客的有");
System.out.println(name1);
System.out.println("载入:4,租金:500");
}
if("".equals(name2)!=true){
System.out.println("可载或的有");
System.out.println(name2);
System.out.println("载人:2,租金:1000");
System.out.println(again+"吨");
}
System.out.println(money);
System.out.println("您是否要继续使用?是的话请按1否的话请按0" );
input=new Scanner(System.in).nextInt();
if(input==1){
main(args);
}else{
System.out.println("谢谢使用,欢迎下次光临");
System.exit(0);
}
}else if(input==0){
System.out.println("确定要退出?是的话请按0否的话请按1" );
input=new Scanner(System.in).nextInt();
if(input==1){
main(args);
}else{
System.out.println("谢谢使用,欢迎下次光临");
System.exit(0);
}
}
}
}
/
父类
*/
package dd;
public abstract class AllCar {
private String xinghao;
private int zujin;
private int zaikeliang;
private int zaihuoliang;
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public int getZujin() {
return zujin;
}
public void setZujin(int zujin) {
this.zujin = zujin;
}
public int getZaikeliang() {
return zaikeliang;
}
public void setZaikeliang(int zaikeliang) {
this.zaikeliang = zaikeliang;
}
public int getZaihuoliang() {
return zaihuoliang;
}
public void setZaihuoliang(int zaihuoliang) {
this.zaihuoliang = zaihuoliang;
}
}
/子类/
package dd;
public class car extends AllCar {
public car(String newxinghao,int newzujin,int newzaikeliang){
this.setXinghao(newxinghao);
this.setZaikeliang(newzaikeliang);
this.setZujin(newzujin);
}
}
/子类/
package dd;
public class Bus extends AllCar {
public Bus(String newxinghao,int newzujin,int newzaikeliang) {
// TODO Auto-generated constructor stub
this.setXinghao(newxinghao);
this.setZaikeliang(newzaikeliang);
this.setZujin(newzujin);
}
}
/子类/
package dd;
public class BigCar extends AllCar {
public BigCar(String newxinghao,int newzujin,int newzaikeliang,int newzaihuoliang) {
// TODO Auto-generated constructor stub
this.setXinghao(newxinghao);
this.setZaikeliang(newzaikeliang);
this.setZujin(newzujin);
this.setZaihuoliang(newzaihuoliang);
}
}