最后一节的 代码 谁有
我 最后系统还是有点懵不会写 有现成的给我参考吗?各位大佬
我 最后系统还是有点懵不会写 有现成的给我参考吗?各位大佬
2018-08-12
import java.util.ArrayList; import java.util.Scanner; class SCar { int number; String name; int money; SCar(int number, String name, int money) { this.number = number; this.name = name; this.money = money; } } class Car extends SCar { int person; Car(int number, String name, int money, int person) { super(number, name, money); this.person = person; } public String toString() { return "车辆编号:" + number + "\t 车型:" + name + "\t 每天租金:" + money + "\t 可载人数:" + person ; } } class Pick extends Car { int goods; Pick(int number, String name, int money, int person, int goods) { super(number, name, money, person); this.goods = goods; } public String toString() { return "车辆编号:" + number + "\t 车型:" + name + "\t 每天租金" + money + "\t 可载人数:" + person + "\t 可载货物吨数:" + goods; } } class Turck extends SCar { int goods; Turck(int number, String name, int money, int goods) { super(number, name, money); this.goods = goods; } public String toString() { return "车辆编号:" + number + "\t 车型:" + name + "\t 每天租金:" + money + "\t 可载货物吨数:" + goods; } } public class LianXi { public static void main(String[] args) { System.out.println("欢迎来到Dehy租车系统"); System.out.println("是否进入租车系统:1-是 0-否"); Scanner scanner = new Scanner(System.in); int sc = scanner.nextInt(); if (sc == 0) { scanner.close(); return; } if (sc == 1) { System.out.println("可租用车辆信息"); Car c1 = new Car(1, "奥迪", 800, 4); Turck t1 = new Turck(2, "长安", 1000, 10); Pick p1 = new Pick(3, "福特猛禽", 800, 4, 1); System.out.println("车辆编号:" + c1.number + "\t车型:" + c1.name + "\t每天租金:" + c1.money + "\t\t可载人数:" + c1.person); System.out.println("车辆编号:" + t1.number + "\t车型:" + t1.name + "\t每天租金:" + t1.money + "\t\t可载货物吨数:" + t1.goods); System.out.println("车辆编号:" + p1.number + "\t车型:" + p1.name + "\t每天租金:" + p1.money + "\t\t可载人数:" + p1.person + "\t 可载货物吨数:" + p1.goods); System.out.println("请输入您需要租车数量"); Scanner scanner1 = new Scanner(System.in); int sc1 = scanner1.nextInt(); ArrayList<Car> list = new ArrayList(); ArrayList<Turck> list1 = new ArrayList(); ArrayList<Pick> list2 = new ArrayList(); ArrayList list3 = new ArrayList(); int money1 = 0; for (int i1 = 0; i1 < sc1; i1++) { System.out.println("请输入车辆编号"); Scanner scanner2 = new Scanner(System.in); int sc2 = scanner2.nextInt(); System.out.println("租用车辆信息"); if (sc2 == 1) { System.out.println("车辆编号:" + c1.number + "\t车型:" + c1.name + "\t租金:" + c1.money + "\t\t可载人数:" + c1.person); list.add(c1); list3.addAll(list); money1 = money1 + c1.money; } else if (sc2 == 2) { System.out.println("车辆编号:" + t1.number + "\t车型:" + t1.name + "\t租金:" + t1.money + "\t\t可载人数:" + t1.goods); list1.add(t1); list3.addAll(list1); money1 = money1 + t1.money; } else if (sc2 == 3) { System.out.println("车辆编号:" + p1.number + "\t车型:" + p1.name + "\t租金:" + p1.money + "\t\t可载人数:" + p1.person + "\t 可载货物吨数:" + p1.goods); list2.add(p1); list3.addAll(list2); money1 = money1 + p1.money; } else { System.out.println("输入有误,请重新输入车辆编号! 如想退出程序请输入:0"); System.out.println("请输入车辆编号"); Scanner scanner3 = new Scanner(System.in); int sc3 = scanner3.nextInt(); System.out.println("租用车辆信息"); if (sc3 == 1) { System.out.println("车辆编号:" + c1.number + "\t车型:" + c1.name + "\t租金:" + c1.money + "\t\t可载人数:" + c1.person); list.add(c1); list3.addAll(list); money1 = money1 + c1.money; } else if (sc3 == 2) { System.out.println("车辆编号:" + t1.number + "\t车型:" + t1.name + "\t租金:" + t1.money + "\t\t可载人数:" + t1.goods); list1.add(t1); list3.addAll(list1); money1 = money1 + t1.money; } else if (sc3 == 3) { System.out.println("车辆编号:" + p1.number + "\t车型:" + p1.name + "\t租金:" + p1.money + "\t\t可载人数:" + p1.person + "\t 可载货物吨数:" + p1.goods); list2.add(p1); list3.addAll(list2); money1 = money1 + p1.money; } else { scanner3.close(); return; } } } System.out.println("请输入租车天数"); Scanner scanner3 = new Scanner(System.in); int sc3 = scanner3.nextInt(); scanner3.close(); int money4 = money1 * sc3; System.out.println("租赁信息如下:"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < list3.size(); i++) { sb.append(list3.get(i)+"\r\n"); } String str = sb.toString(); System.out.println(str); System.out.println("租用车辆天数:" + sc3); System.out.println("租车所需金额:" + money4); } } }
package zuche;
import java.util.Scanner;
public class Test {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
System.out.println(" ***欢迎来到速运租车***");
System.out.println("请问您是否要租车?");
System.out.println("1:我想要租车 2:我逛逛看 3:我点错了");
boolean a = true;
while(a) {
int b = input.nextInt();
switch(b) {
case 1:
System.out.println("请问你需要什么类型的车?");
System.out.println("1:客车 2:货车 3:既能拉货又能拉客 4:返回上级菜单");
boolean c = true;
while(c) {
int d = input.nextInt();
switch(d) {
case 1:
Keche k = new Keche();
k.zaike();
c = false ;
break ;
case 2:
Huoche h = new Huoche();
h.lahuo();
c = false ;
break ;
case 3:
Zonghe z = new Zonghe();
z.zaike();
z.lahuo();
c = false ;
break ;
case 4:
Test.main(args);
c = false ;
break ;
default:
System.out.println("请问你需要什么类型的车?");
System.out.println("1:客车 2:货车 3:既能拉货又能拉客 4:返回上级菜单");
}
}
a = false;
break;
case 2:
Ggk g = new Ggk();
g.xinxi();
a = false;
break;
case 3:
System.out.println("退出程序!");
a = false;
break;
default:
System.out.println("请输入‘1’或者‘2’!");
}
}
}
}
举报