Assignment #97 AreaCalculator
Code
/// Name: Lacey Reese
/// Period: 5
/// Program Name: AreaCalculator
/// File Name: AreaCalculator.java
/// Date Finished 3/23/2016
import java.util.Scanner;
public class AreaCalculator
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println( "Want to find the area of a shape? Come here ! GO MATH!" );
System.out.println();
int choice = 1;
while ( choice != 5 ) {
System.out.println( "Please choose a shape: Number" );
System.out.println( "---------------------------------" );
System.out.println();
System.out.println( "1. Circle" );
System.out.println( "2. Rectangle" );
System.out.println( "3. Square" );
System.out.println( "4. Triangle" );
System.out.println( "5. Quit" );
System.out.println();
System.out.print( "Shape: " );
choice = keyboard.nextInt();
System.out.println();
if ( choice == 1 ) {
System.out.print( "Radius: " );
int radius = keyboard.nextInt();
System.out.println();
System.out.println( "The area is " + areaCircle( radius ) );
}
if ( choice == 2 ) {
System.out.print( "Length: " );
int length = keyboard.nextInt();
System.out.println();
System.out.print( "Width: " );
int width = keyboard.nextInt();
System.out.println();
System.out.println( "The area is " + areaRectangle( length, width ) );
}
if ( choice == 3 ) {
System.out.print( "Side Length: " );
int side = keyboard.nextInt();
System.out.println();
System.out.println( "The area is " + areaSquare( side ) );
}
if ( choice == 4 ) {
System.out.print( "Base: " );
int base = keyboard.nextInt();
System.out.println();
System.out.print( "Height: " );
int height = keyboard.nextInt();
System.out.println();
System.out.println( "The area is " + areaTriangle( base, height ) );
}
if ( choice == 5 ) {
System.out.println( "Goodybe" );
}
}
}
public static double areaCircle( int radius ) {
double carea = Math.PI * radius * radius;
return carea;
}
public static int areaRectangle( int length, int width ) {
int rarea = length * width;
return rarea;
}
public static int areaSquare( int side ) {
int sarea = side * side;
return sarea;
}
public static double areaTriangle ( int base, int height ) {
double tarea = base * height * 0.5;
return tarea;
}
}
Picture of the output