第八天学到继承了。。。求大神指教!
-----------------------------------
class Car_Project { //车类
private String bread; //车的类型
private int sum; //载客量
private int price; //价格
public Car_Project() {}
public Car_Project(String bread,int sum,int price) {
this.bread = bread;
this.sum = sum;
this.price = price;
}
public void setBread(String bread) {
this.bread = bread;
}
public String getBread() {
return bread;
}
public void setSum(int sum) {
this.sum = sum;
}
public int getSum() {
return sum;
}
public void setPrice(int Price) {
this.price = price;
}
public int getPrice() {
return price;
}
}
------------------------------------------
class Cra_jc extends Car_Project{ //轿车类
public Cra_jc() {}
public Cra_jc(String bread,int sum,int price) {
super(bread,sum,price);
}
public void jc_xx() { //车的信息
System.out.println(getBread() + ",载客量:" + getSum() + "人," + "租车费用一天为:" + getPrice() + "元!");
}
}
--------------------------------
class Car_Pk extends Car_Project{ //皮卡车类
public Car_Pk() {}
public Car_Pk(String bread,int sum,int price) {
super(bread,sum,price);
}
public void pk_xx() { //皮卡车的信息
System.out.println(getBread() + ",载客量:" + getSum() + "人," + "租车费用一天为:" + getPrice() + "元!");
}
}
-----------------------------------
class Car_Hc extends Car_Project{ //货车类
public Car_Hc() {}
public Car_Hc(String bread,int sum,int price) {
super(bread,sum,price);
}
public void hc_xx() { //货车的信息
System.out.println(getBread() + ",载客量:" + getSum() + "人," + "租车费用一天为:" + getPrice() + "元!");
}
}
-----------------------------------------
import java.util.Scanner;
class Car_Test { //测试类
private static String user; //用户
private static String pass; //密码
public static int count = 0; //天数
public static int sum = 0; //辆数
public void setUser(String user) {
this.user = user;
}
public String getUser() {
return user;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getPass() {
return pass;
}
public static void main(String[] args) {
int i = 1; //次数
do{
System.out.println("\t************欢迎使用租车系统*************");
Scanner in = new Scanner(System.in);
System.out.print("\t请输入账号:");
user = in.next();
System.out.print("\t请输入密码:");
pass = in.next();
if(user.equals("1113909656") & pass.equals("123")) {
System.out.println("\t登陆成功!");
System.out.println("\t你是否使用请选择:1(进入) OR 2(退出)");
System.out.print("\t请选择:");
int out = in.nextInt();
switch(out) {
case 1:
System.out.println();
System.out.println("\t以下是各种车的信息:" + "\n");
Cra_jc c1 = new Cra_jc("\t1,奔驰",5,500);
c1.jc_xx();
Car_Pk c2 = new Car_Pk("\t2,雪佛兰皮卡",10,450);
c2.pk_xx();
Car_Hc c3 = new Car_Hc("\t3,货车",2,400);
c3.hc_xx();
System.out.println("\t4,多选类型");
System.out.println();
System.out.print("\t请选择租用车的类型:");
int out2 = in.nextInt();
switch(out2) {
case 1:
System.out.print("\t你选择的是:" );
Cra_jc ca1 = new Cra_jc("\t1,奔驰",5,500);
ca1.jc_xx();
System.out.print("\t请输入租用辆数:");
sum = in.nextInt();
System.out.print("\t请输入租用天数:");
count = in.nextInt();
System.out.println("\t您需要支付:" + sum*count*ca1.getPrice() + "元");
break;
case 2:
System.out.print("\t你选择的是:");
Car_Pk ca2 = new Car_Pk("\t2,雪佛兰皮卡",10,450);
ca2.pk_xx();
System.out.print("\t请输入租用辆数:");
sum = in.nextInt();
System.out.print("\t请输入租用天数:");
count = in.nextInt();
System.out.println("\t您需要支付:" + sum*count*ca2.getPrice());
break;
case 3:
System.out.print("\t你选择的是:");
Car_Hc ca3 = new Car_Hc("\t3,宇通货车",25,400);
ca3.hc_xx();
System.out.print("\t请输入租用辆数:");
sum = in.nextInt();
System.out.print("\t请输入租用天数:");
count = in.nextInt();
System.out.println("\t您需要支付:" + sum*count*ca3.getPrice());
break;
case 4:
Cra_jc dx = new Cra_jc("\t1,奔驰",5,500);
dx.jc_xx();
Car_Pk dx2 = new Car_Pk("\t2,雪佛兰皮卡",10,450);
dx2.pk_xx();
Car_Hc dx3 = new Car_Hc("\t3,货车",2,400);
dx3.hc_xx();
System.out.println("\t如不需要请选择: 0");
dx.jc_xx();
System.out.print("\t请输入租用辆数:");
sum = in.nextInt();
System.out.print("\t请输入租用天数:");
count = in.nextInt();
System.out.println("\t您需要支付:" + sum*count*dx.getPrice() + "元");
System.out.println("\t---------------------");
dx2.pk_xx();
System.out.println("\t如不需要请选择: 0");
dx.jc_xx();
System.out.print("\t请输入租用辆数:");
sum = in.nextInt();
System.out.print("\t请输入租用天数:");
count = in.nextInt();
System.out.println("\t您需要支付:" + sum*count*dx2.getPrice() + "元");
System.out.println("\t---------------------");
dx3.hc_xx();
System.out.print("\t请输入租用辆数:");
sum = in.nextInt();
System.out.print("\t请输入租用天数:");
count = in.nextInt();
System.out.println("\t您需要支付:" + sum*count*dx3.getPrice() + "元");
break;
default:
System.out.println("\t非法输入!");
break;
}
case 2:
System.out.println("\t欢迎下次使用!");
break;
default:
System.out.println("\t非法输入!");
break;
}
}else {
System.out.println("\t登陆失败!");
i++;
}
}while(i < 1);
}
}
|
|