Assignment 97; ShapeCalc
Code
// Donovan Rich
// Period 6
// Area Calculator
// ShapeCalc.java
// 3/28/2016
import java.util.Scanner;
public class ShapeCalc
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int choice;
double s1, s2;
System.out.println();
System.out.println( "\nShapeCal BETA BUILD v2.13" );
System.out.println();
do
{
System.out.println();
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( "Desired shape: " );
choice = keyboard.nextInt();
if ( choice == 1 )
{
System.out.println();
System.out.print( "Base: " );
s1 = keyboard.nextDouble();
System.out.print( "\nHeight: " );
s2 = keyboard.nextDouble();
System.out.println( "The area is " + calcTriangle( s1, s2 ) );
}
else if ( choice == 2 )
{
System.out.println();
System.out.print( "Length: " );
s1 = keyboard.nextDouble();
System.out.print( "\nWidth: " );
s2 = keyboard.nextDouble();
System.out.println( "The area is " + calcRectangle( s1, s2 ) );
}
else if ( choice == 3 )
{
System.out.println();
System.out.print( "Side: " );
s1 = keyboard.nextDouble();
System.out.println( "The area is " + calcSquare( s1 ) );
}
else if ( choice == 4 )
{
System.out.println();
System.out.print( "Radius: " );
s1 = keyboard.nextDouble();
System.out.println( "The area is " + calcCircle( s1 ) );
}
else if ( choice == 5 )
{
System.out.println();
System.out.print( "Thank you for using ShapeCal BETA BUILD v2.13!\n" );
}
else
{
System.out.println();
System.out.print( "Unrecognized shape number. Please retry input." );
}
} while ( choice != 5 );
}
public static double calcTriangle( double s1, double s2 )
{
double result;
result = (s1*s2)/2;
return result;
}
public static double calcRectangle( double s1, double s2 )
{
double result;
result = (s1*s2);
return result;
}
public static double calcSquare( double s1 )
{
double result;
result = (s1*s1);
return result;
}
public static double calcCircle( double s1 )
{
double result;
result = (s1*s1)*Math.PI;
return result;
}
}
Picture of the output