Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

image text in transcribedimage text in transcribed

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(); } } 

Part II. (80 pts.) Write a program to solve the following problem. Create a new Java Project named assignmentl. When complete, you will create a jar file to be submitted on Blackboard. nne the following locations: * At the top of the program include your name and a sentence describing the program purpose *Comment the purpose of major variables neatly aligned to the right side, including units. *Comment major sections of code such as input, processing steps, and output. Program Design: Your program is a professional document and must be neat and easy to read. All programs should follow the listed specifications. Programs that are deficient in design will lose points or not be accepted. 'Word-wrap of comments is not permitted. Keep comments short to right of statement or place above statement. 'Comments should be aligned and entered in a consistent fashion. " Code within blocks should be indented. 'Comments should not contain spelling mistakes 'Variables names should be meaningful to their content 'All methods (excepts class accessors/modifier) need PRE/POST comments. Classes GeometricObject and Point have been written using the code given in Chapter 13 lecture and are available for download on the Blackboard link. You wrote class Rectangle derived from Geometricbject for Class Exercise #1 1. Write class Rectangle2D that derives from Rectangle. It adds a Point data member (x.y) to store the coordinates of the upper left corner of the rectangle. Point offers constructors, accessors, modifiers and toString methods to report the point in (x,y) notation. Add Rectangle2D constructors, accessors, modifiers, and a toString method that reports the upper left coordinates, width, and height. Add the following methods: public Boolean contains (Point other) Il POST: return true if object contains other point A rectangle contains a point if point lies within it (may lie on border)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions