Assignemnt #97 and Area Calculator
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: Area Calculator
///File Name: AreaCalculator
///Date finished: 2/29/16
import java.util.Scanner;
public class AreaCalculator
{
public static void main( String args[] )
{
Scanner keyboard = new Scanner(System.in);
int choice, baseLength, heightWidth, radius;
System.out.println( "Shape Area Calculator version 0.1 (c) 2015 Davis Inc." );
System.out.println( " " );
System.out.println( "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" );
System.out.println( " " );
choice = 0;
while( choice != 5 )
{
System.out.println( "1) Triangle" );
System.out.println( "2) Rectangle" );
System.out.println( "3) Square" );
System.out.println( "4) Circle" );
System.out.println( "5) Quit" );
System.out.print( "Which shape: " );
choice = keyboard.nextInt();
if( choice == 1 )
{
System.out.print( "Base: " );
baseLength = keyboard.nextInt();
System.out.print( "Height: " );
heightWidth = keyboard.nextInt();
System.out.println( " " );
System.out.println( "The area is " + triangle(baseLength, heightWidth) );
System.out.println( " " );
System.out.println( "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" );
}
else if( choice == 2 )
{
System.out.print( "Length: " );
baseLength = keyboard.nextInt();
System.out.print( "Width: " );
heightWidth = keyboard.nextInt();
System.out.println( " " );
System.out.println( "The area is " + rectangle(baseLength, heightWidth) );
System.out.println( " " );
System.out.println( "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" );
}
else if( choice == 3 )
{
System.out.print( "Side length: " );
baseLength = keyboard.nextInt();
System.out.println( " " );
System.out.println( "The area is " + square(baseLength) );
System.out.println( " " );
System.out.println( "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" );
}
else if( choice == 4 )
{
System.out.print( "Radius: " );
radius = keyboard.nextInt();
System.out.println( " " );
System.out.println( "The area is " + circle(radius) );
System.out.println( " " );
System.out.println( "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" );
}
}
System.out.println( "Goodbye." );
}
public static int triangle( int baseLength, int heightWidth )
{
int area;
area = baseLength * heightWidth;
area = area / 2;
return area;
}
public static int rectangle( int baseLength, int heightWidth )
{
int area;
area = baseLength * heightWidth;
return area;
}
public static int square( int baseLength )
{
int area;
area = baseLength * baseLength;
return area;
}
public static double circle( int radius )
{
double area;
area = radius * radius;
area = area * Math.PI;
return area;
}
}
Picture of the output