Assignment # 97 and AreaCalc
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: AreaCalc
/// File Name: AreaCalc.java
/// Date: 3/30/2016
import java.util.Scanner;
public class AreaCalc
{
static Scanner keyboard = new Scanner(System.in);
public static void main( String[] args )
{
System.out.println("Tommy's Area Calculator v0.1 (c) 2015 TIS Indie Games\n\n");
String read = "";
float finalArea,n1,n2 = 0;
do
{
finalArea = 0;
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
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("What do you choose?: ");
read = keyboard.next();
System.out.println();
{
switch (read)
{
case "1":
System.out.print("Base: ");
n1 = keyboard.nextFloat();
System.out.print("Height: ");
n2 = keyboard.nextFloat();
finalArea = triangleArea(n1,n2);
break;
case "2":
System.out.print("Length: ");
n1 = keyboard.nextFloat();
System.out.print("Width: ");
n2 = keyboard.nextFloat();
finalArea = rectangleArea(n1,n2);
break;
case "3":
System.out.print("Side: ");
n1 = keyboard.nextFloat();
finalArea = squareArea(n1);
break;
case "4":
System.out.print("Radius: ");
n1 = keyboard.nextFloat();
finalArea = circleArea(n1);
break;
case "5":
break;
default:
read = "error";
}
}
if (!read.equals("error") && !read.equals("5")) System.out.println("\nThe area is "+finalArea+".\n");
if (read.equals("error")) System.out.println("WRONG INPUT, TRY AGAIN!!!");
}
while (!read.equals("5"));
System.out.println("\nGoodbye!");
}
static float triangleArea(float b,float h)
{
return b*h*.5f;
}
static float rectangleArea(float l,float w) {return l*w;}
static float squareArea(float s)
{
return s*s;
}
static float circleArea(float r)
{
return r*r*(float)Math.PI;
}
}
Picture of the output