I2211 Spring2024 Session1
I2211 Spring2024 Session1
Consider the following UML diagram that shows the relation between a set of interfaces and classes.
The corresponding Java code is shown below.
Interface 6
Interface 4 Interface 5
Shape ShapeCollection
Circle Quadrilateral
Square
public interface Interface6 {
String interfaceVariable = "It is Interface 6.";
static void display(){
System.out.println("This is a static method of Interface 6.");
} }
public interface Interface5 extends Interface6{
String interfaceVariable = "It is Interface 5.";
double getPerimetre();
}
public interface Interface4 extends Interface6 {
String interfaceVariable = "It is Interface 4.";
double getArea();
}
public interface Interface3 {
String interfaceVariable = "It is Interface 3.";
void DisplayInfo();
}
public interface Interface2 extends Interface4,Interface5{
String interfaceVariable = "It is Interface 2.";
String getType();
}
public interface Interface1 {
String interfaceVariable = "It is Interface 1.";
void Draw();
}
Page 1 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Section A (45 points): For each of the following blocks of code specify what the output is. If the
instruction causes an error YOU HAVE to specify its reason. NOTE that the blocks are
INDEPENDENT. If a specific block generates an error, you have to IGNORE it when interpreting
the remaining blocks.
Block 1:
Answer:
Block 2:
Answer:
Block 3:
Answer:
Block 4:
Answer:
Block 5:
Answer:
Page 3 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Block 6:
Answer:
Block 7:
Answer:
Block 8:
System.out.println(Interface5.interfaceVariable);
Answer:
Block 9:
Interface6.display();
Answer:
Block 10:
Answer:
Block 11:
Answer:
Page 4 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Block 12:
Answer:
Block 13:
Interface5.display();
Answer:
Block 14:
Answer:
Block 15:
Answer:
Page 5 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Create a class in Java called “ShapeCollection” that contains an array of Shape objects. The
ShapeCollection class should manage the shapes and include detailed functionalities as specified below:
1. Instance Variables:
2. Methods:
A constructor that initializes the name and capacity of the shape collection to given arguments.
The constructor should set the size of the shapesArray[] to the specified capacity value.
A method called addShape that adds a Shape object to the shapesArray if the collection capacity
is not reached. If the capacity is reached, this method should throw an
ArrayIndexOutOfBoundsException.
A method called getShapesInformation that returns a string value containing the information of
all the shapes in the collection.
A method called searchShapeByName that displays information about shapes having a specific
name. If no shape with the specified name is found, this method should throw an
IllegalArgumentException.
A method called countShapesByArea that counts and returns the number of shapes having a
specific area.
A method called countSquaresWithSideLength that counts and returns the number of squares
having a specific side length.
3. Main Method:
In the main method, demonstrate the functionalities of the ShapeCollection class by:
Creating an instance of ShapeCollection.
Adding shapes to the collection.
Attempting to add a shape beyond the capacity to trigger an exception.
Retrieving and displaying information about all shapes in the collection.
Searching for a shape by name and handling the case where the shape is not found.
Counting shapes by a specific area.
Counting squares by a specific side length.
Include exception handling to manage and display user-friendly error messages.
Note: Include exception handling in the main method to demonstrate the error handling functionality.
Page 6 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Page 7 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Page 8 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Page 9 of 10
INFO I2211-E Final Exam
Object Oriented Programming June 11, 2024
Java Duration: 1h30
Page 10 of 10