Assignment Problem:

Spoiler

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 ); } }

import java.util.Scanner; class GeometryTester { 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"); } }

This post has been edited by **weemanpow3**: 01 March 2010 - 05:11 PM