During the activity time grade 3 students were given four sticks and are asked to form a shape and place it on the desk. The teacher will measure one internal angle, and tell the students what shape they have formed with the given sticks. Write a program to get the input for the length of the stick and the internal angle. Based on the input, specify whether it is a square, rectangle, rhombus ,parallelogram, or irregular quadrilateral. Assume sides given as input are sq,s2,s3,s4. If s1=s2=s3=s4 and the angle is 90, the shape is square If s1=s2 and s3=s4 and the angle is 90, the shape is rectangle. If s1=s2=s3=s4 and the angle is not 90, the shape is rhombus. If s1=s2 and s3=s4 and the angle is not 90, the shape is parallelogram. If none of the above conditions are true, the shape is irregular quadrilateral. The output should be "It’s a < >"
Answers
Answer: This will help
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the four sticks in cm");
int n1=sc.nextInt();
int n2=sc.nextInt();
int n3=sc.nextInt();
int n4=sc.nextInt();
System.out.println("Enter one internal angle");
int angle=sc.nextInt();
int p=(n1*n1+n2*n2);
int q=n2*n2+n3*n3;
int r=n3*n3+n4*n4;
int s=n4*n4+n1*n1;
if(n1==n2 && n1==n3 && n1==n4){
if(angle==90){
System.out.println("It's a square");
}
else if(angle!=90){
System.out.println("It's a rhombus");
}
else{
System.out.println("It's a irregular quadrilateral");
}
}
else if(n1==n2 && n3==n4 ||n1==n3 && n4==n2){
if(angle==90){
System.out.println("It's a rectangle");
}
else if(angle!=90 && p!=q || q!=r || r!=s || s!=p){
System.out.println("It's a parallelogram");
}
else{
System.out.println("It's a irregular quadrilateral");
}
}
else{
System.out.println("It's a irregular quadrilateral");
}
}
}
Explanation: