package com.tingyunguan;
public abstract class Car {//定义一个Car父类
public String Name;//用于接收汽车的名字
public int money;//用于接收每天租用所需费用
public int carry;//接收载货量
public int men;//载人数
//返回各个参数
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getCarry() {
return carry;
}
public int getMen() {
return men;
}
}
package com.tingyunguan;
public class Audi extends Car {//继承Car父类
public Audi(String Name, int money,int men) {//定义构造方法并接收车 名字 价格 载人量
this.Name=Name;
this.money=money;
this.men=men;
}
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getMen() {
return men;
}
}
package com.tingyunguan;
public class Iveco extends Car{
public Iveco(String Name, int money,int carry) {//定义构造方法并接收车 名字 价格 载货量
this.Name=Name;
this.money=money;
this.carry=carry;
}
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getCarry() {
return carry;
}
}
package com.tingyunguan;
public class Kinglong extends Car {
public Kinglong(String Name, int money,int men) {//定义构造方法并接收车 名字 价格 载人量
this.Name=Name;
this.money=money;
this.men=men;
}
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getMen() {
return men;
}
}
package com.tingyunguan;
public class Mazda extends Car {
public Mazda(String Name, int money, int men) {//定义构造方法并接收车 名字 价格 载人量
this.Name=Name;
this.money=money;
this.men=men;
}
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getMen() {
return men;
}
}
package com.tingyunguan;
public class pickup extends Car {
public pickup(String Name, int money, int men, int carry) {//定义构造方法并接收车 名字 价格 载人量 和载货量
this.Name=Name;
this.money=money;
this.carry=carry;
this.men=men;
}
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getCarry() {
return carry;
}
public int getMen() {
return men;
}
}
package com.tingyunguan;
public class Songhua extends Car {
public Songhua(String Name, int money,int carry) {//定义构造方法并接收车 名字 价格 载货量
this.Name=Name;
this.money=money;
this.carry=carry;
}
public String getName() {
return Name;
}
public int getMoney() {
return money;
}
public int getCarry() {
return carry;
}
}
package com.tingyunguan;
/*****项目名:答答租车系统
*****制作日期:2016.8.18
**制作人:4666-3545
*/
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//创建一个Car类数组,保存各个子类对象,并传入参数
Car[] carForRent = { new Audi("奥迪A4", 500, 4), new Mazda("马自达6", 600, 4), new pickup("皮卡雪6", 450, 4, 2),
new Kinglong("金龙", 800, 20), new Songhua("松花江", 400, 4), new Iveco("依维柯", 1000, 20) };
Scanner scan = new Scanner(System.in);//创建Scanner对象
System.out.println("欢迎使用答答租车系统");
System.out.println("您是否要租车:1.是 0否");
int input = scan.nextInt();//接收用户输入的数字
if (input == 0) {//判断用户输入的数字是否符合要求
System.out.println("退出系统");
} else if (!(input == 1) && !(input == 0)) {
System.out.println("输入错误");
} else if (input == 1) {
System.out.println("您可租车的类型及其价格目录:");
System.out.println("序号\t汽车名字\t租金\t容量");
for (int i = 0; i < carForRent.length; i++) {//循环遍历子类中,并打印其信息
if (i == 0 i == 1 i == 3) {
System.out.println(i + 1 + ".\t" + carForRent[i].getName() + "\t" + carForRent[i].getMoney()
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123