Lab7-Abstract Class and Interface
Lab7-Abstract Class and Interface
LAB ASSIGNMENT 7
OBJECTIVE:
Learning Objective: Construct An Object-oriented Program Using Abstract and Interface
(P4)
DURATION:
1 week / 3 hours
SUBMISSION:
Please submit your assignment to your demonstrator containing the following materials:
- UML diagram
- Java source code
- List of the test data (if involved user input)
- Print screen of the output.
1
SSK3101 Update : 20 May 2021
QUESTION 1:
3. Create an empty main() method (the body of the main method should be empty).
Make sure you can compile without error.
6. Remove the first and second lines (marked with ‘//**’) and recompile your
program. Your program should be successfully compiled.
7. Explain:
QUESTION 2:
2
SSK3101 Update : 20 May 2021
class must print out a text indicating the name or the type of the Shape e.g. an
object of class Triangle should display “A Triangle”.
9. Explain:
QUESTION 3:
3. (Design and implement abstract class and interface from a specified problem)
You are assigned a task to develop a multi-level menu system for an application. The
menu system contains the following structure:
1-File
1-- New
2-- Open
3-- Close
4-- Print
2- Edit
3- Help
1-- Info
2-- About
In the main menu, user should be given the 3 options – File, Edit, Help. If user choose
File, she will be shown the options New, Open, Close, Print. If user choose New then
display “choose New”, or “choose Open” for Open and so on. If user choose Edit, display
“choose Edit”. If User choose Help, display the options Info and About. User can exit
anytime by choosing 0. For example, the following output in Figure 1 shows an example
of a user using the menu system in command prompt:
3
SSK3101 Update : 20 May 2021
<continue…>
Figure 1 Figure 1 (cont.)
Develop the menu system by implementing the concept of abstract class or interface. You
may also use other Java features you already learned - array, looping, if-else statement,
etc.
(Tips: A menu can be represented by a class Menu. A menu item is contained by a menu
or a sub menu. A sub menu is a menu and also a menu item, thus should derive features
from Menu and Menu Item. )