醉梦呆瓜
2018-12-14 09:36
package com.albote.dadazuche;
public class Car { public String name;//车名 public int carryingCapacity;//载人辆 public int rent;//租金 public int burden;//载货量 public void list() { System.out.println("\t"+ name + "\t租金:" + rent + "\t载人:" + carryingCapacity + "人\t载货:" + burden + "吨"); }//输出车名、租金、容量 }
package com.albote.dadazuche; public class Truck extends Car{ public void list() { System.out.println("\t"+ name + "\t租金:" + rent + "\t载货:" + burden + "吨"); } public Truck(String name_1,int rent_1,int carryingCapacity_1,int burden_1){ name = name_1; rent = rent_1; carryingCapacity = carryingCapacity_1; burden = burden_1; } }
package com.albote.dadazuche; public class PassageCar extends Car { public void list() { System.out.println("\t"+ name + "\t租金:" + rent + "\t载人:" + carryingCapacity + "人"); } public PassageCar(String name_1,int rent_1,int carryingCapacity_1,int burden_1){ name = name_1; rent = rent_1; carryingCapacity = carryingCapacity_1; burden = burden_1; } }
package com.albote.dadazuche; public class Pickup extends Car { public void list() { System.out.println("\t"+ name + "\t租金:" + rent + "\t载人:" + carryingCapacity + "人 载货:" + burden + "吨"); } public Pickup(String name_1,int rent_1,int carryingCapacity_1,int burden_1){ name = name_1; rent = rent_1; carryingCapacity = carryingCapacity_1; burden = burden_1; } }
package com.albote.dadazuche; import java.util.Scanner; public class Execirse { private static Scanner answer; public static Car[] car = {new Truck("小型货车",300,0,5), new Truck("大型货车",1000,0,20), new PassageCar("宝马Z4",3000,2,0), new PassageCar("奥迪A8",2000,5,0), new Pickup("江铃皮卡",1500,5,1), new Pickup("福特猛禽",2300,5,3)}; public static void main(String[] args) { answer = new Scanner(System.in); judgeIn();//判断是否进入系统9 showList();//输出租车列表 System.out.println("请输入您租车的数量"); int answer_2_1 = answer.nextInt(); int total = 0;//创建变量total,记录总租车价格。 int[] carCapacity = new int[car.length]; for (int i = 0;i < answer_2_1;i++){ System.out.println("请输入第" + (i+1) + "辆车的编号"); int answer_2_2 = answer.nextInt(); carCapacity[answer_2_2-1] = carCapacity[answer_2_2-1] + 1; System.out.println("请输入您需要租车的天数"); int day = answer.nextInt();//创建变量day,接收租车天数。 total = car[answer_2_2-1].rent * day + total;} for (int i = 0;i < car.length;i++) { if (carCapacity[i] > 0) System.out.print(car[i].name + ":" + carCapacity[i] +"辆 ");} System.out.println(); System.out.println("您好,您需要支付租车金额:" + total +"元。");} //判断是否进入系统 private static void judgeIn() { System.out.println("欢迎使用答答租车系统,请问您是否需要租车?\n1、是 2、否"); int answer_1 = answer.nextInt(); if (answer_1 != 1) { System.out.println("谢谢惠顾!"); System.exit(0);}} //输出租车列表 private static void showList() { System.out.println("以下是车辆信息,请您选择:\n序号\t汽车名称\t租金\t容量"); for (int i = 0;i < car.length;i++) { System.out.print((i+1)+"、"); car[i].list();}}}
页面代码排版真是醉了。。。
Java入门第二季 升级版
530678 学习 · 6091 问题
相似问题