Car Model Selection | 2008-02-05

Portfolio » Application Programming

This is project is about the simple Car listing where it ask user to input car make and model and gave the description of the car.

There are two class files, one is Main.java another one is CarList.java where it create the object of the CarList.

Main.Java

/*******************************************
Author: [email protected]
********************************************/

package CarList;

/**
 * @description:
 * This class file is the main class that call the methods of CarList object
 * @author Andy Ng
 */
public class Main {

    /**This is the main class file
     * Program start from here
     * @param args empty
     */

    public static void main(String[] args) {
        // Greeting
        System.out.println("Welcome to Automobile Showroom!");
        System.out.println("Please select from one of the following:");

        // Create car instance
        CarList NewCar = new CarList();

        // Enter Selections
        ***

        NewCar.setMake();
        NewCar.setModel( NewCar.GetMake() );
       
        // Result
        NewCar.showCar(NewCar.GetMake(), NewCar.GetModel());
    }
   
}

 

CarList.java

/*******************************************
Author: [email protected]
********************************************/

package CarList;

import java.io.*;

/**
 * @description:
 * This class file create the object of the Car List
 * with Makes and Model values
 * @author Andy Ng
 */
public class CarList {
    private String Make;
    private String Model;

    // Contructor
    public CarList(){}
    
    /**
     * @return String Make
     * Car Make value
     */
    public String setMake()
    {
        System.out.println("====================================");
        System.out.println("Please enter your Make Name (Word)!");

        // Show make list
        String[] MakeList = {"chevy","toyota","honda","ford"};
        for( int i=0; i< MakeList.length; i++ )
        {
            System.out.println(i+": "+MakeList[i]);
        }

        // Capture input
        BufferedReader MakeBR = new BufferedReader(new InputStreamReader(System.in));

        try
        {
            Make = MakeBR.readLine();
        }
        catch(IOException e)
        {
            System.out.println("Error!");
        }

        // Show result
        if( Make.equals("honda") )
        {
            System.out.println("You have select the make: "+Make);
        }
        else
        {
            System.out.println("Sorry, we do not have inventory for make "+Make);
            Make = "";
        }

        return Make;
    }

    /**
     * @return String Make
     * Car Make getter
     */
    public String GetMake(){ return Make; }

    /**
     * @param  String Make
     * Car Make value
     * @return String Model
     * Car Model value
     */
    public String setModel( String Make )
    {
        System.out.println("====================================");
        System.out.println("Please enter your Model Name for "+Make+" (Word)");

        if( Make.equals("honda") )  // As we have only honda in list
        {
            // Show model list
            *** = {"civic","accord","odessy"};
            for( int i=0; i< ModelList.length; i++ )
            {
                System.out.println(i+": "+ModelList[i]);
            }

            // Capture input
            BufferedReader ModelBR = new BufferedReader(new InputStreamReader(System.in));
            try
            {
               ***
                Model = ModelBR.***;
            }
            catch(IOException e)
            {
                System.out.println("Error!");
            }

            // Show reuslt
            System.out.println("You have select the model: "+Model+" for "+Make);
        } // if
        else    // If the make is not honda
        {
           ***
            System.out.println("I am sorry, no model inventory availiable for "+Make);
            Model = "";
        }

        return Model;
    }

    /**
     * @return String Model
     * Car Model value
     */
    public String GetModel(){ return Model; }

    /**
     * @param String Make
     * Car Make value
     * @param String Model
     * Car Model Value
     * @return void
     */
    public void showCar(String Make, String Model)
    {
        System.out.println("===================================="); // for easier reading

        // Make description
        if( Make.equals("honda") )
            System.out.println("Honda is a Japanese Car maker");
        else
            System.out.println("No Description availiable for make "+Make);

        // Model description
        if( Model.equals("civic") )
            System.out.println("Civic is a Econmoical model");
        else
            System.out.println("No Description availiable for model "+Model);
    }
}

 

*** indicated that some partial codes has been removed