Questions
I need to update this program to follow the these requirements please and thank you :...

I need to update this program to follow the these requirements please and thank you :

Do not use packages

Every class but the main routine class must have a toString method . The toString method for Quadrilateral should display its fields: 4 Points.

All instance variables should be declared explicitly private .

Area incorrect : enter points no: 1 1 3 enter points no: 2 6 3 enter points no: 3 0 0 enter points no: 4 5 0 This is a Parallelogram Area is : 15.811

Type of quadrilateral incorrect : enter points no: 1 5 4 enter points no: 2 5 0 enter points no: 3 0 4 enter points no: 4 0 0 This is a Parallelogram Area is : 20.000

The assignment question is :

Write an inheritance hierarchy for the classes Quadrilateral (an abstract class), Trapezoid, Parallelogram, Rectangle, and Square and then code it up. Create and use a Point class that has instance variables: x-coordinate and y-coordinate (each quadrilateral will have 4 of these, declared in the Quadrilateral class as protected). Each class must be defined in a separate .java file.Write one or more constructors, get and set methods for each class, and another method that computes the area of the object of each class (except for Point and Quadrilateral). For simplicity require that one side of any CMPSC Assignments4quadrilateral lie along the x-axis, and any figure with parallel sides will have a parallel side lying along the x-axis; do NOT assume that the points have to entered in any particular order; reject any input that fails to meet these conditions. Test all of these methods.In a separate class write a main function that prompts the user for the 4 points. Hence there will be 7 classes: Point, Quadrilateral (abstract), Trapezoid, Parallelogram, Rectangle, Square, and a Driver (with the main routine).Extra credit: enhance the above to remove the simplifying requirement (NOT trivial!).

The program :

////// MAIN CLASS ////

package main;


import java.util.Scanner;

