Assig3 FA2017 [Compatibility Mode Home Insert Design Layout References Mailings
ID: 3586092 • Letter: A
Question
Assig3 FA2017 [Compatibility Mode Home Insert Design Layout References Mailings Review View Share AasbCcDdEc Aa Paste Heading 1 Heading 2 Styles Pane Test name Tips for us. Assignment 3 oOPS (ITBP319_FA17) (In Class Assignment) Point PotNT : Y COoRD - Create a class called Point which takes X and Y coordinates Create a class called Triangle that wil take three points which will be the corners o P1 (5,5) o P2 12,11 o P3 (7,1) ASSIGNMENT: Create method inside the Triangle class that determines the type of the Triangle's sides · Equilateral Isceles Scalene 3 of 60 WordsEnglish (US) Focus 130%Explanation / Answer
// please find the code below
import java.util.Scanner;
class Point {
int X;
int Y;
public Point(int x, int y){
X = x;
Y = y;
}
}
class Triangle {
Point P1;
Point P2;
Point P3;
public Triangle(int x1, int y1,int x2, int y2,int x3, int y3) {
P1 = new Point(x1, y1);
P2 = new Point(x2, y2);
P3 = new Point(x3, y3);
}
String getTriangleType(){
// Comparing squares of length as it is easy to compar that way
// if squares of side length are equal then length is also equal
int l1, l2, l3;
l1 = getSideLengthSquare(P1, P2);
l2 = getSideLengthSquare(P2, P3);
l3 = getSideLengthSquare(P3, P1);
if(l1 == l2 && l1 == l3){
return "Equilateral";
} else if(l1 == l2 || l1 == l3 || l2 == l3){
return "Isosceles";
} else{
return "Scalene";
}
}
int getSideLengthSquare(Point p1, Point p2){
return ((p2.X - p1.X) * (p2.X - p1.X)) + ((p2.Y - p1.Y) * (p2.Y - p1.Y)) ;
}
}
public class Main1 {
public static void main(String[] args) {
System.out.println("Please Enter coordinates of traingle ");
Scanner in = new Scanner(System.in);
System.out.println("Please Enter First cordinate x,y ");
int x1 = in.nextInt();
int y1 = in.nextInt();
System.out.println("Please Enter Second cordinate x,y ");
int x2 = in.nextInt();
int y2 = in.nextInt();
System.out.println("Please Enter third cordinate x,y ");
int x3 = in.nextInt();
int y3 = in.nextInt();
Triangle triangle = new Triangle(x1, y1, x2, y2, x3, y3);
System.out.println(triangle.getTriangleType());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.