Results 1 to 8 of 8
  1. #1
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default Need some litltle help. Almost done with project

    Thank you for taking the time to look at my issue. I am currently creating some code for a project to do certain things. The issue I have at hand is this. I am asking the code to have user put in a number which would be a rate and be calcuated down the road. I want to put a max value to this rate for example I have a max rate of 5.00$ if the person running the code puts any amount over that it would just use the max rate of 5.00 and if it is less than 5.00 use that number the user puts in. The entire code I have write is below so some help with checking it out would be great. Thanks ahead of time.

    // ================================================== ============================================
    // test1fence.java
    // CS-12 Justin Donaldson
    // Repetition with do/while, if/else statments, with a currency exchange loop
    // ================================================== =============================================

    import java.util.Scanner;
    import java.text.DecimalFormat;

    public class sierrafencing
    {
    public static void main( String [] args )
    {
    Scanner input = new Scanner(System.in);
    Scanner scan = new Scanner( System.in );
    DecimalFormat moneyForm = new DecimalFormat("$#0.00");


    int estimate, count = 0;
    String installationS, optionS;
    char installation, option;
    double LF, result, rate = 0.0, total = 0, RMAX = 5.00, NMAX = 6.00;

    System.out.println("============================== ========================");
    System.out.println(" Welcome to Sierra Fencing Company");
    System.out.println("============================== ========================\n\n");



    System.out.print("Enter your first name and last name: " );
    String fullName = scan.nextLine( );
    String fullNameUpper = fullName.toUpperCase( ); //No matter what case changes full name to UPPER CASE

    System.out.println("\n\n========================== ============================");
    System.out.println(" Fence Service ");
    System.out.println("============================== ========================\n\n");
    String menu = "\nAvailable Options";
    menu += "\n\tR Repair Installation";
    menu += "\n\tN New Installation";

    System.out.println( menu ); // print the menu
    System.out.print( "Enter your option: " );
    installationS = scan.next( );
    installation = installationS.charAt( 0 );

    do
    {

    switch ( installation )
    {
    case 'R':
    case 'r':
    if ( inputNum < RMAX )
    {
    rate = inputNum;
    }
    else rate = RMAX;

    break;

    case 'N':
    case 'n':
    if ( inputNum < NMAX )
    {
    rate = inputNum;
    }
    else rate = NMAX;
    break;

    default:
    System.out.println( installation + " is not valid." );
    System.exit( 0 );
    }

    System.out.print("\nPlease enter linear feet of fencing: " );
    LF = input.nextDouble( );

    System.out.print("\nPlease enter cost per linear foot in $0.00 format : ");
    double inputNum = input.nextDouble( );


    result = LF * rate;
    count++;
    total += result;

    System.out.println("\n\nName: " + fullNameUpper);

    System.out.println("\nEstimated linear foot/feet: " + LF);
    System.out.println("\nEstimated cost per linear foot: " + moneyForm.format(rate));
    System.out.println("\nEstimated cost of fencing work is: " + moneyForm.format(result));




    System.out.println("\nIs there another estimate? Y/N : ");
    optionS = scan.next( );
    option = optionS.charAt( 0 );


    }
    while ( option != 'N' && option != 'n' );


    System.out.println("\nTotal number of installations or repairs is = " + count);
    System.out.println("Grand total of all estimates is = " + moneyForm.format(total));




    }
    }
    Last edited by JDAWG; 02-28-2009 at 02:09 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Perhaps you could say what the problem is?

    Does it compile? If not, and you can't understand the compiler message(s), post them.

    Does it do what you want? If not, say the program does when you run it and describe what you were expecting or intending to happen.

  3. #3
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    no it doesnt compile right. error is:

    sierrafencing.java:54: cannot find symbol
    symbol : variable inputNum
    location: class sierrafencing
    if ( inputNum <= RMAX )
    ^
    sierrafencing.java:56: cannot find symbol
    symbol : variable inputNum
    location: class sierrafencing
    rate = inputNum;
    ^
    sierrafencing.java:64: cannot find symbol
    symbol : variable inputNum
    location: class sierrafencing
    if ( inputNum <= NMAX )
    ^
    sierrafencing.java:66: cannot find symbol
    symbol : variable inputNum
    location: class sierrafencing
    rate = inputNum;
    ^

    I thought i wrote it correctly to have it compile right so with that said something with the if and else statments need to change i guess
    Last edited by JDAWG; 02-28-2009 at 02:12 AM. Reason: add more

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Java Code:
    sierrafencing.java:54: cannot find symbol
    symbol  : variable inputNum
    location: class sierrafencing
    				if ( inputNum <= RMAX )
    				     ^
    The "cannot find symbol" error occurs when you use a method or variable (in this case inputNum) but have not declared that variable anywhere.

    This is indeed the case here: you need to declare it (most likely as a double).

  5. #5
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    Isnt this declaring the variable for inputNum

    double inputNum = input.nextDouble( );

    which i have in my code already

    System.out.print("\nPlease enter cost per linear foot in $0.00 format : ");
    double inputNum = input.nextDouble( );

  6. #6
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    Even if i change the code around and give the variable double for inputNum up at the beginning i still get errors but they are different now but for the same area of the code

    error is

    ----jGRASP exec: javac -g C:\Documents and Settings\NCOC\My Documents\sierrafencing.java

    sierrafencing.java:54: variable inputNum might not have been initialized
    if ( inputNum <= RMAX )
    ^
    sierrafencing.java:64: variable inputNum might not have been initialized
    if ( inputNum <= NMAX )
    ^
    2 errors

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

    Default

    Good. that means you've solved the one error. Now solve the other by initializing the variable before using it. It makes sense that this variable should have some reasonable variable before you start using it in tests, right?

  8. #8
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    I didnt understand what you were meaning at first but took a guess to it and moved the code i was running to up toward the begging so it would have a value for inputNum. Then it all worked. Thanks for your help Fubarable and pbrockway2

Similar Threads

  1. Project Help
    By XxHEXSORxX in forum AWT / Swing
    Replies: 4
    Last Post: 01-28-2009, 10:01 AM
  2. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 08:12 PM
  3. How to use ejb in our project
    By Ragini Shukla in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 12-26-2008, 09:29 AM
  4. jsp project help
    By rajibmp in forum New To Java
    Replies: 4
    Last Post: 10-10-2008, 12:50 AM

Posting Permissions

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