PLANE SHAPES AREA AND PERIMETER CALCULATOR

 import java.util.Scanner;

public class AREA_CALCULATOR{
public static void main(String[] args) {
Scanner Hafiz = new Scanner(System.in);
System.out.println("WELCOME TO HAFIZ'S AREA CALCULATOR\nPRESS 1 FOR TRIANGLE\nPRESS 2 FOR CIRCLE");
System.out.println("PRESS 3 FOR RECTANGLE");
System.out.println("PRESS 4 FOR KITE");
System.out.println("PRESS 5 FOR TRAPEZIUM");
System.out.println("PRESS 6 FOR SQUARE");
System.out.println("PRESS 7 FOR RHOMBUS");
System.out.println("PRESS 8 FOR PARALLELOGRAM");

System.out.print("CHOOSE A SHAPE(1-8): ");
int choice = Hafiz.nextInt();

if (choice == 1) {
System.out.println("WELCOME TO THE TRIANGLE SECTION");
System.out.print("Enter (1) for Area , (2) for the Perimeter and (3) for both Area and Perimeter: ");
int haz = Hafiz.nextInt();
if(haz == 1){
System.out.print("Enter the base of the triangle: ");
float base = Hafiz.nextFloat();
System.out.print("Enter the height of the triangle: ");
float height = Hafiz.nextFloat();
float area = ((base * height) / 2);
System.out.print("The area of the Triangle is:" + area);
System.exit(1);
}
else if(haz == 2) {
System.out.print("Enter the base of the triangle: ");
float base = Hafiz.nextFloat();
System.out.print("Enter the height of the triangle: ");
float height = Hafiz.nextFloat();
float perimeter = (base + height);
System.out.print("The perimeter of the Triangle is:" + perimeter);
System.exit(1);
}
else if(haz == 3){
System.out.print("Enter the base of the triangle: ");
float base = Hafiz.nextFloat();
System.out.print("Enter the height of the triangle: ");
float height = Hafiz.nextFloat();
float area = ((base * height) / 2);
float perimeter = (base + height);
System.out.println("The area of the Triangle is: " + area);
System.out.println("The perimeter of the Triangle is: " + perimeter);
}
else{
System.out.println("OUT OF RANGE");
System.exit(1);
}
/* if(base || height == 0){
System.out.println("Invalid input");
}*/
} else if (choice == 2) {
System.out.println("WELCOME TO THE CIRCLE SECTION");
System.out.print("Enter 1 for the area, 2 for the Perimeter and 3 for both the area and perimeter of the circle: ");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the Radius of the Circle: ");
float Radius = Hafiz.nextFloat();
float Circle_Area = (Radius * Radius);
System.out.print("The area of the Circle is: " + Circle_Area);
}
else if(Haz == 2){
System.out.print("Enter the Radius of the Circle: ");
float Radius = Hafiz.nextFloat();
double perimeter = (2 * 3.1416 * Radius);
System.out.print("The perimeter of the Circle is: " + perimeter);
}
else if(Haz == 3){
System.out.print("Enter the Radius of the Circle: ");
float Radius = Hafiz.nextFloat();
float Circle_Area = (Radius * Radius);
double perimeter = (2 * 3.1416 * Radius);
System.out.println("The area of the Circle is: " + Circle_Area);
System.out.println("The perimeter of the Circle is: " + perimeter);
}
else{
System.out.println("OUT OF RANGE");
System.exit(1);
}
} else if (choice == 3) {
System.out.println("WELCOME TO THE RECTANGLE SECTION");
System.out.print("Enter 1 for the Area, 2 for the Perimeter and 3 for both the Area and Perimeter: ");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the Length of the Rectangle: ");
float Length = Hafiz.nextFloat();
System.out.print("Enter the Width of the Rectangle: ");
float width = Hafiz.nextFloat();
float area = (Length * width);
System.out.print("The area of the Rectangle is: " + area);
}
else if(Haz == 2){
System.out.print("Enter the Length of the Rectangle: ");
float Length = Hafiz.nextFloat();
System.out.print("Enter the Width of the Rectangle: ");
float width = Hafiz.nextFloat();
float perimeter = (2 * (Length + width));
System.out.print("The Perimeter of the Rectangle is: " + perimeter);
}
else if(Haz == 3){
System.out.print("Enter the Length of the Rectangle: ");
float Length = Hafiz.nextFloat();
System.out.print("Enter the Width of the Rectangle: ");
float width = Hafiz.nextFloat();
float perimeter = (2 * (Length + width));
float area = (Length * width);
System.out.println("The area of the Rectangle is: " + area);
System.out.println("The Perimeter of the Rectangle is: " + perimeter);}
else{
System.out.println("OUT OF RANGE");
System.exit(1);
}
} else if (choice == 4) {
System.out.println("WELCOME TO THE KITE SECTION");
System.out.print("Press 1 for the Area, 2 for the Perimeter and 3 for both the Area and Perimeter: ");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the Length of the first diagonal: ");
float d1 = Hafiz.nextFloat();
System.out.print("Enter the Length of the second diagonal: ");
float d2 = Hafiz.nextFloat();
float area = ((d1 * d2) / 2);
System.out.print("The area of the Kite is: " + area);
}
else if(Haz == 2){
System.out.print("Enter the Length of the first diagonal: ");
float d1 = Hafiz.nextFloat();
System.out.print("Enter the Length of the second diagonal: ");
float d2 = Hafiz.nextFloat();
float perimeter = ((d1 + d2) * 2);
System.out.print("The perimeter of the kite is:" + perimeter);
}
else if (Haz == 3) {
System.out.print("Enter the Length of the first diagonal: ");
float d1 = Hafiz.nextFloat();
System.out.print("Enter the Length of the second diagonal: ");
float d2 = Hafiz.nextFloat();
float area = ((d1 * d2) / 2);
float perimeter = ((d1 + d2) * 2);
System.out.println("The area of the Kite is: " + area);
System.out.println("The perimeter of the kite is:" + perimeter);
}
else{
System.out.print("OUT OF RANGE");
System.exit(1);
}
} else if (choice == 5) {
System.out.println("WELCOME TO THE TRAPEZIUM SECTION");
System.out.print("Enter 1 for the Area, 2 for the Perimeter and 3 for both");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the length of the first parallel side: ");
float b1 = Hafiz.nextFloat();
System.out.print("Enter the length of the second parallel side: ");
float b2 = Hafiz.nextFloat();
System.out.print("Enter the height (The height is the perpendicular distance between the parallel sides: ");
float height = Hafiz.nextFloat();
float parallel_side = ((b1 + b2) * height);
float area = (parallel_side / 2);
System.out.print("The area of the Trapezium is: " + area);
}
else if(Haz == 2){
System.out.print("Enter the length of the first parallel side: ");
float b1 = Hafiz.nextFloat();
System.out.print("Enter the length of the second parallel side: ");
float b2 = Hafiz.nextFloat();
System.out.print("Enter the height (The height is the perpendicular distance between the parallel sides: ");
float height = Hafiz.nextFloat();
float parallel_side = ((b1 + b2) * height);
//float perimeter = ()
//System.out.println("The perimeter of the Trapezium is: " + );
}
else if(Haz == 3) {
System.out.print("Enter the length of the first parallel side: ");
float b1 = Hafiz.nextFloat();
System.out.print("Enter the length of the second parallel side: ");
float b2 = Hafiz.nextFloat();
System.out.print("Enter the height (The height is the perpendicular distance between the parallel sides: ");
float height = Hafiz.nextFloat();
float parallel_side = ((b1 + b2) * height);
float area = (parallel_side / 2);
//float perimeter = ()
System.out.print("The area of the Trapezium is: " + area);
//System.out.println("The perimeter of the Trapezium is: " + );
}
else{
System.out.println("OUT OF RANGE");
System.exit(1);
}
}
else if (choice == 6) {
System.out.println("WELCOME TO THE SQUARE SECTION");
System.out.print("Press 1 for the Area, 2 for the Perimeter and 3 for both:");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the length of the sides: ");
float Side = Hafiz.nextFloat();
float area = (Side * Side);
float perimeter = (4 * Side);
System.out.print("The area of the square is: " + area);
}
else if(Haz == 2){
System.out.print("Enter the length of the sides: ");
float Side = Hafiz.nextFloat();
float area = (Side * Side);
float perimeter = (4 * Side);
System.out.print("The perimeter of the Square is: " + perimeter);
}
else if(Haz == 3){
System.out.print("Enter the length of the sides: ");
float Side = Hafiz.nextFloat();
float area = (Side * Side);
float perimeter = (4 * Side);
System.out.println("The area of the square is: " + area);
System.out.println("The perimeter of the Square is: " + perimeter);}
else{
System.out.println("OUT OF RANGE");
System.exit(1);
}
}
else if (choice == 7){
System.out.println("WELCOME TO THE RHOMBUS SECTION");
System.out.print("Press 1 for Area, 2 for Perimeter, 3 for both:");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the length of the first diagonal: ");
float d1 = Hafiz.nextFloat();
System.out.print("Enter the length of the second diagonal: ");
float d2 = Hafiz.nextFloat();
float area = ((d1 * d2) / 2);
System.out.print("The area of the RHOMBUS is: " + area);
}
else if(Haz == 2){
System.out.print("Enter the length of the first diagonal: ");
float d1 = Hafiz.nextFloat();
System.out.print("Enter the length of the second diagonal: ");
float d2 = Hafiz.nextFloat();
float perimeter = ((d1 + d2) * 2);
System.out.print("The Perimeter of the Rhombus is: " + perimeter);
}
else if(Haz == 3){
System.out.print("Enter the length of the first diagonal: ");
float d1 = Hafiz.nextFloat();
System.out.print("Enter the length of the second diagonal: ");
float d2 = Hafiz.nextFloat();
float area = ((d1 * d2) / 2);
float perimeter = ((d1 + d2) * 2);
System.out.println("The area of the Rhombus is: " + area);
System.out.println("The perimeter of the Rhombus is: " + perimeter);
}
else{
System.out.println("OUT OF RANGE");
System.exit(1);
}

} else if (choice == 8){
System.out.println("WELCOME TO THE PARALLELOGRAM SECTION");
System.out.print("Press 1 for Area, 2 for Perimeter and 3 for both:");
int Haz = Hafiz.nextInt();
if(Haz == 1){
System.out.print("Enter the base : ");
float base = Hafiz.nextFloat();
System.out.print("Enter the height: ");
float height = Hafiz.nextFloat();
float area = (base * height);
System.out.print("The area of the parallelogram is: " + area);
}
else if(Haz == 2){
System.out.print("Enter the base : ");
float base = Hafiz.nextFloat();
System.out.print("Enter the height: ");
float height = Hafiz.nextFloat();
float perimeter = ((base + height) * 2);
System.out.print("The Perimeter of the Parallelogram is: " + perimeter);
}
else if(Haz == 3){
System.out.print("Enter the base : ");
float base = Hafiz.nextFloat();
System.out.print("Enter the height: ");
float height = Hafiz.nextFloat();
float area = (base * height);
float perimeter = ((base + height) * 2);
System.out.println("The area of the parallelogram is: " + area);
System.out.println("The Perimeter of the Parallelogram is: " + perimeter);
}
else {
System.out.println("OUT OF RANGE");
}

}
else{
System.out.println("OUT OF RANGE");
}

}
}

Submitted By:
Mohamed Alpha Kamara
B. Sc. Information Technology
I - 24 - 64179

Comments

Popular posts from this blog

COMPUTER PROGRAMMING(DIT 111) ASSIGNMENT

TILE ESTIMATOR

MY IPAM GRADING SYSTEM PROGRAM