Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Working on a Car Rental Program and need to finish by Tonight!!

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Working on a Car Rental Program and need to finish by Tonight!!

    Im currently working on creating a Car Rental program. Im nearly done but I have some errors that I need help fixing.

    There are three vehicle categories: cars, SUVs, and trucks.
    Each one needs the make/model, miles per gallon, num of seats, vehicle number (VIN)

    - must allow for the entry of new vehicles of a given type.
    - must be able to display the all the information related to a given vehicle type,
    including make/model, miles per gallon, vehicle seats, daily rate, weekend rate, weekly rate,
    and whether currently reserved or not.
    - must allow for vehicle reservation for a number of days, weeks, or months.
    - User must enter the VIN of the vehicle to reserve, the amount of time of the rental
    period desired, and the company name reserving the vehicle.
    - must allow a given company to enter the company name, and get a list of the complete cost of all the vehicles reserved for rental.

    Im fairly new to programming and Im having alot of trouble with inserting the functions into right positions in the VehicleApp to make everything work. Also, Im having some trouble understanding how to connect the car, truck, and SUV classes to the vehicle app so that I can calculate the total cost. I worked on for a long while last night and after a while I started just plugging things in where I thought they might go in order to get output.

    Im having a great amount of trouble figuring out how to actually reserve the cars and keep them in the array while the program is running. Im sure this has to do with the VehicleAppDoes anyone know how to do this?

    Im also having an issue with calcRentalCost. This is what I have so far:

    double calcRentalCost = (numDays * DailyCost) + (numWeeks * WeeklyCost) + (numMonths * MonthlyCost);

    However, since the app is static it wont allow for me to get the costs from another part of the program. What should I do?

    ANY HELP WOULD BE GREATLY APPRECIATED.

    This is what I have so far:


    Vehicle2:

    package vehicle2;

    public abstract class Vehicle2 {
    int Vin, MilePG;
    String Make, Model;
    Reservation reserve;
    double DailyCost, WeeklyCost, MonthlyCost;

    public Vehicle2(int MPG, String mke, String mdl){
    Make = mke;
    Model = mdl;
    MilePG = MPG;
    reserve = null;
    }

    public int getVin(){
    return Vin;
    }
    public int getMilePG(){
    return MilePG;
    }
    public String getMake(){
    return Make;
    }
    public String getModel(){
    return Model;
    }
    public double getDailyCost(){
    return DailyCost;
    }
    public double getWeeklyCost(){
    return WeeklyCost;
    }
    public double getMonthlyCost(){
    return MonthlyCost;
    }


    //public abstract double getDailyCost();
    //public abstract double getWeeklyCost();
    //public abstract double getMonthlyCost();

    public void setVin(int vn){
    Vin = vn;
    }
    public void setMilePG(int MPG){
    MilePG = MPG;
    }
    public void setMake(String mke){
    Make = mke;
    }
    public void setModel(String mdl){
    Model = mdl;
    }

    public void createReservation(String CompName, int numDays, int numWeeks, int numMonths){
    reserve = new Reservation(CompName,numDays, numWeeks, numMonths);
    }

    public boolean isReserved(Vehicle2[] vehicles, Reservation[] reserve){
    return !(reserve == null);
    }

    public String toString(){
    if (reserve == null){
    return getMake() + " " + getModel() + " " + getVin() + "Is not reserved";}
    else{
    return getMake() + " " + getModel() + " " + getVin() + "Is reserved";}
    }

    public double calcRentalCost(double total, double numDays, double numWeeks, double numMonths){
    total= (numDays * DailyCost) + (numWeeks * WeeklyCost) + (numMonths * MonthlyCost);
    return total;
    }
    }


    Reservation

    package vehicle2;

    public class Reservation {
    String companyName;
    int numDays, numWeeks, numMonths;

    public Reservation(String compName, int nDay, int nWeek, int nMonth){
    companyName = compName;
    numDays = nDay;
    numWeeks = nWeek;
    numMonths = nMonth;
    }

    public int getnumDays(){
    return numDays;
    }
    public int getnumWeeks(){
    return numWeeks;
    }
    public int getnumMonths(){
    return numMonths;
    }
    public String getcompanyName(){
    return companyName;
    }
    }

    Car

    package vehicle2;

    public class Car extends Vehicle2{
    double DailyCost;
    double WeeklyCost;
    double MonthlyCost;
    int NumSeats;


    public Car(int MPG, int seats, String mke, String mdl){
    super(MPG, mke,mdl);
    NumSeats = seats;
    reserve = null;
    }

    public int getNumSeats(){
    return NumSeats;
    }

    public void setDailyCost(){
    DailyCost = 24.95;
    }
    public void setWeeklyCost(){
    WeeklyCost = 149.95;
    }
    public void setMonthlyCost(){
    MonthlyCost = 514.95;
    }

    public void setNumSeats(int seats){
    NumSeats = seats;
    }
    }

    SUV

    package vehicle2;

    public class SUV extends Vehicle2{
    double DailyCost;
    double WeeklyCost;
    double MonthlyCost;
    int NumSeats;


    public SUV(int MPG, int seats, String mke, String mdl){
    super(MPG, mke,mdl);
    NumSeats = seats;
    reserve = null;
    }


    public void setDailyCost(){
    DailyCost = 29.95;
    }
    public void setWeeklyCost(){
    WeeklyCost = 189.95;
    }
    public void setMonthlyCost(){
    MonthlyCost = 679.95;
    }

    public void setNumSeats(int seats){
    NumSeats = seats;
    }
    }

    Truck

    package vehicle2;

    public class Truck extends Vehicle2{
    double DailyCost;
    double WeeklyCost;
    double MonthlyCost;
    int NumSeats;


    public Truck(int MPG, int seats, String mke, String mdl){
    super(MPG, mke,mdl);
    NumSeats = seats;
    reserve = null;
    }
    public void setDailyCost(){
    DailyCost = 34.95;
    }
    public void setWeeklyCost(){
    WeeklyCost = 224.95;
    }
    public void setMonthlyCost(){
    MonthlyCost = 797.95;
    }

    public void setNumrCap(int seats){
    NumSeats = seats;
    }
    }


    Vehicle2App

    package vehicle2;
    import java.util.*;

    public class Vehicle2App{

    public static void displayVehicles(Vehicle2[] vehicles, Reservation[] reserve){
    for (int x = 1; x <= 25; x++){
    if (isReserved(vehicles, reserve) == true){
    System.out.println("Vehicle " + x + ": " + vehicles[x - 1] + ", is currently reserved");
    }
    else{
    System.out.println("Vehicle " + x + ": " + vehicles[x - 1] + ", is not reserved");
    }
    }
    }

    public static int findNext(int loc){
    loc = 0;
    for (int x = 0; x <= 24; x++){
    x = loc + 1;
    return x;
    }
    return 0;
    }
    public static void main(String[] args){

    String Make, Model, Company_name;
    int cmd, Selection, total_cost, Vin, MilePG, seats;

    Vehicle2[] vehicles = new Vehicle2[25];

    Scanner input = new Scanner(System.in);
    boolean quit = false;

    int loc = 0;
    while(!quit){
    System.out.println(" 1- Enter a new vehicle \n 2- Display all vehicles \n 3- Reserve a specific vehicle (by a specific company). \n 4- Display itemized list and total cost of all vehicles reserved for a specified company. \n 5- Quit");
    cmd = input.nextInt();

    if(cmd==5){
    quit = true;}
    else{
    switch(cmd){
    case 1: System.out.print("Enter(1)Car, (2)SUV, (3)Truck:");
    Selection = input.nextInt();

    switch(Selection){

    case 1: System.out.print("Enter the make of the car:");
    Make = input.next();
    System.out.print("Enter the model of the car:");
    Model = input.next();
    System.out.print("Enter the number of seats:");
    seats = input.nextInt();
    System.out.print("Enter the MPG:");
    MilePG = input.nextInt();
    loc = findNext(loc);
    vehicles[loc] = new Car(MilePG, seats, Make, Model);
    break;


    case 2: System.out.print("Enter the make of the SUV:");
    Make = input.next();
    System.out.print("Enter the model of the SUV:");
    Model = input.next();
    System.out.print("Enter the number of seats:");
    seats = input.nextInt();
    System.out.print("Enter the MPG:");
    MilePG = input.nextInt();
    loc = findNext(loc);
    vehicles[loc] = new SUV(MilePG, seats, Make, Model);
    break;

    case 3: System.out.print("Enter the make of the Truck:");
    Make = input.next();
    System.out.print("Enter the model of the Truck:");
    Model = input.next();
    System.out.print("Enter the number of seats:");
    seats = input.nextInt();
    System.out.print("Enter the MPG:");
    MilePG = input.nextInt();
    loc = findNext(loc);
    vehicles[loc] = new Truck(MilePG, seats, Make, Model);
    break;
    }

    //case 2: displayVehicles(vehicles);
    break;

    case 3: System.out.print("Enter the vin of the vehicle to reserve:");
    Vin = input.nextInt();
    System.out.println("How many months, weeks or days would you like to rent for? \n");

    System.out.println("Months(if none type 0)?");
    int numMonths = input.nextInt();

    System.out.println("Weeks(if none type 0)?");
    int numWeeks = input.nextInt();

    System.out.println("Days(if none type 0)?");
    int numDays = input.nextInt();
    //reserveVehicle(Vin);// Supporting function

    case 4: System.out.print("Enter Company name: ");
    String compName = input.next();


    //double calcRentalCost = total_cost;
    //calcRentalCost = (numDays * DailyCost) + (numWeeks * WeeklyCost) + (numMonths * MonthlyCost);
    //displayVehicles(compName);
    //System.out.println("Total cost for all vehicles: $" + total_cost);
    }
    }
    }
    System.out.println("Goodbye");
    }


    // public static boolean isReserved(Vehicle2[] vehicles, Reservation[] reserve){
    // for (int x = 0; x <= vehicles.length; x++){
    // if ((vehicles[x].Vin) == (reserve[0].Vin)){
    // return true;
    // }
    // else{
    // return false;
    // }
    // }
    // return false;
    // }

    }
    }


    Let me know what you think.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Working on a Car Rental Program and need to finish by Tonight!!

    A better way to get fast help is not to post your deadline but rather to read the forum FAQ so that you know how to edit your post to add code tags around your code so that your posted code is readable and understandable. Also indicate by comment which line(s) is causing errors, and show the actual error message.

  3. #3
    Member suyog53's Avatar
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    37
    My Mood
    Daring
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Working on a Car Rental Program and need to finish by Tonight!!

    passing value from static is congested...'
    why don't you create a method include all the variables in it....'
    then access them into other class by referencing that method'

Similar Threads

  1. Can anyone help me finish creating a GUI for my program
    By danbendlin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 16th, 2012, 07:34 PM
  2. [SOLVED] Help me finish this program :(
    By thisbeme in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 12th, 2011, 03:09 AM
  3. The car/vehicle application will be responsible for providing a car simulation.
    By vikasreddy556 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 20th, 2011, 01:32 AM
  4. Get out of loop to finish program?
    By Doofy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 17th, 2011, 08:34 AM
  5. tax return program..help finish please!!
    By dscrudato21xo in forum Loops & Control Statements
    Replies: 2
    Last Post: November 5th, 2009, 02:23 PM

Tags for this Thread