Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

b. Will there be one assigned leader?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago

Question

b. Does senior management trust the team?

Answered: 1 week ago