查看: 1491|回复: 0

[PHP实例] Java入门第二季 答答租车系统(新手一枚),只是我的思路

发表于 2018-3-13 08:00:11

父级(这个其实没必要写的)
package com.car;

public class First {
public int number=1;
public String name;
public int money;
public float person;
public float heavy;

}
子级1
package com.car;

public class Num1 extends First {
public int number=1;
public String name="奥迪A4";
public int money=500;
public float person=4f;
public float heavy=0f;
}
子级2
package com.car;

public class Num2 extends First {
public int number=2;
public String name="马自达6";
public int money=400;
public float person=4f;
public float heavy=0f;
};
类推,很简单吧
重要的来了!!!
输出代码
package com.car;
import java.util.Scanner;
public class Test {

  1. public static void main(String[] args) {
  2. // TODO Auto-generated method stub
  3. Scanner input=new Scanner(System.in);
  4. System.out.println("***欢迎使用滴滴租车系统***:");
  5. System.out.println("您是否要租车:1是 0否");
  6. int kais= input.nextInt();
  7. if(kais==1) {
  8. System.out.println("您可租车的类型及其价目表:");
  9. System.out.println("序号 汽车名称 租金 容量\n 1. 奥迪A4 500元/天 载人:4人\n 2. 马自达6 400元/天 载人:4人\n 3. 皮卡雪6 450元/天 载人:4人\n 4. 金龙 800元/天 载人:20人\n 5. 松花江 400元/天 载货4吨\n 6. 依维柯 1000元/天 载货:20吨");
  10. Num1 f1=new Num1();
  11. Num2 f2=new Num2();
  12. Num3 f3=new Num3();
  13. Num4 f4=new Num4();
  14. Num5 f5=new Num5();
  15. Num6 f6=new Num6();
  16. int max=0;
  17. String Mname="";
  18. float Mperson=0f;
  19. float Mheavy=0f;
  20. System.out.println("请输入您要租汽车的数量:");
  21. int shul=input.nextInt();
  22. for(int i=1;i<=shul;i++) {
  23. System.out.println("请输入你要租的第"+i+"辆车序号");
  24. int xuhao=input.nextInt();
  25. if(xuhao==1) {
  26. max=max+f1.money;
  27. Mname=Mname+"丶 "+f1.name;
  28. Mperson=Mperson+f1.person;
  29. Mheavy=Mheavy+f1.heavy;
  30. }else if(xuhao==2) {
  31. max=max+f2.money;
  32. Mname=Mname+"丶"+f2.name;
  33. Mperson=Mperson+f2.person;
  34. Mheavy=Mheavy+f2.heavy;
  35. }else if(xuhao==3) {
  36. max=max+f3.money;
  37. Mname=Mname+"丶"+f3.name;
  38. Mperson=Mperson+f3.person;
  39. Mheavy=Mheavy+f3.heavy;
  40. }else if(xuhao==4) {
  41. max=max+f4.money;
  42. Mname=Mname+"丶"+f4.name;
  43. Mperson=Mperson+f4.person;
  44. Mheavy=Mheavy+f4.heavy;
  45. }else if(xuhao==5) {
  46. max=max+f5.money;
  47. Mname=Mname+"丶"+f5.name;
  48. Mperson=Mperson+f5.person;
  49. Mheavy=Mheavy+f5.heavy;
  50. }else if(xuhao==6) {
  51. max=max+f6.money;
  52. Mname=Mname+"丶"+f6.name;
  53. Mperson=Mperson+f6.person;
  54. Mheavy=Mheavy+f6.heavy;
  55. }else {
  56. System.out.println("请输入1-6");
  57. i--;
  58. }
  59. };
  60. System.out.println("请输入你要租的天数");
  61. int day=input.nextInt();
  62. max=max*day;
  63. System.out.println("你这次租车有"+Mname+"这几辆车;总共可以座"+Mperson+"个人;总共可以装"+Mheavy+"吨;总金额为"+max+"元");
  64. }else {
  65. System.out.println(" see you 凉凉");
  66. }
  67. }
复制代码

}



回复

使用道具 举报