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 4 of 4

Thread: Insurance Premium class not compiling

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Insurance Premium class not compiling

    // Practical 7A (Revision) - Q6
    // Marcus Ward
    // 26/10/2011
    /* User will enter details, and program will calculate + display
    insurance premium. */

    import java.util.Scanner;

    public class DriverPremium
    {
    public static void main(String[] args)
    {
    Scanner keyboardIn = new Scanner(System.in);

    // declare variables
    double premium, age, carValue, penaltyPoints, drivingExperience;
    String gender;

    // get user input
    System.out.print("Please enter your age: ");
    age = keyboardIn.nextInt();
    System.out.print("Please enter your gender: ");
    gender = keyboardIn.nextLine();
    System.out.print("Please enter the value of your car: ");
    carValue = keyboardIn.nextInt();
    System.out.print("Please enter number of points on your license: ");
    penaltyPoints = keyboardIn.nextInt();
    System.out.print("Please enter number of years that you are driving: ");
    drivingExperience = keyboardIn.nextInt();

    premium = carValue*.05;

    if (age<28)
    premium = (carValue*0.5) + 175;

    else if (gender == female)
    premium = (carValue*0.5) * 0.8;

    else if (drivingExperience>=20&&penaltyPoints==0)
    premium = (carValue*0.5) * 0.8;

    else if ((drivingExperience>=8&&drivingExperience<20)&&pen altyPoints==0)
    premium = (carValue*0.5) * 0.8;

    else if (penaltyPoints>8)
    System.out.println("We unfortunately cannot insure you");
    }
    }

    Error Message
    DriverPremium.java:36: cannot find symbol
    symbol : variable female
    location: class DriverPremium
    else if (gender == female)
    Last edited by mwardjava92; November 3rd, 2011 at 10:14 AM.


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    9
    My Mood
    Depressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Insurance Premium class not compiling

    line 36, else if (gender == female)

    should be (gender == "female") because you are checking if the gender equals to a string "female" and not checking against a variable called female.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: Insurance Premium class not compiling

    Ah I see, thanks

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Insurance Premium class not compiling

    Quote Originally Posted by nggdowt View Post
    line 36, else if (gender == female)

    should be (gender == "female") because you are checking if the gender equals to a string "female" and not checking against a variable called female.
    Close...it should actually be
    gender.equals("female")
    (see http://www.javaprogrammingforums.com...html#post18725 )

Similar Threads

  1. Compiling error
    By Bri4n in forum Java Theory & Questions
    Replies: 5
    Last Post: November 7th, 2011, 10:26 PM
  2. Compiling error
    By tangara in forum Java IDEs
    Replies: 3
    Last Post: September 4th, 2011, 03:00 AM
  3. Compiling Error?
    By Arkeshen in forum Java Theory & Questions
    Replies: 2
    Last Post: June 22nd, 2011, 04:31 AM
  4. Help with Compiling
    By w.spidey in forum Object Oriented Programming
    Replies: 10
    Last Post: September 9th, 2010, 01:48 PM
  5. Need help compiling java class files
    By peahead in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 11th, 2010, 09:04 AM