Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default programming help!!??

    Hi I keep receiving errors every time I try to compile the following:

    import java.util.Scanner;

    class GeometryCalculator {

    public static void main( String [] args ) {
    Scanner sc = new Scanner( System.in );
    boolean run = true;
    do {
    System.out.println("Please select from the following menu... ");
    System.out.println(" 1. Calculate the Area of a Circle");
    System.out.println(" 2. Calculate the Area of a Rectangle");
    System.out.println(" 3. Calculate the Area of a Triangle");
    System.out.println(" 4. Quit");
    System.out.print("Please make your selection ==> ");
    String selection = sc.nextLine();
    int choice = Integer.parseInt( selection );

    switch( choice ) {
    case 1 :
    System.out.println("You Entered, 1. Calculate the Area of a Circle");
    System.out.print("Enter the radius of the circle ==> ");
    float c = Float.parseFloat( sc.nextLine() );
    System.out.println( "The area is " + Geometry.areaCircle( c ) );
    break;
    case 2:
    System.out.println("You Entered, 2. Calculate the Area of a Rectangle");
    System.out.print("Enter the Length of the circle ==> ");
    System.out.print("Enter the Width of the circle ==> ");
    float r = Float.parseFloat( sc.nextLine() );
    System.out.println( "The area is " + Geometry.areaRectangle( r ) );
    break;
    case 3:
    System.out.println("You Entered, 3. Calculate the Area of a Triangle");
    System.out.print("Enter the radius of the circle ==> ");
    float t = Float.parseFloat( sc.nextLine() );
    System.out.println( "The area is " + Geometry.areaTriangle( t ) );
    case 4:
    run = false;
    break;
    default:
    System.out.println( "you must enter 1,2,3,or 4");
    }
    } while( run = true );
    System.out.println("Thanks for using our program");
    }
    }

    and
    public class Geometry
    {

    public static float areaCircle( float radius ) {
    if( radius < 0 )
    System.out.println("Can not have negative numbers");
    return (float) (Math.PI * ( radius * radius ));
    }
    public static float areaRectangle(float area){
    if( area < 0 )
    System.out.println("Can not have negative numbers");
    return (float) ( area * area );

    }
    public static float areaTriangle(float base){
    if( base < 0 )
    System.out.println("Can not have negative numbers");
    return (float) ( base * height * 0.5 );

    }
    }

    I've been working on this for 5 days, and I feel burned out. Please help!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    This forum is for Java developers not psychics. If you get error messages then how about including the EXACT messages in your post.

  3. #3
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    And also, please use the code tags:
    [ code] code goes right here [ /code ] without the spaces
    And format with spaces (preferably 3-4 spaces for a tab)

  4. #4
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    sorry bout that,
    "Geometry.java:18: cannot find symbol
    symbol : variable height
    location: class Geometry
    return (float) ( base * height * 0.5 );
    ^
    1 error"

    I don't know how/where to declare "height"

    Java Code:
    import java.util.Scanner;
    
    class GeometryCalculator {
    
    public static void main( String [] args ) {
    Scanner sc = new Scanner( System.in );
    boolean run = true;
    do {
    System.out.println("Please select from the following menu... ");
    System.out.println(" 1. Calculate the Area of a Circle");
    System.out.println(" 2. Calculate the Area of a Rectangle");
    System.out.println(" 3. Calculate the Area of a Triangle");
    System.out.println(" 4. Quit");
    System.out.print("Please make your selection ==> ");
    String selection = sc.nextLine();
    int choice = Integer.parseInt( selection );
    
    switch( choice ) {
    case 1 :
    System.out.println("You Entered, 1. Calculate the Area of a Circle");
    System.out.print("Enter the radius of the circle ==> ");
    float c = Float.parseFloat( sc.nextLine() );
    System.out.println( "The area is " + Geometry.areaCircle( c ) );
    break;
    case 2:
    System.out.println("You Entered, 2. Calculate the Area of a Rectangle");
    System.out.print("Enter the Length of the circle ==> ");
    System.out.print("Enter the Width of the circle ==> ");
    float r = Float.parseFloat( sc.nextLine() );
    System.out.println( "The area is " + Geometry.areaRectangle( r ) );
    break;
    case 3:
    System.out.println("You Entered, 3. Calculate the Area of a Triangle");
    System.out.print("Enter the radius of the circle ==> ");
    float t = Float.parseFloat( sc.nextLine() );
    System.out.println( "The area is " + Geometry.areaTriangle( t ) );
    case 4:
    run = false;
    break;
    default:
    System.out.println( "you must enter 1,2,3,or 4");
    }
    } while( run = true );
    System.out.println("Thanks for using our program");
    }
    }
    Java Code:
     
    public class Geometry
    {
    
    public static float areaCircle( float radius ) {
    if( radius < 0 )
    System.out.println("Can not have negative numbers");
    return (float) (Math.PI * ( radius * radius ));
    }
    public static float areaRectangle(float area){
    if( area < 0 )
    System.out.println("Can not have negative numbers");
    return (float) ( area * area );
    
    }
    public static float areaTriangle(float base){
    if( base < 0 )
    System.out.println("Can not have negative numbers");
    return (float) ( base * height * 0.5 );
    
    }
    }
    it's supposed to be a geometry calculator:

    1. Calculate the Area of a Circle
    2. Calculate the Area of a Rectangle
    3. Calculate the Area of a Triangle
    4. Quit

    Enter your choice ( 1- 4):
    Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu.

    thanks again in advance,

    I truly appreciate it.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Java Code:
    public static float areaRectangle(float area){
    If the method is supposed to calculate the area, why are you passing it in as a parameter?
    Java Code:
    public static float areaTriangle(float base){
        if( base < 0 )
            System.out.println("Can not have negative numbers");
        return (float) ( base * height * 0.5 );
    }
    :confused: You can handle the base but have no idea how to handle the height?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Java Code:
    System.out.println("You Entered, 2. Calculate the Area of a Rectangle");
    System.out.print("Enter the Length of the circle ==> ");
    System.out.print("Enter the Width of the circle ==> ");
    
    System.out.println("You Entered, 3. Calculate the Area of a Triangle");
    System.out.print("Enter the radius of the circle ==> ");
    Also, your print statements do not make sense.

  7. #7
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    For "height", make it another parameter, so the user types in 2 doubles

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by ra4king View Post
    For "height", make it another parameter, so the user types in 2 doubles
    Really? Do we have to spell it out for them? How about expecting them to think for themselves. They should be able to work it out for themselves from my nudge.

  9. #9
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. GPS programming =)
    By santa in forum New To Java
    Replies: 6
    Last Post: 01-23-2011, 06:06 PM
  2. New to Programming!!HW Help!
    By Bgreen7887 in forum New To Java
    Replies: 13
    Last Post: 10-16-2010, 02:43 AM
  3. new to programming need help with something
    By surg3y3 in forum New To Java
    Replies: 4
    Last Post: 01-26-2010, 03:13 AM
  4. New to Programming . . .Need Help
    By DSutta22 in forum New To Java
    Replies: 2
    Last Post: 09-10-2008, 05:19 AM
  5. programming
    By abcdefg in forum New To Java
    Replies: 9
    Last Post: 03-10-2008, 10:34 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
  •