You must write one Main class containing a main method . For each question, exce
ID: 670822 • Letter: Y
Question
You must write one Main class containing a main method. For each question, except the last, you must write another method in your Main class. Your main method must show each of your others methods running on some sensible example values. Comment your methods appropriately.
Submit your code, together with the results of running it on sensible example values. ( Java)
Write a method that takes 8 doubles as arguments, x1, y1, x2, y2, x3, y3, x4, y4, being the corner points of a rectangle (given clockwise starting from the top left corner), and returns the area (as a double) of that rectangle. ( JAVA)
Explanation / Answer
class Rectangle{
public static double area(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
double length = Math.sqrt(Math.pow(x2 - x1,2) + Math.pow(y2 - y1,2));
double width = Math.sqrt(Math.pow(x3 - x2,2) + Math.pow(y3 - y2,2));
return length*width;
}
public static void main(String args[]){
Scanner in = new Scanner(System.in);
double x1 = in.nextDouble();
double y1 = in.nextDouble();
double x2 = in.nextDouble();
double y2 = in.nextDouble();
double x3 = in.nextDouble();
double y3 = in.nextDouble();
double x4 = in.nextDouble();
double y4 = in.nextDouble();
System.out.println("Area of rectangle is "+area(x1,y1,x2,y2,x3,y3,x4,y4));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.