/*问题:User类账单部分要求显示用户选中的车有哪些是可以载人的,一共载人数量是多少以及那些车是载货的,共载货多少但我在自己的代码中到这里就卡壳了,请求各位大神的指导和帮助!谢谢!如图:*/Tool类
public class Tool {
char no;
String name;
int rent;
public char getNo() {
return no;
}
public void setNo(char no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRent() {
return rent;
}
public void setRent(int rent) {
this.rent = rent;
}
}
piKa类
public class piKa extends Tool{
private int personCapacity;
private int goodsCapacity;
public piKa(char no,String name,int rent,int personCapacity,int goodsCapacity){
this.no=no;
this.name=name;
this.rent=rent;
this.personCapacity= personCapacity;
this.goodsCapacity=goodsCapacity;
}
public int getPersonCapacity() {
return personCapacity;
}
public void setPersonCapacity(int personCapacity) {
this.personCapacity = personCapacity;
}
public int getGoodsCapacity() {
return goodsCapacity;
}
public void setGoodsCapacity(int goodsCapacity) {
this.goodsCapacity = goodsCapacity;
}
}
HuoChe类
public class huoChe extends Tool {
int goodsCapacity;
public huoChe(char no,String name,int rent,int goodsCapacity){
this.no=no;
this.name=name;
this.rent=rent;
this. goodsCapacity= goodsCapacity;
}
public int getGoodsCapacity() {
return goodsCapacity;
}
public void setGoodsCapacity(int goodsCapacity) {
this.goodsCapacity = goodsCapacity;
}
}
KeChe类
public class keChe extends Tool{
private int personCapacity;
public keChe(char no,String name,int rent,int personCapacity){
this.no=no;
this.name=name;
this.rent=rent;
this.personCapacity= personCapacity;
}
public int getPersonCapacity() {
return personCapacity;
}
public void setPersonCapacity(int personCapacity) {
this.personCapacity = personCapacity;
}
}
public class User {
static Scanner input = new Scanner(System.in);
static Tool[] t={new keChe('1',"奥迪A4",500,4),new keChe('2',"马自达6",400,4),
new piKa('3',"皮卡雪6",450,4,2),new keChe('4',"金龙",800,20),
new huoChe('5',"松花江",400,4),new huoChe('6',"依维柯",1000,20)};
public void zuChe(){
System.out.println("欢迎来到答答租车系统!");
System.out.println("您是否要租车:");
System.out.println("1:是 0:否");
int a = input.nextInt();
if(a==1){
System.out.println("您可租车的类型及价目表:");
System.out.println("序号\t汽车名称\t价目表\t\t容量");
for(Tool tool:t){
if(tool instanceof keChe)
System.out.println(tool.getNo()+"\t"+tool.getName()+"\t"+tool.getRent()
+"元/天"+"\t\t"+"载人:"+((keChe)tool).getPersonCapacity()+"人");
if(tool instanceof huoChe)
System.out.println(tool.getNo()+"\t"+tool.getName()+"\t"+tool.getRent()
+"元/天"+"\t\t"+"载货:"+((huoChe)tool).getGoodsCapacity()+"吨");
if(tool instanceof piKa)
System.out.println(tool.getNo()+"\t"+tool.getName()+"\t"+tool.getRent()
+"元/天"+"\t\t"+"载人:"+((piKa)tool).getPersonCapacity()+"人"+" "+"载货:"+((piKa)tool).getGoodsCapacity()+"吨");
}
}
}
public void select(){
System.out.println("请输入您要租车的数量:");
int b = input.nextInt();
int selectVclID[]=new int[b];
int costPerDay=0;
for(int i=0;i<b;i++){
System.out.println("请输入第"+(i+1)+"辆车的序号:");
selectVclID[i]=input.nextInt()-1;
costPerDay+=t[selectVclID[i]].rent;
}
System.out.println("请输入租车的天数:");
int rentDays=input.nextInt();
int allCost=costPerDay*rentDays;
System.out.println("您的账单:");
int peopleSum = 0 , volSum = 0 ;
System.out.println("***租车的总价格为:"+allCost);
}
}
Main类
public class Main {
public static void main(String args[]){
User user = new User();
user.zuChe();
user.select();
}
}
添加回答
举报
0/150
提交
取消