Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default Help with this program.

    Hey guys, I have a school assignment and I am supposed to create a code that designs a program that does the following pseudocode:

    Start

    Display a welcoming message

    Ask for the required number of passengers from 1-8

    Ask about importance of mileage on a scale of 1-10

    Ask about importance of cargo space on a scale of 1-10

    If the user entered valid answers then

    If the passenger count is 6 or more Then

    Choose the Sports Utility Vehicle (SUV)

    Else

    If mileage is more important than cargo Then

    Choose the Hybrid Sedan

    Else

    If passenger count is 5 Then

    Choose SUV

    Else

    If cargo space importance was 7 or better Then

    Choose the Pickup w/Cab

    Else

    Choose the SUV

    End If

    End If

    End If

    End If

    Tell the customer which vehicle is recommended

    Else

    Tell the customer that their entries are not correct

    End If

    Thank the customer for their interest

    Stop
    Here is my code, I am very much a beginner so I am not sure what is wrong with it:
    public class VehicleChooser
    {

    public static void main(String args[])
    {
    //I'll declare the variables first.
    int numberOfPassengers = 0;
    int mileageRating = 0;
    int cargoRating = 0;
    String passengerString;
    String mileageString;
    String cargoString;
    final int HEAVY_CARGO = 7;
    final int TAXI_CAB = 5;
    final int SIX = 6;
    int vehicleNum = 0;
    String vehicle;

    System.out.println("Welcome to the Front Range Vehicle Center");

    //Here are my input GUIs.
    passengerString = JOptionPane.showInputDialog("How many passengers at most will you need to carry (1-8)? ");
    mileageString = JOptionPane.showInputDialog("How important is mileage (Rank on a scale of 1-10)?");
    cargoString = JOptionPane.showInputDialog("How important is cargo space (Rank on a scale of 1-10)?");

    //Now I'll convert the strings to integer variables.
    numberOfPassengers = Integer.parseInt(passengerString);
    mileageRating = Integer.parseInt(mileageString);
    cargoRating = Integer.parseInt(cargoString);

    if ((numberOfPassengers >= 1 && numberOfPassengers <= 8) && (mileageRating >= 1 && mileageRating <= 10) && (cargoRating >= 1 && cargoRating <= 10))


    {
    if (numberOfPassengers >= SIX)
    vehicleNum = 1;
    else if (mileageRating > cargoRating)
    vehicleNum = 2;
    else if (numberOfPassengers == TAXI_CAB)
    vehicleNum = 1;
    else if (cargoRating >= HEAVY_CARGO)
    vehicleNum = 3;
    }

    switch(vehicleNum)
    {
    case 1: vehicle = "Sports Utility Vehicle";
    break;
    case 2: vehicle = "Hybrid Sedan";
    break;
    case 3: vehicle = "Pickup w/Cab";
    break;
    default: vehicle = "Sports Utility Vehicle";
    }

    System.out.println("Based on your inputs, please consider our fine" + vehicle);
    System.out.println("Thanks for stopping by, come again soon");

    System.exit(0);
    }
    }
    Could anyone help me?

  2. #2
    bubbless is offline Member
    Join Date
    Mar 2009
    Posts
    81
    Rep Power
    0

    Default

    What's the error message?

  3. #3
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Here are the error messages:

    C:\Users\Jackson\Documents\VehicileChooser.java:1: class VehicleChooser is public, should be declared in a file named VehicleChooser.java
    public class VehicleChooser
    ^
    C:\Users\Jackson\Documents\VehicileChooser.java:22 : cannot find symbol
    symbol : variable JOptionPane
    location: class VehicleChooser
    passengerString = JOptionPane.showInputDialog("How many passengers at most will you need to carry (1-8)? ");
    ^
    C:\Users\Jackson\Documents\VehicileChooser.java:23 : cannot find symbol
    symbol : variable JOptionPane
    location: class VehicleChooser
    mileageString = JOptionPane.showInputDialog("How important is mileage (Rank on a scale of 1-10)?");
    ^
    C:\Users\Jackson\Documents\VehicileChooser.java:24 : cannot find symbol
    symbol : variable JOptionPane
    location: class VehicleChooser
    cargoString = JOptionPane.showInputDialog("How important is cargo space (Rank on a scale of 1-10)?");

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    C:\Users\Jackson\Documents\VehicileChooser.java:1: class VehicleChooser is public, should be declared in a file named VehicleChooser.java
    public class VehicleChooser
    Your class name is VehicleChooser while the file name is VehicileChooser -- something different, and hence the error as they both have to be exactly the same.

    C:\Users\Jackson\Documents\VehicileChooser.java:22 : cannot find symbol
    symbol : variable JOptionPane
    You need to import this class before you can use it.

  5. #5
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Thank you Fubarable, thanks to you I finally have it down :)
    Last edited by ShotGunRockets; 03-13-2009 at 11:47 PM.

  6. #6
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default

    pls mark this as solved
    Last edited by tomiu; 03-13-2009 at 11:50 PM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    glad it helped. Please realize that any one of us could have helped you and probably even sooner. The key is in how much information you provide and the quality of this information. If you get errors in the future and post a question here regarding this, it will help to always include the exact error message and some indication as the the line of code that is throwing the error. Best of luck with your Java coding!
    Last edited by Fubarable; 03-14-2009 at 12:53 AM.

Similar Threads

  1. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 05:17 PM
  2. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 09:24 AM
  3. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •