April 1, 2003

  • Anyone understand java? I am a bit frustrated with the fact that I have run into a wall… or “programmers block” compared to “writers block”, except its nothing in similarity… nvm…


    Anyone help? Please. thx!


    /* programmer: Matthew Yok
    course: Info Tech 12, Block E
    project: Car Rental Problem
    starting date: 03-03-07
    due date: 03-03-
    dependencies: KeyIn.java
    */
    import java.io.*;

    class Rental
    {
    //**************************main method**************************

    public static void main(String[]args) throws IOException
    {

    //**********************variable declarations********************

    int days, km, car_model;
    double rental_charge, subtotal, GST, total_cost, car_price, mileage_charge;

    //*********************title and introduction********************
    System.out.println(“tt Car Rental”);
    System.out.println(“tt +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=”);
    System.out.println(“This program will offer three different car models up for”);
    System.out.println(“rental. The daily rates are displayed below:”);
    System.out.println(“CAR MODEL               TYPE                    PRICE”);
    System.out.println(“Economy Model           1                       $24.95″);
    System.out.println(“Mid-size Model          2                       $24.95″);
    System.out.println(“Luxury Model            3                     
    $24.95.nn”);

    //************************requires input*************************

    System.out.println(“t Please enter car model number.”);
    car_model = KeyIn.anInt();
    if (car_model == 1)
    car_price = 24.95;
    else
    if (car_model == 2)
    car_price = 32.95;
    else
    if (car_model == 3)
    car_price = 44.90;
    else
    if (car_model > 3)
    System.out.println(“t Error, please restart.”);
    else
    if (car_model < 1)
    System.out.println(“t Error, please restart.”);

    System.out.println(“t Please enter number of days you wish to rent car
    model["+car_model+"].”);
    days = KeyIn.anInt();
    System.out.println(“t Each car is supplied with a car allowance of 100
    kilometers..”);
    System.out.println(“t You will be charged $0.20 per every additional
    kilometer.”);
    System.out.println(“t Please enter number of kilometers you will drive during
    your ["+days+"] day rental.”);
    km = KeyIn.anInt();
    if (km > 100)
    mileage_charge = ((km-100)*0.2) + 100;
    else
    if (km < 1)
    System.out.println(“t Error, please restart.”);
    else
    if ((km > 1) & (km < 100) | (km == 1) | (km == 100))
    mileage_charge = 0;
    //*********************calculation and output********************

    rental_charge = car_price * days;
    subtotal = rental_charge + mileage_charge;
    GST = subtotal * 0.7;
    total_cost = subtotal + GST;

    ;System.out.print(“nntCar model:                  “+car_model+”")
    ;System.out.println(“Car model’s daily price:        “+car_price+”");
    ;System.out.println(“Number of days to be rented:    “+days+”");
    ;System.out.println(“Kilometers:                     “+km+”");
    ;System.out.println(“Rental charge                   “+rental_charge+”");
    ;System.out.println(“Mileage charge                  “+mileage_charge+”");
    ;System.out.println(“Subtotal                        “+subtotal+”");
    ;System.out.println(“GST                             “+GST+”");
    ;System.out.println(“Total cost of the rental        “+total_cost+”");

    //***************************conclusion**************************

    ;System.out.println(“nt This program is now finished. Press Enter to exit.”);
    byte exit[]=new byte[1];
    System.in.read(exit);
    }
    }


Post a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *