how implement rent system

//the first order should be package…
package com.imooc.thomas;
//the second order should be import system package
import java.util.ArrayList;
import java.util.Scanner;
//import java.util.ArrayList;
public class CarRentSystem {
// accept the input from System.in
public static String ls_input_buy;
public static int li_input_count, li_input_no, li_input_days,
li_output_passenger;
public static float lf_output_fare;
public static float li_output_ton;
public static String ls_output_name_passenger = “”,
ls_output_name_ton = “”, ls_element_datatype;
public static ArrayList<Integer> carNo = new ArrayList<Integer>();
// public static int[] carNo_values;
public static Object[] carNo_values;
protected static String ls_output_name;
public static Car[] cars = { new passageCar(“audi”, 234, 0f, 4),
new truckCar(“LiberationTruck”, 315, 40.5f, 0),
new truckCar(“pickup”, 217, 20.76f, 3) };
public static int li_i;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("Welcome to Use FMR Taxi System:");
    System.out.println("Whether or not you will rent the car:1 yes 0 no");
    System.out.println();
    // scan what the use input
    Scanner scan = new Scanner(System.in);
    // accept the input as string
    ls_input_buy = scan.next();
    // judge the input value.
    if (ls_input_buy.equals("1")) {
        System.out.println("the Cars and their type which you can rent:");
        System.out.println("Sequence\tName\tprice\tton\tpassenger");
    } else {
        System.out.println("you want to end the system");
    }
    // println the original construct stub info,using the array
    for (Car mycar : cars) {
        li_i++;
        // get the car info
        System.out.println(li_i + "\t" + mycar.getName() + "\t"
                + mycar.getPrice() + "\t" + mycar.getTon() + "\t"
                + mycar.getPassenger());

    }
    // input how many cars the customers will buy
    System.out.println("please input the car count you want:");
    li_input_count = scan.nextInt();
    System.out.println("you input is:" + li_input_count);
    // please input the sort No of cars
    for (int i = 0; i < li_input_count; i++) {
        System.out.println("please input the No of " + (i + 1) + "car:");
        // put such No into an array
        li_input_no = scan.nextInt();
        // System.out.println("what you input is:" + li_input_no);
        carNo.add(li_input_no);
        System.out.println("you choose:" + cars[li_input_no - 1].getName());
    }
    // define a new [] and convert ArrayList to it
    // carNo_values = new int[carNo.size()];
    // carNo_values = new int[carNo.Count];
    // int[] values = (int[]) carNo.toArray(new int[carNo.size()]);//
    // int[] values = (int[]) carNo.toArray(int[carNo.size()]);
    carNo_values = (Object[]) carNo.toArray(); // work well
    // int[] values = (int[]) carNo.toArray(new int[carNo.size()]);
    // carNo.CopyTo(carNo_values);
    // carNo_values = new int[carNo.Count];
    // List.CopyTo(values);
    // carNo_values = carNo.ToArray(typeof());
    System.out
            .println("please input how many days you want to rent these cars:");
    // input the days
    li_input_days = scan.nextInt();
    // get the summary of loading passenger and ton respectively
    for (int i = 0; i < carNo_values.length; i++) {
        // get the load passenger
        // if (cars[carNo_values[i] - 1].getPassenger() > 0) {
        // li_output_passenger += cars[carNo_values[i] - 1].getPassenger();
        // ls_output_name_passenger += cars[carNo_values[i] - 1].getName()
        // + "\t";
        // }
        // else if (cars[carNo_values[i] - 1].getTon() > 0) {
        //
        // li_output_ton += cars[carNo_values[i] - 1].getTon();
        // ls_output_name_ton += cars[carNo_values[i] - 1].getName()
        // + "\t";
        // }
        // System.out.println(carNo_values[i]);//work well
        // System.out.println((Integer)carNo_values[i]); //work well;convert
        // object to integer
        // get the element's datatype
        // Class<?> c1 = cars[(Integer)carNo_values[i] -
        // 1].getClass().getComponentType();
        // System.out.println(c1.getName());
        // boolean flag1 = cars[(Integer)carNo_values[i] - 1] instanceof
        // passageCar; //passageCar is car
        // boolean flag2 = cars[(Integer)carNo_values[i] - 1] instanceof
        // truckCar;
        // boolean flag3 = cars[(Integer)carNo_values[i] - 1] instanceof
        // Car;
        // judge which subclass is
        if (cars[(Integer) carNo_values[i] - 1] instanceof passageCar) {
            // passageCar
            ls_output_name_passenger += cars[(Integer) carNo_values[i] - 1]
                    .getName() + "\t";
            li_output_passenger += cars[(Integer) carNo_values[i] - 1]
                    .getPassenger();
            // convert to passenger subclass
            // li_output_ton += (passageCar)cars[(Integer)carNo_values[i] -
            // 1].fare(li_input_days,cars[(Integer)carNo_values[i].getPrice());
            lf_output_fare += cars[(Integer) carNo_values[i] - 1].fare(
                    li_input_days,
                    cars[(Integer) carNo_values[i] - 1].getPrice());// cars[(Integer)carNo_values[i]                                                                // -
                                                                    // 1].getPrice();
        } else if (cars[(Integer) carNo_values[i] - 1] instanceof truckCar) {
            // passageCar
            ls_output_name_ton += cars[(Integer) carNo_values[i] - 1]
                    .getName() + "\t";
            li_output_ton += cars[(Integer) carNo_values[i] - 1].getTon();
            lf_output_fare += cars[(Integer) carNo_values[i] - 1].fare(
                    li_input_days,
                    cars[(Integer) carNo_values[i] - 1].getPrice());
        }

        // calculate fare
        // Car cc = new passageCar();
        // lf_fare += cc.fare(li_input_days,cars[carNo_values[i] -
        // 1].getPrice());
    }
    // output the summary of your order
    System.out.println("your recipe:");
    System.out.println("***Cars which can load passenger:\n"
            + ls_output_name_passenger + "\ttotally load passengers:"
            + li_output_passenger);
    System.out.println("***Cars which can load ton:\n" + ls_output_name_ton
            + "\ttotally load ton:" + li_output_ton);
    System.out.println("***the total rent is:" + lf_output_fare);   }}
点赞