Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /*******************************************
- * Author: Ryan Forster 19145178 *
- * Purpose: To calculate the area of shapes *
- * Date: 15/03/2018 *
- *******************************************/
- public class ShapeCalculator
- {
- public static void main( String [] args)
- {
- circleCalc();
- rectangleCalc();
- triangleCalc();
- }
- public static void circleCalc()
- {
- int circDiameter;
- double area;
- circDiameter = inputInteger("Enter diameter");
- area = calcCircArea(circDiameter);
- getDimensions(area);
- }
- public static void rectangleCalc()
- {
- double recLength, recWidth;
- recLength = inputReal("Enter length");
- recWidth = inputReal("Enter width");
- area = calcRecArea(recLength, recWidth);
- getDimensions(area);
- }
- public static void triangleCalc()
- {
- double triBase, triHeight;
- triBase = inputReal("Enter base");
- triHeight = inputReal("Enter height");
- area = calcTriArea(triBase, triHeight);
- getDimensions(area);
- }
- public static double calcCircArea(int circDiameter)
- {
- double radius, circSum, circArea;
- radius = (double)circDiameter / 2;
- circSum = radius * radius;
- circArea = circSum * Math.PI;
- return circArea;
- }
- public static double calcRecArea(double recLength, double recWidth)
- {
- double recArea;
- recArea = recLength * recWidth;
- return recArea;
- }
- public static double calcTriArea(double triBase, double triHeight)
- {
- double triArea;
- triArea = triBase * triHeight / 2;
- triArea = triArea / 100;
- return triArea;
- }
- public static void getDimensions(double area)
- {
- int getM, getCM;
- double getMM;
- getMM = (area - (int)area) * 100;
- getM = (int)area / 10000;
- getCM = (int)area - getM * 10000;
- System.out.println("The area of your shape is " + getM + "m^2 " + getCM + "cm^2 " + getMM + "mm^2");
- }
- public static int inputInteger(String msg);
- {
- int output;
- output = sc.nextInt();
- System.out.println(msg);
- return output;
- }
- public static double inputReal(String msg);
- {
- double output;
- output = sc.nextDouble();
- System.out.printlm(msg);
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement