JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST CASES(WHAT IM TRYING TO PRODUCE) BELOW THOSE IMAGES ARE THE .JAVA FILES THAT I HAVE CREATED. THESE ARE GeometircObject.Java,Point.java, and Tester.Java. I just need help making the Rectangle.java and Rectangle2D.java classes.
GeometricObject.Java: public abstract class GeometricObject { private String color = "white"; // shape color private boolean filled; // fill status protected GeometricObject() { // POST: default shape is unfilled blue this.color = "blue"; this.filled = false; } // POST: shape set by user protected GeometricObject(String color, boolean filled) { this.color = color; this.filled = filled; } // accessors and modifiers public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isFilled() { return filled; } public void setFilled(boolean filled) { this.filled = filled; } public String toString() { // POST: string representation of shape return "color: " + color + " filled: " + filled; } public abstract double getArea(); // POST: return area of geometric object public abstract double getPerimeter(); // POST: return perimeter of geometric object }
Point.Java:
public class Point {
private double x ; // x coordinate private double y; // y coordinate public Point ( ) // POST: point (0,0) { x = y = 0; } public Point (double x, double y) // POST: point (x,y) { this.x = x; this.y = y; } // accessors and modifiers 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 String toString() // POST: return (x,y) { return " (" + x + "," + y + ") "; } }
Tester.Java:
import java.util.Scanner; public class Tester { public static void main(String[] args) { Scanner scan = new Scanner (System.in); System.out.print("Enter (x,y) for start rectangle: "); double x = scan.nextDouble(); double y = scan.nextDouble(); System.out.print("Enter width,height for start rectangle: "); double w = scan.nextDouble(); double h = scan.nextDouble(); Rectangle2D rec = new Rectangle2D (x,y,w,h); String code; System.out.print("Contains or overlap (C/O): "); code = scan.next(); if (code.equals("C")) { System.out.print("Compare to point or rectangle: (P/R): "); code = scan.next(); if (code.equals("P")) { Point p = new Point(); System.out.print("Enter (x,y) for point: "); p.setX(scan.nextDouble()); p.setY(scan.nextDouble()); if (rec.contains(p))System.out.println("rec contains point"); else System.out.println("rec does not contain point"); } else { System.out.print("Enter (x,y) for second rectangle: "); x = scan.nextDouble(); y = scan.nextDouble(); System.out.print("Enter width,height for second rectangle: "); w = scan.nextDouble(); h = scan.nextDouble(); Rectangle2D rec2 = new Rectangle2D (x,y,w,h); if (rec.contains(rec2))System.out.println("rec contains second rec" + ""); else System.out.println("rec does not contain second rec"); } } else { System.out.print("Enter (x,y) for second rectangle: "); x = scan.nextDouble(); y = scan.nextDouble(); System.out.print("Enter width,height for second rectangle: "); w = scan.nextDouble(); h = scan.nextDouble(); Rectangle2D rec2 = new Rectangle2D (x,y,w,h); if (rec.overlaps(rec2))System.out.println("second rec overlaps rec" + ""); else System.out.println("second rec does not overlap rec"); } scan.close(); } }
Feel free to reach out if you have any doubts.
Please do rate if the answer was helpful.
Thanks
----------------------------------------------------------------------------------------------------------------------------
Rectangle.java
public class Rectangle extends GeometricObject{
private double width;
private double height;
public Rectangle() {
super();
width = 2.0;
height = 1.0;
}
public Rectangle(double width, double height, String
color, boolean filled) {
super (color,filled);
this.width = width;
this.height = height;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
@Override
public double getArea() {
return width * height;
}
@Override
public double getPerimeter() {
return ((2 * width) + (2 *
height));
}
@Override
public String toString ( ) {
return super.toString() + "
height: " + height + " width: " + width + " area: " +
String.format("%-6.2f",getArea()) + " perimeter: " +
String.format("%-10.2f",getPerimeter());
}
}
----------------------------------------------------------------------------------------------------------------------------
Rectangle2D.java
public class Rectangle2D extends Rectangle {
private Point upperLeft;
public Rectangle2D()
{
super();
upperLeft = new Point(0,0);
}
public Rectangle2D(double x, double y,double width, double
height)
{
super(width, height, "white", false);
upperLeft = new Point(x, y);
}
public Rectangle2D(double x, double y,double width, double height,
String color, boolean filled)
{
super(width, height, color, filled);
upperLeft = new Point(x, y);
}
public Point getUpperLeft()
{
return upperLeft;
}
public String toString()
{
return super.toString() +" upper left: " + upperLeft;
}
public boolean contains(Point other)
{
if(upperLeft.getX() <= other.getX() && other.getX()
<= upperLeft.getX() + getWidth())
{
if(upperLeft.getY() <= other.getY() && other.getY()
<= upperLeft.getY() + getHeight())
return true;
}
return false; //for all other cases
}
public Boolean contains (Rectangle2D other)
// POST: return true if object contains other rectangle
{
//compute the lowerRight corner of the other rectangle
Point lowerRight = new Point(other.upperLeft.getX() +
other.getWidth() , other.upperLeft.getY() + other.getHeight());
//only if this rectangle contains both the upper left and lower
right corners of the other rectangle,
//the other rectangle is fully contained in this rectangle
if(contains(other.upperLeft) && contains(lowerRight))
return true;
else
return false;
}
public Boolean overlaps (Rectangle2D other)
// POST: return true if other overlaps object
{
//calculate the 3 other corners of the other rectangle
Point lowerRight = new Point(other.upperLeft.getX() +
other.getWidth() , other.upperLeft.getY() +
other.getHeight());
Point upperRight = new Point(other.upperLeft.getX() +
other.getWidth() , other.upperLeft.getY() );
Point lowerLeft = new Point(other.upperLeft.getX() ,
other.upperLeft.getY() + other.getHeight());
//there is an overlap if any of the 4 corners of the other
rectangle are contained in this rectangle
if(contains(other.upperLeft) || contains(lowerRight) ||
contains(upperRight) || contains(lowerLeft))
return true;
else
return false;
}
}
------------------------------------------------------------------------------------------------------------------------------
Output for Tester Class:
Enter (x,y) for start rectangle: 2 2
Enter width,height for start rectangle: 5 5
Contains or overlap (C/O): C
Compare to point or rectangle: (P/R): 3 3
Enter (x,y) for second rectangle: 4 5
Enter width,height for second rectangle: 10 5
rec does not contain second rec
-------
Enter (x,y) for start rectangle: 2 2
Enter width,height for start rectangle: 5 3
Contains or overlap (C/O): O
Enter (x,y) for second rectangle: 3 3
Enter width,height for second rectangle: 10 5
second rec overlaps rec
-------------------------------------------------------------------------------------------------------------------
JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST...
The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; protected GeometricObject() { dateCreated = new java.util.Date(); } protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isFilled() { return filled; } public...
Can the folllowing be done in Java, can code for all classes and code for the interface be shown please. Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometriObject class for finding the larger of two GeometricObject objects. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles. The GeometricObject class is provided below: public abstract class GeometricObject { private...
this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...
Why is my program returning 0 for the area of a triangle? public class GeometricObjects { private String color = " white "; private boolean filled; private java.util.Date dateCreated; public GeometricObjects() { dateCreated = new java.util.Date(); } public GeometricObjects(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color)...
Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...
This is a question about Java abstract classes. The correct answer is E and I do not understand why. Please be specific! I am a beginner in Java abstract classes and methods... 13.6 What is the output of running class Test? public class Test { public static void main(String[] args) { new Circle9(); } } public abstract class GeometricObject { protected GeometricObject() { System.out.print("A"); } protected GeometricObject(String color, boolean filled) { System.out.print("B"); } } public class Circle9 extends GeometricObject {...
I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side; //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); } //setter and getter methods for Square public void setSide(double side) { this.side = side; } public double getSide() { return...
Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The ColoredRectangle class will have an additional private String field named Color. The ColoredRectangle class should have four constructors: a no-arg constructor; a three-arg constructor; a two-arg constructor that accepts a Rectangle object and a color; and a copy constructor. The ColoredRectangle class should have an Equals and toString methods. The ColoredRectangle class should have mutators and accessors for all three fields. public class Rectangle...
Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt); third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console { private Scanner sc; boolean isValid; int i; double d; public Console() { sc = new Scanner(System.in); } public String getString(String prompt) { System.out.print(prompt); return sc.nextLine();...
Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g GeometricObject.java GeometricObject.java:92: error: class, interface, or enum expected import java.util.Comparator; ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 20.21 Please code using Java IDE. Please DO NOT use Toolkit. You can use a class for GeometricObject. MY IDE does not have access to import ToolKit.Circle;import. ToolKit.GeometricObject;.import ToolKit.Rectangle. Can you code this without using the ToolKit? Please show an...