public class Main {

static double distSq(Point p, Point q)
{
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
  
//Check whether for points forms rectangle or not.
static boolean isRectangle(Point p1, Point p2, Point p3, Point p4) {
  
double d1 = distSq(p1, p2); // from p1 to p2
double d2 = distSq(p2, p3); // from p2 to p3
double d3 = distSq(p3, p4); // from p3 to p4
double d4 = distSq(p4, p1); // from p4 to p1
  
//Diagonal dist
double d5 = distSq(p1,p3);
  
//d5==d1+d2 ,then it divides the points into two right angle triangle .Hence it is a rectangle
if(d5==d1+d2) {
return true;
}else {
return false;
}

}
// This function returns true if (p1, p2, p3, p4) form a
// square, otherwise false
static boolean isSquare(Point p1, Point p2, Point p3, Point p4)
{
double d2 = distSq(p1, p2); // from p1 to p2
double d3 = distSq(p1, p3); // from p1 to p3
double d4 = distSq(p1, p4); // from p1 to p4
  
// If lengths if (p1, p2) and (p1, p3) are same, then
// following conditions must met to form a square.
// 1) Square of length of (p1, p4) is same as twice
// the square of (p1, p2)
// 2) Square of length of (p2, p3) is same
// as twice the square of (p2, p4)
  
if (d2 == d3 && 2 * d2 == d4
&& 2 * distSq(p2, p4) == distSq(p2, p3)) {
return true;
}
  
// The below two cases are similar to above case
if (d3 == d4 && 2 * d3 == d2
&& 2 * distSq(p3, p2) == distSq(p3, p4)) {
return true;
}
if (d2 == d4 && 2 * d2 == d3
&& 2 * distSq(p2, p3) == distSq(p2, p4)) {
return true;
}
  
return false;
}
  
static boolean isParallelogram(Point p1, Point p2, Point p3, Point p4){
//To determine this first we calculate slope
double a = slope(p1,p2);
double b = slope(p3,p4);
double c = slope(p1,p4);
double d = slope(p2,p3);
  
double g = slope(p1,p3);
double h = slope(p2,p4);
  
  
  
//Test for parallelogram
if(a==b && (c==d || g==h)) {
return true;
}
return false;
}
  
static boolean isTrapezoid(Point p1, Point p2, Point p3, Point p4){
//To determine this first we calculate slope
double a = slope(p1,p2);
double b = slope(p3,p4);
double c = slope(p1,p4);
double d = slope(p2,p3);
  
//Test for parallelogram
if(a==b || c==d) {
return true;
}
return false;
}
  
static private double slope(Point p1, Point p2) {
// TODO Auto-generated method stub
return (p2.y-p1.y)/(p2.x-p1.x);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Point[] arr = new Point[4] ;
Scanner sc = new Scanner(System.in);
for(int i=0;i<4;i++) {
System.out.printf("%s%n","enter points no: "+(i+1));
double first = sc.nextDouble();
double second = sc.nextDouble();
arr[i] = new Point(first,second);
}
  
if(isSquare(arr[0],arr[1],arr[2],arr[3])) {
  
System.out.printf("%s%n","This is a Square");
Square s = new Square(arr[0],arr[1],arr[2],arr[3]);
System.out.printf("Area is : %5.3f%n",s.area());
  
}
else if(isRectangle(arr[0],arr[1],arr[2],arr[3])) {
  
System.out.printf("%s%n","This is a Rectangle");
Rectangle r = new Rectangle(arr[0],arr[1],arr[2],arr[3]);
System.out.printf("Area is : %5.3f%n",r.area());
  
  
}
else if(isParallelogram(arr[0],arr[1],arr[2],arr[3])) {
  
System.out.printf("%s%n","This is a Parallelogram");
Parallelogram p = new Parallelogram(arr[0],arr[1],arr[2],arr[3]);
System.out.printf("Area is : %5.3f%n",p.area());

}else if(isTrapezoid(arr[0],arr[1],arr[2],arr[3])) {
System.out.printf("%s%n","This is a Trapezoid");
Trapezoid t = new Trapezoid(arr[0],arr[1],arr[2],arr[3]);
System.out.printf("Area is : %5.3f%n",t.area());
  
  
}else {
System.out.printf("%s%n","Invalid Inputs");
}
  
  
}

}

//////////////////class Parallelogram//////////////

package main;


class Parallelogram extends Quadrilateral{
Point p1;
Point p2;
Point p3;
Point p4;

public Parallelogram(Point point, Point point2, Point point3, Point point4) {
// TODO Auto-generated constructor stub
this.p1=point;
this.p2=point2;
this.p3=point3;
this.p4=point4;
}
  
double distSq(Point p, Point q)
{
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}

@Override
double area() {
// TODO Auto-generated method stub
double side = Math.sqrt(distSq(p1,p2));
double side2 = Math.sqrt(distSq(p1,p3));
return side*side2;
}

}

//////////////////class Point//////////////

package main;


public class Point {
// x represents x axis value and y represents y axis value
double x;
double y;
//Constructor to initialize data members
Point(double x, double y){ this.x=x; this.y=y; } }

//////////////////class Quadrilateral//////////////

package main;


abstract class Quadrilateral { abstract double area(); }

//////////////////class Rectangle//////////////

package main;


class Rectangle extends Quadrilateral{

Point p1;
Point p2;
Point p3;
Point p4;
  
public Rectangle(Point point, Point point2, Point point3, Point point4) {
// TODO Auto-generated constructor stub
this.p1=point;
this.p2=point2;
this.p3=point3;
this.p4=point4;
}

double distSq(Point p, Point q)
{
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
  
@Override
double area() {
// TODO Auto-generated method stub
double side = Math.sqrt(distSq(p1,p2));
double side2 = Math.sqrt(distSq(p1,p3));
return side*side2;
}

}

//////////////////class Square//////////////

package main;


public class Square extends Quadrilateral{

//Data members
Point p1;
Point p2;
Point p3;
Point p4;

//Constructor

Square(Point p1, Point p2, Point p3, Point p4){
this.p1=p1;
this.p2=p2;
this.p3=p3;
this.p4=p4;

}
  
double distSq(Point p, Point q)
{
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
  
  
@Override
double area() {
// TODO Auto-generated method stub
double d1 = Math.sqrt(distSq(p1, p2)); // from p1 to p2
double d2 = Math.sqrt(distSq(p3, p4)); // from p1 to p3
  
return d1*d2;

}

}

////////////////////////////////Trapezoid///////////////

package main;

class Trapezoid extends Quadrilateral{


Point p1;
Point p2;
Point p3;
Point p4;
  
public Trapezoid(Point point, Point point2, Point point3, Point point4) {
// TODO Auto-generated constructor stub
this.p1=point;
this.p2=point2;
this.p3=point3;
this.p4=point4;
}

double distSq(Point p, Point q)
{
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
  
@Override
double area() {
// TODO Auto-generated method stub

return 0.5*Math.abs((p1.x*(p2.y-p3.y)+p2.x*(p3.y-p1.y)+p3.x*(p1.y-p2.y))) + 0.5*Math.abs((p1.x*(p3.y-p4.y)+p3.x*(p4.y-p1.y)+p4.x*(p1.y-p3.y)));
}

}

In: Computer Science

Describe some of the problems that might arise from a failure to maintain and update an...

Describe some of the problems that might arise from a failure to maintain and update an existing Chart of Accounts. Discuss in 100–120 words.

In: Accounting

I only need to update this JAVA program to be able to : 1 ) Exit...

I only need to update this JAVA program to be able to :

1 ) Exit cleanly after creating the chart

2 ) change the pie chart to a perfect circle rather than an oval

3 ) provide a separate class driver

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.Scanner;

