明月暖清风
2019-07-15 22:56
package com.test.practice; import java.util.*; public class Test { public static int summ; public static int umoney; public static String uname = ""; public static String mname = ""; public static String muname = ""; @SuppressWarnings("resource") public static void main(String[] args) {//创建租车流程系统 // TODO Auto-generated method stub System.out.println("欢迎使用答答租车系统!"); Car[] cars = { //创建可租车辆列表 new TruckCars("东风风神",0,20,1,500),new TruckCars("瑞沃卡车",0,10,1,350), new TruckCars("欧曼GTL",0,25,1,550),new passengerCars("宇通客车",48,0,1,450), new passengerCars("宇通客车",80,0,1,550),new passengerCars("金龙客车",25,0,1,350), new PickupCars("铃拓皮卡",4,6,1,500),new PickupCars("欧钻皮卡",5,5,1,550), new PickupCars("川崎皮卡",2,6,1,500) }; System.out.println("您是否需要进行车辆租赁?0否 1是"); Scanner sin = new Scanner(System.in); int typ; do { typ = sin.nextInt(); if(typ==1){ System.out.println("亲爱的顾客朋友,您可租用的车辆及相关信息有:"); System.out.println("序号\t名称\t\t载重量(吨)\t载人数(人)\t租金(元/天)"); for(int i=0;i<cars.length;i++){ System.out.println((i+1)+"\t"+cars[i].name+"\t\t"+cars[i].load+"\t\t"+cars[i].mannned+"\t\t"+cars[i].money); } System.out.println("请输入您所需要租赁的汽车数量:"); }else if (typ==0) { System.out.println("感谢您的光临,期待下次与您再见,祝您生活愉快!"); }else if(typ!=0&&typ!=1) { System.out.println("您好,您的输入不正确。请根据提示正确输入!"); } } while (typ!=0&&typ!=1); int num = sin.nextInt(); for(int i = 1;i <= num;i++){ System.out.println("请输入第"+i+"辆车的序号"); int typs = sin.nextInt(); switch (typs) { case 1: mname += cars[0].name; umoney += cars[0].money; break; case 2: mname += cars[1].name; umoney += cars[1].money; break; case 3: mname += cars[2].name; umoney += cars[2].money; break; case 4: uname += cars[3].name; umoney += cars[3].money; break; case 5: uname += cars[4].name; umoney += cars[4].money; break; case 6: uname += cars[5].name; umoney += cars[5].money; break; case 7: muname += cars[6].name; umoney += cars[6].money; break; case 8: muname += cars[7].name; umoney += cars[7].money; break; case 9: muname = cars[8].name; umoney += cars[8].money; break; default: break; } } System.out.println("请输入租赁车辆的天数:"); int day = sin.nextInt(); summ = umoney * day; System.out.println("您总共租赁车辆的账单为:"+summ+"元,以及您总租赁的车辆为"+num+"辆。"); System.out.println("可载人的车有:\n"+uname+"\n可载货车辆有:\n"+mname+"\n可载人载货车辆有:\n"+muname); } }
你这里都没用到面向对象的方法,很难提升自己代码视野的
主方法里最好是new对象来调用这些方法,方法可以写在父类里面来调用可以减少很多重复代码
Java入门第二季 升级版
530652 学习 · 6091 问题
相似问题