The Ellipse2DDemo class This class will consists oftwo metho

The Ellipse2DDemo class This class will consists oftwo methods: the main and the printEllipseDetails methods. The main method does the following: 1. Prompts the user to enter the X- and Y-coordinates of the location of the ellipse and its width and height width height 2. Creates an Ellipse2D object using the user\'s input. 3. Calls the printEllipseDetails method to print all the details about this ellipse as shown in the sample run. 4. Creates a second ellipse that perfectly overlaps with the first ellipse. 5. Calls the printEllipseDetails method to print all the details about the second ellipse as shown in the sample run.

Solution

Ellipse2D.java

import java.lang.Math;
public class Ellipse2D{
    double x, y, w, h;

    public Ellipse2D(double x, double y, double w, double h){
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
    }

    public double getArea(){
        return Math.PI*w*h;
    }

    public void setWidth(double width){
        this.w = width;
    }

    public void setHeight(double height){
        this.h = height;
    }

    public double getPerimeter(){
        return 2*Math.PI*Math.sqrt((w*w + h*h)/2.0);
    }
}

Ellipse2DDemo.java

//import java.awt.geom.Ellipse2D.Double;
import java.util.Scanner;
public class Ellipse2DDemo{

    public static void printEllipseDetails(double x, double y, double w, double h, double area, double perimeter){
        System.out.printf(\"Ellipse2D[x=%.5f, y=%.5f, w=%.5f, h=%.5f]\", x, y, w, h);
        System.out.printf(\"\ location: (%.5f, %.5f)\", x, y);
        System.out.printf(\"\ width:   %.5f   height:   %.5f\", w, h);
        System.out.printf(\"\ area:    %.5f   perimeter:   %.5f\", area, perimeter);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x, y, w, h;
        double area1, perimeter1, area2, perimeter2;
        System.out.print(\"Enter the value of x: \");
        x = sc.nextDouble();
        System.out.print(\"Enter the value of y: \");
        y = sc.nextDouble();
        System.out.print(\"Enter the value of width: \");
        w = sc.nextDouble();
        System.out.print(\"Enter the value of height: \");
        h = sc.nextDouble();

        while(w<h){
            System.out.println(\"Please enter the value of width greater than height\");
            System.out.print(\"Enter the value of width: \");
            w = sc.nextDouble();
            System.out.print(\"Enter the value of height: \");
            h = sc.nextDouble();
        }

        Ellipse2D ellipse1 = new Ellipse2D(x, y, w, h);
        area1 = ellipse1.getArea();
        perimeter1 = ellipse1.getPerimeter();
        System.out.println(\"Description of the first ellipse:\");
        System.out.println(\"--------------------------------------------------------------------------------\");
        printEllipseDetails(x, y, w, h, area1, perimeter1);

        Ellipse2D ellipse2 = new Ellipse2D(x, y, w, h);
        System.out.println(\"Description of the second ellipse:\");
        System.out.println(\"--------------------------------------------------------------------------------\");
        printEllipseDetails(x, y, w, h, area1, perimeter1);

        Ellipse2D ellipse2modified = new Ellipse2D(x, y, w, h);
        ellipse2modified.setWidth(h);
        area2 = ellipse2modified.getArea();
        perimeter2 = ellipse2modified.getPerimeter();
        System.out.println(\"Description of the second ellipse after it is modified:\");
        System.out.println(\"--------------------------------------------------------------------------------\");
        printEllipseDetails(x, y, w, h, area2, perimeter2);

        double areaDifference = area1-area2;
        System.out.printf(\"\ The area between the first and second ellipses is %.5f\ \", areaDifference);
    }
}

 The Ellipse2DDemo class This class will consists oftwo methods: the main and the printEllipseDetails methods. The main method does the following: 1. Prompts th
 The Ellipse2DDemo class This class will consists oftwo methods: the main and the printEllipseDetails methods. The main method does the following: 1. Prompts th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site