What is Area in Mathematical ?
Area is the size and amount of two-dimensional space taken up by an object.Like Square , Equilateral Triangle , Circle , Rectangle, Parallelogram , Triangle , Ellipse and Trapezoid.
Function
public static int square(int var) { return (var * var); } public static int equilateral_triangle(int side) { side = side * side; return (int)(side * 0.43); } public static int circle(int radius) { return (int)((radius * radius)*3.14); } public static int rectangle(int vala, int valb) { return vala * valb; } public static int parallelogram(int base, int height) { return base * height; } public static int triangle(int base, int height) { return (int)((0.5 * base) * height); } public static int ellipse(int radius1, int radius2) { return (int)((radius1 * radius2)*3.14); } public static int trapezoid(int height, int base1, int base2) { return ((base1 + base2) / 2) * height; }
Program
//package com.ahirlab.findarea; import java.util.Scanner; public class findarea{ public static void main(String[] args) { Scanner userInput = new Scanner(System.in); int option=0; int side1 = 0; int side2 = 0; int side3 = 0; int area=0; System.out.println("\n 1.Square \n 2.Equilateral Triangle \n 3.Circle \n 4.rectangle\n 5.Parallelogram \n 6.Triangle \n 7.Ellipse \n 8.Trapezoid"); System.out.print(" Select the Option : "); option = userInput.nextInt(); switch(option){ case 1: System.out.println(" Square Area "); System.out.print(" Enter The Side Length of Square : "); side1 = userInput.nextInt(); area = square(side1); break; case 2: System.out.println(" Equilateral Triangle Area "); System.out.print(" Enter The Side Length of Triangle : "); side1 = userInput.nextInt(); area = equilateral_triangle(side1); break; case 3: System.out.println(" Circle Area "); System.out.print(" Enter The Radius of Circle : "); side1 = userInput.nextInt(); area = circle(side1); break; case 4: System.out.println(" Rectangle Area "); System.out.print(" Enter The Width of Rectangle : "); side1 = userInput.nextInt(); System.out.print(" Enter The Height of Rectangle : "); side2 = userInput.nextInt(); area = rectangle(side1,side2); break; case 5: System.out.println(" Parallelogram Area "); System.out.print(" Enter The Base Length of Parallelogram : "); side1 = userInput.nextInt(); System.out.print(" Enter The Height Length of Parallelogram : "); side2 = userInput.nextInt(); area = parallelogram(side1,side2); break; case 6: System.out.println(" Triangle Area "); System.out.print(" Enter The Base Length of Triangle : "); side1 = userInput.nextInt(); System.out.print(" Enter The Height Length of Triangle : "); side2 = userInput.nextInt(); area = triangle(side1,side2); break; case 7: System.out.println(" Ellipse Area "); System.out.print(" Enter The Radius 1 Length of Ellipse : "); side1 = userInput.nextInt(); System.out.print(" Enter The Radius 2 Length of Ellipse : "); side2 = userInput.nextInt(); area = ellipse(side1,side2); break; case 8: System.out.println(" Trapezoid Area "); System.out.print(" Enter The Height Length of Trapezoid : "); side1 = userInput.nextInt(); System.out.print(" Enter The Base 1 Length of Trapezoid : "); side2 = userInput.nextInt(); System.out.print(" Enter The Base 2 Length of Trapezoid : "); side3 = userInput.nextInt(); area = trapezoid(side1,side2,side3); break; } System.out.println(" Area is : "+area+"\n"); userInput.close(); } public static int square(int var) { return (var * var); } public static int equilateral_triangle(int side) { side = side * side; return (int)(side * 0.43); } public static int circle(int radius) { return (int)((radius * radius)*3.14); } public static int rectangle(int vala, int valb) { return vala * valb; } public static int parallelogram(int base, int height) { return base * height; } public static int triangle(int base, int height) { return (int)((0.5 * base) * height); } public static int ellipse(int radius1, int radius2) { return (int)((radius1 * radius2)*3.14); } public static int trapezoid(int height, int base1, int base2) { return ((base1 + base2) / 2) * height; } }
Output
(Visited 785 times, 1 visits today)
Written by: