Question

In: Computer Science

Define an interface called Shape that requires methods to get x and y, and a method...

Define an interface called Shape that requires methods to get x and y, and a method to calculate the area. Call these methods getX(), getY(), and getArea(). Write a class called MyRectangle that implements the Shape interface and contains:

the double data fields x, y , and width with get and set methods

a no-arg constructor that creates a default rectangle with 0 for both x and y and 1 for both length and width

a constructor that creates a rectangle with the specified x, y , length, width

a method getX() that returns x location value of the rectangle

a method getY() that returns y location value of the rectangle

a method getArea() that returns the area of the rectangle

Solutions

Expert Solution

//Shape.java
public interface Shape {
    public double getX();
    public double getY();
    public double getArea();
}
//////////////////////////////////////////////

//MyRectangle.java
public class MyRectangle implements Shape {
    private double x,y, width, length;

    public MyRectangle() {
        x = 0;
        y = 0;
        width = 1;
        length = 1;
    }

    public MyRectangle(double x, double y, double width, double length) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.length = length;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getWidth() {
        return width;
    }

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

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getArea() {
        return width*length;
    }
}

Related Solutions

create an interface called Visible that has two methods called makeVisiible, makeInvisible. both methods take no...
create an interface called Visible that has two methods called makeVisiible, makeInvisible. both methods take no parameters and should return a boolean result. HTML EditorKeyboard Shortcuts 12pt Paragraph 0 words Flag this Question Question 58 pts The following classes have been created with the given behaviors: public class Leo extends Don { public void method1() { System.out.print("Leo 1 "); } public void method3() { System.out.print("Leo 3 "); } public String toString() { return "Leo 1 "; } } class Mike...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y),...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y), where x and y are integers. Define methods to individually set the x and y coordinates of your new point and retrieve their values. Write an Objective-C program to implement your new class and test it (main section of the file). Your test program needs to create two instances of your class. Make sure your program test prints out the values that you have...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the...
Suppose (X, dX) and (Y, dY ) are metric spaces. Define d : (X ×Y )×(X...
Suppose (X, dX) and (Y, dY ) are metric spaces. Define d : (X ×Y )×(X × Y ) → R by d((x, y),(a, b)) = dX(x, a) + dY (y, b). Prove d is a metric on X × Y .
5. Equations of the form y’ = P(x)*y^2 + Q(x)*y + R(x) are called Riccati equations....
5. Equations of the form y’ = P(x)*y^2 + Q(x)*y + R(x) are called Riccati equations. i) If we know a solution y = φ(x) of this equation, then any other solution can be written in the form y(x) = φ(x)+ 1/v(x), where v(x) is an unknown function which satisfies a certain linear equation. Using the fact that φ and y both solve the above Riccati equation, find the differential equation that v satisfies. ii) Consider the equation 3y’ +...
5. Equations of the form y’ = P(x)*y^2 + Q(x)*y + R(x) are called Riccati equations....
5. Equations of the form y’ = P(x)*y^2 + Q(x)*y + R(x) are called Riccati equations. i) If we know a solution y = φ(x) of this equation, then any other solution can be written in the form y(x) = φ(x)+ 1/v(x), where v(x) is an unknown function which satisfies a certain linear equation. Using the fact that φ and y both solve the above Riccati equation, find the differential equation that v satisfies. ii) Consider the equation 3y’ +...
x^2*y''+x*y'+(x^2-1)y=0 what is the solution by using Frobenius method
x^2*y''+x*y'+(x^2-1)y=0 what is the solution by using Frobenius method
Formulate Newton’s method for the system x^3 = y y^3 = x Note that this system...
Formulate Newton’s method for the system x^3 = y y^3 = x Note that this system has three real roots (−1, −1), (0, 0) and (1, 1). By taking various initial points in the square −2 < x, y < 2, try to obtain the attraction regions of these three roots. P.S. An attraction region of a root is defined as the set of all initial points which will eventually converge to the root.
define U=x+y, V=x-y. find the joint and marginal pdf of U and V
define U=x+y, V=x-y. find the joint and marginal pdf of U and V
Define (x,y,θ) ~ P(x,y,θ) as follows: θ ~ Unif{0.1,0.9} (x,y) |θ ~ Bern(x|θ) Bern(y|θ) Where Bern(....
Define (x,y,θ) ~ P(x,y,θ) as follows: θ ~ Unif{0.1,0.9} (x,y) |θ ~ Bern(x|θ) Bern(y|θ) Where Bern(. | θ) is the p.m.f. for a Bernoulli random variable which takes the value 1 or 0 with probability, θ, (1-θ) respectively. Find probabilities a) Pr(x=0, y=0) ? (enter answer in decimal form, e.g. 0.56 ) (b) Pr(x=1, y=1) ? (enter answer in decimal form, e.g. 0.56 ) (c) Pr(x=1, y=0)   ? (enter answer in decimal form, e.g. 0.56 ) (d) Pr(x=0, y=1) ?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT