> 汽车类
package com.Dada;
public class Car {
private int num;
private String name;
private int rental;
private int manned;
private int load;
public int getManned() {
return manned;
}
public void setManned(int manned) {
this.manned = manned;
}
public int getLoad() {
return load;
}
public void setLoad(int load) {
this.load = load;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRental() {
return rental;
}
public void setRental(int rental) {
this.rental = rental;
}
}
> 小汽车类继承汽车(只载人)
package com.Dada;
public class Smallcar extends Car{
public Smallcar(int newNum, String newName, int newRental, int newManned) {
this.setNum(newNum);
this.setName(newName);
this.setRental(newRental);
this.setManned(newManned);
// TODO Auto-generated constructor stub
}
}
大车类(只载货)
package com.Dada;
public class BigCar extends Car{
public BigCar(int newNum, String newName, int newRental,int newLoad) {
this.setNum(newNum);
this.setName(newName);
this.setRental(newRental);
this.setLoad(newLoad);
// TODO Auto-generated constructor stub
}
}
皮卡类(载货载人)
package com.Dada;
public class PickCar extends Car {
public PickCar(int newNum, String newName, int newRental, int newManned,
int newLoad) {
this.setNum(newNum);
this.setName(newName);
this.setRental(newRental);
this.setManned(newManned);
this.setLoad(newLoad);
}
}
> 主函数
package com.Dada;
import java.util.Scanner;
import com.day07.smallcar;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Car car[] = { new Smallcar(1, "奥迪A4"+"\t", 500, 4),
new Smallcar(2, "马自达6"+"\t", 400, 4),
new PickCar(3, "皮卡雪6"+"\t", 450, 4, 2),
new Smallcar(4, "金龙"+"\t", 80, 20), new BigCar(5, "松花江"+"\t", 400, 4),
new BigCar(6, "依维柯"+"\t", 1000, 20) };
System.out.println("欢迎使用答答出租车系统:");
System.out.println("你是否要租车:1是 0否");
Scanner input = new Scanner(System.in);
int r = input.nextInt();
if (r == 1) {
String name1=" ";
String name2=" ";
String name3=" ";
String name4=" ";
String name5=" ";
String name6=" ";
int AllPeople=0;
int people=0;
int rental=0;
int Allrental=0;
int load=0;
int Allload=0;
System.out.println("您可租车的类型及其价目表:");
System.out
.println("序号" + "\t" + "汽车名称" + "\t" + "租金" + "\t" + "容量");
for (int x = 0; x < 6; x++) {
if (x == 0 x == 1 x == 3) {
System.out.println(car[x].getNum() + "." + "\t"
+ car[x].getName() + car[x].getRental()
+ "元/天" + "\t" + "载人" + car[x].getManned());
} else if (x == 2) {
System.out.println(car[x].getNum() + "." + "\t"
+ car[x].getName() + car[x].getRental()
+ "元/天" + "\t" + "载人" + car[x].getManned() + "载货"
+ car[x].getLoad()+"吨");
} else if(x == 4) {
System.out.println(car[x].getNum() + "." + "\t"
+ car[x].getName() + car[x].getRental()
+ "元/天" + "\t"+"载货" + car[x].getLoad()+"吨");
}
else if(x==5) {
System.out.println(car[x].getNum() + "." + "\t"
+ car[x].getName() + car[x].getRental()
+ "元/天" +"载货" + car[x].getLoad()+"吨");
}
}
System.out.println("请输入你要租车的数量");
Scanner intp = new Scanner(System.in);
int n = intp.nextInt();
for (int i = 1; i <= n; i++) {
System.out.println("请输入第" + i + "辆车的序号");
Scanner intput = new Scanner(System.in);
int choose = intput.nextInt();
if (choose == 1) {
name1=car[0].getName();
rental=car[0].getRental();
people=car[0].getManned();
} else if (choose == 2) {
name2=car[1].getName();
rental=car[1].getRental();
people=car[1].getManned();
} else if (choose == 3) {
name3=car[2].getName();
rental=car[2].getRental();
people=car[2].getManned();
load=car[2].getLoad();
} else if (choose == 4) {
name4=car[3].getName();
rental=car[3].getRental();
people=car[3].getManned();
} else if (choose == 5) {
name5=car[4].getName();
rental=car[4].getRental();
load=car[4].getLoad();
} else {
name6=car[5].getName();
rental=car[5].getRental();
load=car[5].getLoad();
}
AllPeople=AllPeople+people;
people=0;
Allload=Alload+load;
load=0;
Allrental=Allrental+rental;
rental=0;
}
System.out.println("请输入你要租车的天数:");
Scanner intp3 = new Scanner(System.in);
int day = intp3.nextInt();
System.out.println("您的账单:");
System.out.println("***可载人的车有:");
System.out.println(name1 + name2 + name3 + name4 + "共载人:" + AllPeople+ "人");
System.out.println("***载货的车有:");
System.out.println(name3 + name5 + name6 + "共载货:" + Allload + "吨");
System.out.println("租车总价格:" + Allrental*day);
}
else{
System.out.println("感谢使用嗒嗒租车系统");
}
}
打开App,阅读手记
热门评论
为啥我想不出来整个流程呢 笨死了
缺少判断继续租车模块,不够完美。