Hello guys,
I hop you are all well,
guys I need help in this exercises. Could any one help me with and understand it?
Write the Java programs according to the following specifications
Part 1.1 Develop an interface Colourful to the following specifications:
It includes one public method assignMyColour( String colour). When this method is
implemented, it should set the colour of its object by the given value as its argument.
Part 1.2 Develop a public class Point to the following specifications:
1) The class has two private instance variables: int x and y.
2) The class has a multi-argument constructor that sets the values of its instance
variables to the given values.
3) The class has a zero-argument constructor that sets the values of its instance variables
to their default values. It should invoke the multi-argument constructor.
4) The class has the getter and setter methods for the instance variables.
Part 1.3 Develop a public abstract class Shape to the following specifications:
1) The class implements the Colourful interface.
2) The class has one private instance variable: Point p1.
3) The class has a one-argument constructor that creates and sets the value of its
instance variable to the given value of p1.
4) The class has to override the Object’s toString() method in order to return a string with
representation of the Point instance variables as:
(x, y)
5) Implement any methods that are needed.
Part 1.4 Develop a public class Oval to the following specifications:
1) The class inherits the Shape class.
2) The class has the following private instance variables: width and height as an integer,
myColour as string, counterO as an integer which keeps one copy for all instantiated
objects of oval and counts their numbers.
3) The class has a multi-argument constructor that creates and sets the values of its
instance variables to the given values. It should invoke its super-class constructor.
Oval (Point p, int width, int height, String colourName)
4) The class has the getter and the setter methods for the private instance variables width,
height, counterO.
5) The class has to override the Object’s toString() method in order to return a string
representation of the Oval instance variables as:
The oval in (10 , 10) its width is 80 its height is 90 its colour is Red
6) Implement any methods that are needed.
Part 1.5 Develop a public class Rectangle to the following specifications:
1) The class inherits the Shape class.
2) The class has the following private instance variables: Point p2, myColour as string,
counterR as an integer which keeps one copy for all instantiated objects of rectangle and
counts their numbers.
M257 TMA Spring 13-14 Page 4
3) The class has a multi-argument constructor that creates and sets the values of its
instance variables to the given values. It should invoke its super-class constructor.
Rectangle (Point p1, Point p2, String colourName)
4) The class has the getter and the setter methods for the private instance variable
counterR.
5) The class has to override the Object’s toString() method in order to return a string
representation of the Rectangle instance variables as:
The Rectangle starts at (0 , 0) and ends at (100 , 100) its colour is green
7) Implement any methods that are needed.
Part 1.6 Develop a public class MyShapes to the following specifications:
1) The class has one private instance variable HashMap<String, Shape> myShapes,
which represents the collection of shapes from class Shape and its subclasses.
2) The class has a zero-argument constructor that creates its instance variable
myShapes.
3) The class has the method void addOval( String type, Oval oval). It creates the key of
the Oval object by concatenating its type by its counter, and then it adds the Oval object
into the myShapes collection.
4) The class has the method void addRectangle( String type, Rectangle rectangle). It
creates the key of the Rectangle object by concatenating its type by its counter, and then
it adds the Rectangle object into the myShapes collection.
5) The class has the method String showShapes(), which returns a string representation
for all shapes in the collection or a message “There are no shapes in the collection” if
the collection is empty.
6) Implement any methods that are needed.
Part 1.7 Develop a public class TestMain to the following specifications:
1) The class has a static main method.
2) The class instantiate the MyShapes class.
3) The class has to fill myShapes instance object by reading the values from the TXT file
("C:/Spring13-14Shapes.txt"), which is provided in the TMA folder.
4) It should check whether the type of the shape is Oval or Rectangle and then it should use
the corresponding methods that are needed to add the objects into the myShapes object.
5) The data includes the following
For Oval: the type of the object followed by the Point P1’s coordinates width, height and
colour.
For Rectangle: the type of the object followed by Points P1 and P2 coordinates, and its
colour.
6) Finally, it should display on the screen the shapes in myShapes and the number of
Rectangle and Oval objects.
7) Implement any methods that are needed.
Thank you all,