首页 > IT职业 > IT图书 > 答答租车系统规范代码示例
父类
package practice;
public class Car {
public String carname;
public int busload;//载客量
public double burden;//载货量
public double money;//金额
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
载货子类
package practice;
public class Busdencar extends Car {
public String carname;
public int busload;//载客量
public double burden;//载货量
public double money;//金额
public Busdencar(String carname,int busload, double burden,double money){
this.carname = carname;
this.busload = busload;
this.burden = burden;
this.money = money;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
载客子类
package practice;
public class Busloadcar extends Car {
public String carname;
public int busload;//载客量
public double burden;//载货量
public double money;//金额
public Busloadcar(String carname,int busload, double burden,double money){
this.carname = carname;
this.busload = busload;
this.burden = burden;
this.money = money;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
载客载货子类
package practice;
public class PackUp extends Car {
public String carname;
public int busload;//载客量
public double burden;//载货量
public double money;//金额
public PackUp(String carname,int busload, double burden,double money){
this.carname = carname;
this.busload = busload;
this.burden = burden;
this.money = money;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
用户测试代码
package practice;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car[] car = {new Busloadcar("奥迪A4",4,0,500),new Busloadcar("马自达6",4,0,400),
new PackUp("皮卡雪6",4,2,450),new Busloadcar("金龙",20,0,800),new Busdencar("松花江",0,4,400),
new Busdencar("依维柯",0,20,1000)};
//询问用户
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:1是 0否");
Scanner console = new Scanner(System.in);
int answer = console.nextInt();
int i = 1;
if(answer == 1){
//输出可租车型及其价目表
System.out.println("您可租输的类型及其价目表:");
System.out.println("序号" + " " + "汽车名称" + " " + "租金" + " " + "容量");
for(Car foreachcar : car){
System.out.println(i + " " + foreachcar.getCarname() + " " + foreachcar.getMoney() + "元/天" + " "+ "载人:" +
foreachcar.getBusload() + "人" + " " + "载货" + foreachcar.getBurden() + "吨");
i++;
}
//询问用户租车数量
System.out.println("请输入您要租汽车的数量:");
int count = console.nextInt();
Car[] rentcar = new Car[count];
for(int j = 0 ; j 
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1762/viewspace-2798499/ ,如需转载,请注明出处,否则将追究法律责任。