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 named Circle and Rectangle. Write a test program that uses the max method to find the larger of two circles (c1 of the radius 1.2 and c2 of the radius 1.2) and the larger of one circle (c1 of the radius 1.2) and one rectangle (of the length 5 and width 3.4.
Sample run (red indicates user input)
Comparing two circles:
The two shapes are equal.
Comparing a circle and a rectangle:
The greater shape is the rectangle of length 5.0 and width 3.4
This is the geometric object code(Keep in mind you can change this if needed, only posted to make your life easier) But please make sure the classes are clearly seperated. If you wish to make your own code rather than the one below please do so
GeometricObject:
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
public 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.filled = filled;
}
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean,
so, the get method name is isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}
/** Return a string representation of this object */
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color +
" and filled: " + filled;
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}
Example of a comparator:
import java.util.Comparator;
public class GeometricObjectComparator
implements Comparator<GeometricObject>, java.io.Serializable
{
public int compare(GeometricObject o1, GeometricObject o2) {
double area1 = o1.getArea();
double area2 = o2.getArea();
if (area1 < area2)
return -1;
else if (area1 == area2)
return 0;
else
return 1;
}
}
Example of Max.java:
public class Max {
/** Return the maximum between two objects */
public static Comparable max(Comparable o1, Comparable o2) {
if (o1.compareTo(o2) > 0)
return o1;
else
return o2;
}
}
Example of another Max.java:
public class Max1 {
/** Return the maximum between two objects */
public static <E extends Comparable<E>> E max(E o1, E
o2) {
if (o1.compareTo(o2) > 0)
return o1;
else
return o2;
}
}
If you need more info comment! please and thanks :)
It will help you package geometricobject;
public abstract class GeometricObject implements Comparable<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 void setFilled(boolean filled){
this.filled = filled;
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public String toString() {
return "Created on " + dateCreated + "\ncolor: " + color +
"and filled: " + filled;
}
public static void main(String[] args) {
GeometricObject circle1 = new Circle(1, "Red", true);
GeometricObject circle2 = new Circle(2, "Blue", false);
GeometricObject maxCircle = new Circle();
GeometricObject rect1 = new Rectangle(1, 1, "Red", true);
GeometricObject rect2 = new Rectangle(2, 2, "Blue", false);
GeometricObject maxRect = new Rectangle();
maxCircle = GeometricObject.max(circle1, circle2);
maxRect = GeometricObject.max(rect1, rect2);
System.out.println(maxCircle.toString());
System.out.println(maxRect.toString());
}
public static GeometricObject max (GeometricObject o1, GeometricObject o2){
if (((Comparable)o1).compareTo(o2) > 0 )
return o1;
else
return o2;
}
public interface Comparable {
public int compareTo(GeometricObject o);
}
public int compareTo(GeometricObject o) {
if (this.getArea() > o.getArea())
return 1;
else if (this.getArea() < o.getArea())
return -1;
else
return 0;
}
public abstract double getArea();
}
The circle class
class Circle extends GeometricObject {
private double radius;
public Circle() {
}
public Circle(double radius){
this.radius = radius;
}
public Circle(double radius, String color, boolean filled){
this.radius = radius;
setColor(color);
setFilled(filled);
}
public double getRadius(){
return radius;
}
public void setRadius(double radius){
this.radius = radius;
}
public double getArea(){
return radius * radius * Math.PI;
}
public double getDiameter(){
return 2 * radius;
}
public double getPerimeter(){
return 2 * radius * Math.PI;
}
public void printCircle() {
System.out.println("The circle is created " + getDateCreated() +
" and the radius is " + radius);
}
}
The rectangle class
class Rectangle extends GeometricObject {
private double width;
private double height;
public Rectangle() {
}
public Rectangle(double Width, double Height){
this.width = Width;
this.height = Height;
}
public Rectangle(double Width, double Height, String Color, boolean Filled){
this.width = Width;
this.height = Height;
setColor(Color);
setFilled(Filled);
}
public double getWidth(){
return width;
}
public double getHeight(){
return height;
}
public void setHeight(double Height){
this.height = Height;
}
public double getArea(){
return width * height;
}
public double getPerimeter(){
return 2 * (width + height);
}
}
this is for java programming Please Use Comments I am not 100% sure if my code...
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...
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...
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;...
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)...
Objective Extend the class GeometicShapes to include a Triangle class.. Background Reading ZyBooks Chapter 10 Task Create the following fields and methods for a Triangle class that extends the provided GeometricShapes class public class GeometricShapes { private String color = "red"; private boolean filled; private java.util.Date dateCreated; public GeometricShapes() { dateCreated = new java.util.Date(); } public GeometricShapes(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public void setColor (String color)...
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...
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";...
Define an abstract class GeometricShape with a color (string), filled (boolean), and dateCreated (java.util.Date) GeometricShape has getter/setter methods for each attribute, along with a getArea, a getPerimeter, and toString method that returns the shape information in a formatted string including class name, color, filled, dimensions (if available), area, perimeter, and date created Additionally GeometricShape implements the Java Comparable interface and defines a static method max used to find the larger of two GeometricShapes based on their area
Hey, I have this homework from my data structures class using java that I am having difficulties coding. I had to create an abstract class Shape, which contains two protected instance variables color(String) and filled(boolean). Getter and setter for all the instance variables, and toString(). Two abstract methods getArea() and getPerimeter(). The part that I am not sure how to code is: for the subclasses of Shape which are Circle and Rectangle I have to override the abstract methods getArea()...
All Codes are in java, I need the answers asap my assignment is
almost due, thanks. I'll give thumbs up.
5. (20 pts)Given the Abstract class below, Shape, draw the UML diagram for a class Square that inherits Shape. Square needs to contain a private variable called side which is a double. It should have a default no argument constructor and an overloaded constructor that takes color, filled and side. Shape -color: String -filled: boolean +Shape() +Shape(color: String, filled: boolean)...