SWEN 601 HOMEWORK 10
Abstract Classes & Interfaces
You should have already accepted the GitHub classroom invite for this assignment, but
if for some reason you have not, do so now. Create a package for this homework, and
commit/push your project to GitHub.
For this homework assignment, you will be using the code session10 located under
content > Homework > Homework 10.
This code contains the classes: Circle, Position, Rectangle, Shape, ShapeMover, and
Triangle.
1. Make the class Share abstract, by making both methods area() and perimeter()
abstract. And make the necessary adjustments for the remaining classes.
2. Add a new interface to your project: Figure. Add the following methods to the
interface:
a. Position getPos()
b. move(Position)
c. String getFillColor()
d. String getLineColor()
e. double area()
f. double perimeter()
3. Update your Shape class to implement Figure. Delete methods area() and
perimeter() from the Shape class.
4. Update your ShapeMover class to use the Figure interface instead of the Shape
class.
5. Add a new method to scale the size of a Figure: scale(double factor). Make the
necessary changes to your classes to reflect the behavior of this new method.
6. In your ShapeMover class, write a new method to scale a figure. Update your
main method to scale each of your figures after moving it.
7. Add a new class called ShapeArray. This class will also have a main method, just
like ShapeMover. It will also prompt the user for a given arraySize (between 2
and 20), then it will create an array that will contain objects of type Triangle,
Circle, and Rectangle. The size of the array is arraySize.
8. Populate this array randomly with objects that can be of any of the following
types: Triangle, Circle, and Rectangle. The state of each object (e.g., position, or
radius, etc.) is also randomly assigned.
9. Loop through the array and print all the created objects (using
System.out.println).
10.Create a method, in ShapeArray, called sortShape, which takes as input, an
array of type Shape, as a parameter, and returns a sorted array of shapes based
on the area values (the first cell contains the object with the smallest area, all the
way to the last cell containing the object with the largest area).
11.Call the method sortShape to sort the randomly created array.
12.Create a method, in ShapeArray, called findShape, which takes as input, an
array of type Shape as a first parameter, and a given Shape object, as a second
parameter, and returns true if the object has a similar one in the array. By
similarity, we mean an object of the same type (Circle, rectangle, etc.) and the
same state.
13.Loop through the array and print all the created objects (using
System.out.println).
14.Call the method findShape twice, in the first call, you pass the randomly created
array and a randomly created object, then in the second call, you pass the
randomly created array, and the object of its first cell. Print both results.
When you are finished, draft a new GitHub release. Use the “Source code (.zip)” link to
download your release. Submit this to the assignment on MyCourses. Late submissions
are not accepted.
Grading Rubric
Exceptional
Performance
4
Competent
Performance
3
Acceptable
Performance
2
Developing
Performance
1
Beginning
Performance
0
All assignment
instructions
followed. Program
runs as described.
A small number of
minor problems,
e.g. 1-2
instructions not
followed,
specifications not
met, few commits,
few comments,
etc.
Several minor
problems, e.g.
several
instructions not
followed,
specifications not
met, few commits,
few comments,
etc.
Many minor or
major problems,
e.g. code does not
compile or run,
does not meet
functionality
requirements, etc.
Very little effort or
no submission at
all.
100% 88% 75% 50% 0%