I have a programming question from my highschool course that needs a java solution.

I have a programming question from my highschool course that needs a java solution.

Create a Java Project called InterfaceDemo

A. Create the following classes in the project (under default package):

  • GeometricObjects
  • Circle
  • Rectangle
  • ShapesMain
  • In addition, under the same package create a new interface called Shape
  • B. Implement the following interface and classes as per the given direction:

    1. Shape : defined as: public interface Shape. The interface will contain two methods:

  • public double getArea();
  • public double getPerimeter();
  • These methods will be implemented in the Circle and Rectangle classes.

    2. GeometricObjects:

    Use the code given below for the GeometricObjects class:

    public class GeometricObjects {

    private String color;

    private boolean filled;

    public GeometricObjects(){

    this.color = “white”;

    this.filled = false;

    }

    /*Construct Geometric Object with specified color and filled value*/

    public GeometricObjects(String color, boolean filled){

    this.color = color;

    this.filled = filled;

    }

    /* Return Color*/

    public String getColor(){

    return color;

    }

    /*Return filled. since filled is boolean we name it isFilled*/

    public boolean isFilled(){

    return filled;

    }

    /*Set new color*/

    public void setColor(String color) {

    this.color = color;

    }

    /*Set new filled*/

    public void setFilled(boolean filled){

    this.filled = filled;

    }

    /* toString method that returns the string representation of object*/

    public String toString(){

    return “Object color is: ” + color + ” object filled is: ” + filled ;

    }

    }

    3. Circle :

    The circle class will extend GeomtricObjects and implement Shape as follows. Fill the required code for this code by following the directions given as comments

    public class Circle extends GeometricObjects implements Shape {

    //3.1 Declare instance variable radius as private and type double.

    //3.2 create a constructor that takes in radius value as an argument

    //3.3 create a 3-arg constructor that takes in values for radius, color and filled. Color and filled inherited //from GeometricObjects

    //3.4 Write a getArea() method that calculates and returns the area of the circle

    //3.5 Write a getPerimeter() method that calculates and returns the perimeter of the circle

    // 3.6 Write a toString() method that will return a return: super.toString()+ “; Circle Area is: ” + getArea() + “; Perimeter is: ” + getPerimeter() ;

    }

    }

    4. Rectangle :

    This class will extend GeometricObjects and implement Shape as follows:

    public class Rectangle extends GeometricObjects implements Shape {

    //4.1 Declare two instance variables width and length of type double and as private

    //4.2 Create a 2-arg constructor that takes in values of length and width.

    //4.3 Create a 4-arg constructor that takes in values of width , length, color and filled. Color and filled inherited //from GeometricObjects

    // 4.4 Write a getArea() method that calculates and returns the area of the rectangle

    //4.5 Write a getPerimeter() method that calculates and returns the perimeter of the rectangle

    //4.6 Write a toString() that will return: super.toString()+ “; Rectangle Area is: ” + getArea() + “; Perimeter is: ” + getPerimeter() ;

    }

    }

    5. ShapesMain :

    This will be the tester class that will use an ArrayList of shapes, of type Shape (,the interface).

    Please use the code below:

    import java.util.ArrayList;

    public class ShapesMain {

    public static void main(String[] args){

    /* 5.1 Create an array list of Shape as shown below –it can hold any Shape Circle or Rectangle since both of them implement Shape.*/

    ArrayList<Shape> shape = new ArrayList<Shape>();

    //5.2 You can add a shape — either Rectangle of circle using appropriate constructors as shown below

    shape.add(new Rectangle(2,3));

    shape.add (new Circle(5));

    shape.add(new Circle(6,”blue”,true));

    shape.add(new Rectangle(2,3,”red”,false));

    /*5.3 Use a for loop to step through each element/object of the array list and print out the String returned by the toString() method for each object. Pay attention to the use of shape.get(i) to fetch the object located in index I of the ArrayList */

    for(int i = 0; i<shape.size();i++){

    System.out.println(“shape “+i+ ” = “+shape.get(i).toString());

    }

    }

    }

    To submit: all the .java files Circle, Rectangle and ShapeMain and Shape for this exercise. Also submit a copy of your code in word document.

    Please create a new Project called GeoObjArrayList. In this project, under the default package, you will have the following classes:

    1) A super class called GeometricObjects. Use the same code as what you used in the previous exercise.

    2) Two subclasses: Rectangle and Circle – use the same code as in the previous exercises.

    Please do not include the interface called Shape in this example . Make sure you define your Circle class as: public class Circle extends Geometric Objects. Also make sure you define your Rectangle class as : public class Rectangle extends GeometricObjects

    3) Tester class called TestGeoObjectsYourName that needs to be completed. Please follow the comments which gives you instructions to complete the code, as given below:

    import java.util.ArrayList;

    public class TestGeoObjectsYourName {

    public static void main(String[] args){

    //create an ArrayList of the type Rectangle as shown below:

    ArrayList<Rectangle> myRectangleList= new ArrayList<Rectangle>();

    //Add five Rectangles to the ArrayList. Two examples are given below.

    // Use different types of constructors.

    myRectangleList.add(new Rectangle(6,7));

    myRectangleList.add(new Rectangle(8,10,”blue”,true));

    //…add 3 more Rectangles to myRectangleList….

    /*Using a for loop, go over each Rectangle object and print the string returned by the toString() for each arrayList element.*/

    // Create another ArrayList called myCircleList of the type Circle as shown below:

    ArrayList<Circle> myCircleList= new ArrayList<Circle>();

    /*add five Circles to myCircleList. Use different types of constructors. Two examples have been worked out for you*/

    myCircleList.add(new Circle(5));

    myCircleList.add(new Circle(7, “red”, false));

    //Create three more circle objects and add them to the list

    /*Using a for loop, printout the string returned by the toString() for each element of myCircleList.*/

    // Create a new ArrayList of GeometricObjects called myShapesList, as shown below

    ArrayList<GeometricObjects> myShapesList = new ArrayList<GeometricObjects>();

    /*add two Rectangle objects (use any Rectangle constructors) to myShapesList. See the code in previous exercise— how we add Rectangle and circle objects to Shapes ArrayList*/

    // add two Circle objects to myShapesList, using any Circle constructors.

    // use a for loop to go over each element of myShapesList and for each element, use the toString()).

    }

    }

    "You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


    Discount Code: CIPD30



    Click ORDER NOW..

    order custom paper