Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment A2 (35 marks) Focus: Abstract Classes and Interfaces, Standard Java Interfaces: Comparable, Cloneable, For this assignment, you need to download from Connect the Shape
Assignment A2 (35 marks) Focus: Abstract Classes and Interfaces, Standard Java Interfaces: Comparable, Cloneable, For this assignment, you need to download from Connect the Shape class shown below and include in your project. public abstract class Shape //attributes private String color; private boolean filled; //constructors protected Shape ()(this ( "White", true);} protected Shape(String color, boolean filled){ setColor (color); setFilled (filled) //methods public String getColorO(return color;) public void setColor(string color){this.color = color:) public boolean isFilled ()(return filled;) public void set Filled (boolean f)(filled f;} public String toString() return "Color " + color + ". " + (filled? "Filled. ":"Not filled. "); public abstract double getArea); public abstract double getPerimeter); Q1. [15 marks] Create a class named Hexagon that extends Shape and implements the Cloneable and Comparable interfaces. The comparison should be based on the area of two shapes. Use the following method header: public int compareTo (Shape shp) Assume that all six sides of a hexagon are of equal length. Create appropriate setter and getter method(s) and constructor(s), and override the toString method to return a string representation of all attribute values as well as the area and perimeter of a hexagon object Write a test program that asks the use for the attributes of a Hexagon object (i.e., side length, color, and filled), creates that object, and then displays its state (side, color, area, etc.). Assume users enter valid inputs. Create a new object using the clone method and compare the two objects using the compareTo method Hint: Add throws CloneNotSupportedException" to the header of the clone method as well as the mainmethod in your test program. You will learn more about exception handling in next lecture and lab
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started