Results 1 to 9 of 9
Thread: programming help!!??
 04122011, 11:55 PM #1Member
 Join Date
 Apr 2011
 Posts
 2
 Rep Power
 0
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!
 04122011, 11:58 PM #2
This forum is for Java developers not psychics. If you get error messages then how about including the EXACT messages in your post.
 04132011, 12:29 AM #3
And also, please use the code tags:
[ code] code goes right here [ /code ] without the spaces
And format with spaces (preferably 34 spaces for a tab)
 04132011, 12:37 AM #4Member
 Join Date
 Apr 2011
 Posts
 2
 Rep Power
 0
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 ); } }
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.
 04132011, 12:43 AM #5Java Code:
public static float areaRectangle(float area){
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 ); }
 04132011, 12:44 AM #6Java 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 ==> ");
 04132011, 12:58 AM #7
For "height", make it another parameter, so the user types in 2 doubles
 04132011, 01:05 AM #8
 04132011, 01:09 AM #9
Similar Threads

GPS programming =)
By santa in forum New To JavaReplies: 6Last Post: 01232011, 06:06 PM 
New to Programming!!HW Help!
By Bgreen7887 in forum New To JavaReplies: 13Last Post: 10162010, 02:43 AM 
new to programming need help with something
By surg3y3 in forum New To JavaReplies: 4Last Post: 01262010, 03:13 AM 
New to Programming . . .Need Help
By DSutta22 in forum New To JavaReplies: 2Last Post: 09102008, 05:19 AM 
programming
By abcdefg in forum New To JavaReplies: 9Last Post: 03102008, 10:34 AM
Bookmarks