Trouble with UseCarRental program I have to write

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Madmax40ao
    New Member
    • Nov 2013
    • 2

    Trouble with UseCarRental program I have to write

    First part having no trouble with this
    Code:
    public class CarRental
    {
       private String name = "";
       private int zipCode = 00000;
       private String carSize = "";
       private int daysRented = 0;
       private double totalFee = 0.00;
       private String chauffer = "";
       double chaufferFee = 0000.00;
       public CarRental(String n, int zc, String cs, int dr)
       {
          name = n;
          zipCode = zc;
          carSize = cs;
          daysRented = dr;
       }
       
       private double RentalFee(String carsize)
       {
          double fee = 0.00;
          if(carsize.equals("economy"))
          {
             fee = 29.99;
          }
          else if(carsize.equals("midsize"))
          {
             fee = 38.99;
          }
          else if(carsize.equals("fullsize"))
          {
             fee = 43.50;
          }
          else if(carsize.equals("luxury"))
          {
             fee = 79.99;
          }
          return fee;
       }
    }
    Second part also no trouble with this.
    public class LuxuryCarRental extends CarRental
    {
       public LuxuryCarRental(String n, int zc, String cs, int dr, String ch)
       {
          super(n, zc, cs, dr);
          if (ch.equals("y"))
             chaufferFee = 200.00;
       }
    }
    Final part is where the trouble is..
    import java.util.*;
    import java.text.*;
    public class UseCarRental
    {
       public static void main(String args[])
       {
          Scanner input = new Scanner(System.in);
          System.out.println("Enter your full name: ");
          input.next();
          String name = input.nextLine();
          System.out.println("Enter your zip code: ");
          int zipCode = input.nextInt();
          System.out.println("Enter the car size you would like to rent: \n"
                + "economy\n"
                + "midsize\n"
                + "fullsize\n"
                + "luxury?");
          String carSize = input.next();
          System.out.println("How many days would you like to rent this vechile for?");
          int daysRented = input.nextInt();
          if (carSize.equals("luxury"))
          {
             System.out.println("Would you like a chauffer? (y or n)");
             String chauffer = input.next();
             LuxuryCarRental rentIt = new LuxuryCarRental(name, zipCode, carSize, 
             daysRented, chauffer);
             rentIt.display();
          }
          else
          {
             CarRental rentIt = new CarRental(name, zipCode, carSize, daysRented);
             rentIt.display();
          }
    }
          private void display()
          {
             double fee = totalFee(carSize);
             System.out.println("Renters Name: " + name);
             System.out.println("Renters Zip Code:" + zipCode);
             System.out.println("Car Rented:" + carSize );
             System.out.println("Daily Rental Fee:" + fee);
             System.out.println("Total Days Rented:" + daysRented);
             double days = (double)daysrented;
             totalFee = (fee * days) + (chaufferFee * days);
             DecimalFormat df = new DecimalFormat("#.##");
             String trf = df.format(totalFee);
             System.out.println("Total Fee:" + tf);
          }
       }
    And this is the errors I'm getting.
    UseCarRental.ja va:27: error: cannot find symbol
    rentIt.display( );
    ^
    symbol: method display()
    location: variable rentIt of type LuxuryCarRental
    UseCarRental.ja va:32: error: cannot find symbol
    rentIt.display( );
    ^
    symbol: method display()
    location: variable rentIt of type CarRental
    UseCarRental.ja va:37: error: cannot find symbol
    double fee = totalFee(carSiz e);
    ^
    symbol: variable carSize
    location: class UseCarRental
    UseCarRental.ja va:38: error: cannot find symbol
    System.out.prin tln("Renters Name: " + name);
    ^
    symbol: variable name
    location: class UseCarRental
    UseCarRental.ja va:39: error: cannot find symbol
    System.out.prin tln("Renters Zip Code:" + zipCode);
    ^
    symbol: variable zipCode
    location: class UseCarRental
    UseCarRental.ja va:40: error: cannot find symbol
    System.out.prin tln("Car Rented:" + carSize );
    ^
    symbol: variable carSize
    location: class UseCarRental
    UseCarRental.ja va:42: error: cannot find symbol
    System.out.prin tln("Total Days Rented:" + daysRented);
    ^
    symbol: variable daysRented
    location: class UseCarRental
    UseCarRental.ja va:43: error: cannot find symbol
    double days = (double)daysren ted;
    ^
    symbol: variable daysrented
    location: class UseCarRental
    UseCarRental.ja va:44: error: cannot find symbol
    totalFee = (fee * days) + (chaufferFee * days);
    ^
    symbol: variable totalFee
    location: class UseCarRental
    UseCarRental.ja va:44: error: cannot find symbol
    totalFee = (fee * days) + (chaufferFee * days);
    ^
    symbol: variable chaufferFee
    location: class UseCarRental
    UseCarRental.ja va:46: error: cannot find symbol
    String trf = df.format(total Fee);
    ^
    symbol: variable totalFee
    location: class UseCarRental
    UseCarRental.ja va:47: error: cannot find symbol
    System.out.prin tln("Total Fee:" + tf);
    ^
    symbol: variable tf
    location: class UseCarRental
    12 errors
    Last edited by Rabbit; Nov 14 '13, 03:13 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    1.) You are calling the display method on the Car rental object but the method is not in the Car rental class. So move that method to the CarRental class.
    2.) If you want to be able to call that method outside that class then you need to make it public too.
    3.) You have a line
    Code:
    double days = (double)daysrented;
    which is incorrect because the variable called daysRented (with a capital R). Java is case sensitive.
    4.) You have another incorrect line with
    Code:
    double fee = totalFee(carSize);
    What are you trying to achieve with that?
    5.) You also have another typing mistake with
    Code:
     System.out.println("Total Fee:" + tf);
    which should be
    Code:
    System.out.println("Total Fee:" + trf);

    Comment

    • Madmax40ao
      New Member
      • Nov 2013
      • 2

      #3
      ok so i fixed some of the issues but i don't understand what you mean by #1 and 2 with the methods.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        You have
        Code:
        CarRental rentIt = new CarRental(name, zipCode, carSize, daysRented);
        rentIt.display();
        For you to call the method rentIt.display( ), it must be in the CarRental class because you are calling it on rentIt which is a reference to an object of the CarRental class. In your code that method is in the UseCarRental class instead so that won't work.

        Comment

        • itsraghz
          New Member
          • Mar 2007
          • 124

          #5
          Look at the lines 75 to 77 in your code pasted above.

          Code:
          LuxuryCarRental rentIt = new LuxuryCarRental(name, zipCode, carSize, 
                   daysRented, chauffer);
                   rentIt.display();
          Whereas the object rentIt is of type LuxuryCarRental . But the class LuxuryCarRental does not have a method 'display'. Hence the error.

          Comment

          Working...