0% found this document useful (0 votes)
7 views3 pages

Java Interfaces and Abstract Classes Lab

This document outlines Lab 6 for EECE 332 Object Oriented Programming, focusing on Java Interfaces and Abstract Classes, due on July 9, 2025. Students will work in pairs to complete the assignment, which includes creating various shape classes and interfaces, and submitting required files in a zip format. General rules emphasize academic integrity, lab attendance, and provide guidelines for submission and project objectives.

Uploaded by

yareyaresass
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Interfaces and Abstract Classes Lab

This document outlines Lab 6 for EECE 332 Object Oriented Programming, focusing on Java Interfaces and Abstract Classes, due on July 9, 2025. Students will work in pairs to complete the assignment, which includes creating various shape classes and interfaces, and submitting required files in a zip format. General rules emphasize academic integrity, lab attendance, and provide guidelines for submission and project objectives.

Uploaded by

yareyaresass
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Department of Electrical and Computer Engineering

EECE 332 Object Oriented Programming


Summer 2025

Class Instructor: Dr. Imad Moukadem, Lab Instructor: M. Zaher Kanafani

Lab 6 – Java Interfaces with more on Abstract Classes.

This programming assignment is due on Wednesday, July 9, 2025 at 1pm.

General Rules:
• Students will be divided in groups of 2 to work on the assignment. One submission per group.
• Cheating and Copying: Any form of cheating or copying from other students' group work will result in a
zero grade for all involved students, regardless of who copied from whom.
• Submissions are not allowed after 24 hours from the deadline. For any additional hour after the deadline,
a penalty of 4% will be applied.
• The instructor will explain to all students what is required, and give some useful hints.
• The lab will span one summer week.
• Be sure to stick to the sample run when provided, otherwise points will be deducted.
• You can ask questions during the lab, regarding what to do, not how to do.
• You can make use of your notes, and any information online including chatGPT and Google.
• You can use your laptops, or the available desktops.
• Students that have accommodation letters should contact us as soon as possible.
• Lab attendance is mandatory, it counts for 5% of the overall course grade.
• In case you have a valid excuse to miss a lab, please present it before the lab for the instructor approval.

Objectives:
• The purpose of this assignment is to provide students with Basic Class Object Creation and Manipulation.
• It includes Objects Creation, Composition and Inheritance.
• It covers also Java Interfaces and Abstract Classes.
• You are asked to use IntelliJ IDEA IDE for Java.

Deliverables:
• The .java file(s) requested in each problem.
• The word file for Parts A and C. Submit just one zip file.
• One submission per student or group of 2.
• As a comment, write your names in each .java submission.

Page 1 of 3
Problem
• Create the interface Shape with 2 abstract methods: void print() and double area().
• Create the interface shape2D extending from Shape with an additional method double perimeter().
• Create the interface shape3D extending from Shape with an additional method double volume().
• Create the classes Circles and Rectangles implementing interface shape2D.
• The circle has a radius, and the rectangle has a length and a width.
• Create the classes Cube, Sphere and Cylinder implementing interface shape3D.
• The sphere has a radius, the cube has a side, and the cylinder has a radius and a height.
• All member variables are of type double.
• All shapes must have the methods print() and area().
• 2D Shapes must have also the perimeter() method.
• 3D Shapes must have also the volume() method.
• The print() method will print the shape type, the member variables, the area, and perimeter /or volume.
• Include the needed constructors, setters and getters.

Part A-
• Draw the UML diagram of this design.

Part B-
• Create an ArrayList of type Shape, and a repetitive menu to instantiate any shape.
• Input the needed parameter(s). Add the instantiated shape in the ArrayList.
• Include try/catch blocks for any input error.
• Finally output all the instantiated shapes through the print() method.
• Format your numbers to 2 decimal points.

Part C-
• I would like to have a color (String) as an attribute for my shapes.
• Can I add color to the interface Shape?
• If not, is there any other alternative?
• Include your answer in a word file together with the diagram of part A.

Page 2 of 3
Circle Area = πR2 Perimeter = 2πR
Rectangle Area = LW Perimeter = 2(L+W)
Cube Area = 6S2 Volume = S3
Sphere Area = 4πR2 Volume = 4πR3/3
Cylinder Area = 2πR(R+H) Volume = πR2H

