package cn.shoot;
import java.util.Scanner;
public class qiche_1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("************欢迎您来到汽车租凭公司!*************");
System.out.println("请输入要租凭的天数:");
int tian=input.nextInt();
System.out.println("请输入要租凭的汽车类型(1:轿车\t 2:客车)");
int lei=input.nextInt(); // 选择类型 接受
jiaoches j=new jiaoches(); //new 轿车
keches k=new keches(); //new 客车
//判断 选的是什么类型
//轿车
if(lei==1){
j.calRent(lei,tian);
System.out.println("请输入要租凭的轿车品牌:");
int pin=input.nextInt();
pinpai p=new pinpai();
System.out.println("请输入要租凭的汽车型号:(1:商务舱GL8\t2:林荫大道)");
System.out.println("请输入轿车型号");
int s=input.nextInt();
p.calRent(s,tian);
//客车
}else if(lei==2){
k.calRent(lei,tian);
System.out.println("请输入要租凭的客车品牌:");
int pi=input.nextInt();
kes k1=new kes();
System.out.println("请输入客车座位数");
int e=input.nextInt();
k1.calRent(e,tian);
}
}
}
package cn.shoot;
//抽象lei
public abstract class qiche {
String bieke; //别克
String baoma; //宝马
String jinlong; //金龙
String jinbei; //金杯
//抽象方法
public abstract void calRent(int dte,double days); //方法 dte选择什么车 days租车天数 用来计算价格
}
//jiaoches轿车 是 汽车子类 是车的品牌父类
class jiaoches extends qiche {
String type; //型号
public void calRent(int xian,double days){ //xian 是选择 days是穿过来的天数 用来计算价格
this. bieke="别克";
this.baoma="宝马";
System.out.println("你要租凭的汽车类型是 “轿车”");
System.out.println("1:"+ bieke+"\t2:"+baoma);
}
}
//pinpai 车的品牌 是轿车的子类
class pinpai extends jiaoches{
public void calRent(int t,double days){ //t 是选择 days是穿过来的天数 用来计算价格
days=500.0; //这个车一天的租金
//这是最后直接的显示 对应测试类的 p.calRent(s,tian);
if(t==1){
System.out.println("分配给你的汽车牌号是:京AK8447");
days=days*t;
System.out.println("你的租车总金是"+days);
}else if(t==2){
System.out.println("分配给你的汽车牌号是:京BH8666");
days=800;
days=days*t;
System.out.println("你的租车总金是"+days);
}
}
}
//keches客车 是汽车子类 是客车的父类
class keches extends qiche{
String seatCount; //座位数
public void calRent(int da,double days){ //方法 租车天数
this.jinbei="金杯";
this.jinlong="金龙";
System.out.println("你要租凭的汽车类型是 “客车”");
System.out.println("1:"+jinbei+"\t"+"2:"+jinlong);
}
}
// kes是客车的大小 是客车的子类
class kes extends keches{
public void calRent(int y,double days){
days=500.0; //这个车一天的租金
//这是最后直接的显示 对应测试类的
if(y<16){
System.out.println("分配给你的汽车牌号是:京AK8888");
days=1000.0;
days=(double)days*y;
System.out.println("你的租车总金是"+days);
}else if(y>16){
System.out.println("分配给你的汽车牌号是:京BH7658");
days=(double)days*y;
System.out.println("你的租车总金是"+days);
}
}
}
2017-12-0615:12:39
原文:http://www.cnblogs.com/less1/p/7992826.html