import javax.swing.JComponent;
import javax.swing.JFrame;

// class to store the value and color mapping of the
// pie segment(slices)
class Segment {
double value;
Color color;

// constructor
public Segment(double value, Color color) {
this.value = value;
this.color = color;
}
}

class pieChartComponent extends JComponent {

private static final long serialVersionUID = 1L;
Segment[] Segments;

// Parameterized constructor
// create 4 segments of the pie chart
pieChartComponent(int v1, int v2, int v3, int v4) {
Segments = new Segment[] { new Segment(v1, Color.black), new Segment(v2, Color.green), new Segment(v3, Color.yellow),
new Segment(v4, Color.red) };
}

// function responsible for calling the worker method drawPie
public void paint(Graphics g) {
drawPie((Graphics2D) g, getBounds(), Segments);
}

// worker function for creating the percentage wise slices of the pie chart
  
void drawPie(Graphics2D g, Rectangle area, Segment[] Segments) {
double total = 0.0D;
// fin the total of the all the inputs provided by the user
for (int i = 0; i < Segments.length; i++) {
total += Segments[i].value;
}
  
// Initialization
double curValue = 0.0D;
int strtAngle = 0;
// iterate till all the segments are covered
for (int i = 0; i < Segments.length; i++) {
// compute start angle, with percentage
strtAngle = (int) (curValue * 360 / total);
// find the area angle of the segment
int arcAngle = (int) (Segments[i].value * 360 / total);

g.setColor(Segments[i].color);
g.fillArc(area.x, area.y, area.width, area.height, strtAngle, arcAngle);
curValue += Segments[i].value;
}
}
}

public class Graphic_Pie2D {
public static void main(String[] argv) {

System.out.println("Pleae provide 4 values, to create the pie chart");
Scanner input = new Scanner(System.in);
int v1, v2, v3, v4;
v1 = input.nextInt();
v2 = input.nextInt();
v3 = input.nextInt();
v4 = input.nextInt();
  
// create a JFrame with title
JFrame frame = new JFrame("Pie Chart");
frame.getContentPane().add(new pieChartComponent(v1,v2,v3,v4));
frame.setSize(500, 300);
frame.setVisible(true);

}
}

here's the assignment for reference :

Pie chart: prompt the user (at the command line) for 4 positive integers, then draw a pie chart in a window. Convert the numbers to percentages of the numbers’ total sum; color each segment differently; use Arc2D. No text fields (other than the window title) are required. Provide a driver in a separate source file to test your class.

In: Computer Science

Companies have to update their strategy on a regular basis but sometimes need to look at...

Companies have to update their strategy on a regular basis but sometimes need to look at radical change, briefly explain these two types of Strategic Change and how they might affect company organization. Define incremental and transformational change.

In: Operations Management

What does the term filtering mean in the context of a database?

What does the term filtering mean in the context of a database?

In: Operations Management

Identify 5 benefits of using a Database management systems

Identify 5 benefits of using a Database management systems

In: Mechanical Engineering

how do you access the icf crosswalk database?

how do you access the icf crosswalk database?

In: Nursing

Decide whether each pair of elements in the table below will form an ionic compound. If they will, write the empirical formula of the compound formed in the space provided.


Decide whether each pair of elements in the table below will form an ionic compound. If they will, write the empirical formula of the compound formed in the space provided.

image.png


In: Chemistry

Explain the spillover benefits that are purported to flow from the athletic department to the university.

Explain the spillover benefits that are purported to flow from the athletic department to the university. What does empirical research indicate about these spillover benefits?

In: Economics

Which of the following types of articles would NOT be included in an embedded review of...

Which of the following types of articles would NOT be included in an embedded review of literature?

Theory articles.

Methodological articles.

Opinion articles.

Empirical findings.

In: Nursing