Sample Run

Page 3 of 3

Common questions

Powered by AI

Extending functionality through interfaces allows for a flexible design where new features, such as color, can be seamlessly integrated. Instead of modifying existing interfaces, which can lead to architectural changes across many classes, a new interface or a class decorator could be introduced to handle optional features like color. This approach adheres to the open/closed principle by allowing classes to be extended with new functionalities without altering existing code, minimizing the risk of bugs and maintaining the integrity of existing functionalities .

To add a color attribute without modifying the existing Shape interface, a decorator pattern or adapter pattern can be employed. These patterns involve wrapping original shapes with additional classes that introduce the color attribute. This approach benefits by enhancing features without altering the foundational class infrastructure, maintaining backward compatibility, and adhering to open/closed principle, thus ensuring that existing functionalities remain unaffected while new features can be deployed seamlessly .

Inheritance and composition complement each other by allowing classes to inherit shared behavior and variables from abstract classes while composing new functionalities through interfaces like shape2D and shape3D. Inheritance allows for the reuse of common functionalities among shape classes, while composition, through interfaces, allows for additional functionalities to be implemented as needed, enabling the creation of complex behaviors in a manner that adheres to the single responsibility and open/closed principles. This synergy provides robust flexibility while minimizing redundancy .

Encouraging the use of online resources aligns with self-directed learning principles, promoting student autonomy and critical thinking by allowing them to leverage vast digital information pools to solve problems. This practice acknowledges the omnipresence of technology and cultivates skills in seeking, evaluating, and applying information effectively. It reflects real-world scenarios where professionals use all available tools, fostering adaptive learning and problem-solving abilities critical for career readiness in a constantly evolving technological landscape .

Formatting numerical outputs to two decimal points ensures consistency and readability, particularly important when dealing with calculated values such as area, volume, and perimeter. Such precision is crucial in applications where these numerical values impact further processes or decisions. It prevents issues related to excessive decimal places, which could cause confusion or be deemed less professional in displayed results, enhancing the usability and clarity of output data for developers and end-users alike .

The requirement to implement methods such as print(), area(), perimeter(), and volume() in every shape encourages the adoption of polymorphism and interface segregation principles. By enforcing a contract that these methods must be included, it ensures that all shapes adhere to a consistent interface, allowing different shapes to be treated uniformly through polymorphism. This design favors loose coupling, where the specifics of each shape’s implementation are abstracted away, promoting a modular and maintainable codebase .

The print() method illustrates polymorphism by allowing different shape objects to be processed using the same interface or abstract class reference. Each shape class, such as Circle, Rectangle, or Sphere, provides its specific implementation of the print() method, detailing its unique attributes and properties. Thus, while the invocation method remains consistent across different shapes, the actual behavior is determined by the specific class of the object being invoked. This runtime polymorphism is a key feature of object-oriented programming, enabling flexible and reusable code .

Using interfaces and abstract classes enhances code modularity and flexibility. Interfaces allow the definition of a contract that various classes can implement, ensuring they provide specific functionalities, such as the ability to compute area or volume for shapes. Abstract classes provide a common base for related classes, allowing for code reuse and the implementation of shared logic, like common methods for printing shape details, while still allowing for unique implementations in subclasses. These concepts help in designing a clean and scalable architecture for managing different shapes and their behaviors independently without code duplication .

Mandatory lab attendance ensures students engage with practical aspects of programming, reinforcing theoretical knowledge through hands-on practice. Group assignments cultivate collaborative skills, mirroring real-world software development environments where teamwork is essential. Together, these strategies enhance learning by integrating active participation and collaboration, fostering deeper understanding and application of programming concepts while developing interpersonal skills that are critical in professional settings .

Using an ArrayList to store shape objects offers great flexibility and ease in dynamically managing an assortment of shapes, allowing for easy additions and iterations over stored elements. Exception handling, via try/catch blocks, plays a critical role in managing user input, catching and addressing errors before they lead to program failures. This design improves usability and reliability by anticipating and handling potential input-related issues and ensuring that the program can recover or provide feedback when incorrect data is inputted by a user .

You might also like