Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Java Worksheet

The document provides instructions for three exercises on object-oriented programming concepts. The first exercise involves creating an abstract LibraryItem class and concrete Book, Magazine, and DVD classes to demonstrate polymorphism. The second exercise extends the first to add course enrollment functionality and integrate with a database. The third exercise similarly implements an online shopping system with abstract Product and concrete PhysicalProduct and DigitalProduct classes connected to a database.

Uploaded by

en a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Java Worksheet

The document provides instructions for three exercises on object-oriented programming concepts. The first exercise involves creating an abstract LibraryItem class and concrete Book, Magazine, and DVD classes to demonstrate polymorphism. The second exercise extends the first to add course enrollment functionality and integrate with a database. The third exercise similarly implements an online shopping system with abstract Product and concrete PhysicalProduct and DigitalProduct classes connected to a database.

Uploaded by

en a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

HiLCoE

School of Computer Science & Technology CS224 (OOP): Lab


Questions

Exercise 1: Library Management System


Task:

Create an abstract class named LibraryItem. This class should have properties for title and
borrowedDate. Also, it should have two abstract methods: displayInformation() and
calculateDueDate(). The displayInformation() method should be responsible for printing the
details about the library item, and the calculateDueDate() method should return the due date for
the item to be returned.
Now, create three classes: Book, Magazine, and DVD. Each class should inherit from the
LibraryItem class. Each of these classes should implement the displayInformation() and
calculateDueDate() methods:
The Book class should implement the displayInformation() method to print "Book title: " followed
by the book's title. The calculateDueDate() method should calculate the date two weeks (14
days) from the borrowed date.
The Magazine class should implement the displayInformation() method to print "Magazine title: "
followed by the magazine's title. The calculateDueDate() method should calculate the date one
week (7 days) from the borrowed date.
The DVD class should implement the displayInformation() method to print "DVD title: " followed
by the DVD's title. The calculateDueDate() method should calculate the date two days from the
borrowed date.
In the main method of your program, create an array of LibraryItem with at least one of each
type of item (book, magazine, and DVD). Loop over the array and for each item, call the
displayInformation() and calculateDueDate() methods.
This question is designed to test your understanding of the concepts of abstraction and
polymorphism in Java. The LibraryItem class is an example of an abstract class, and calling
methods like displayInformation() and calculateDueDate() on objects of type LibraryItem
demonstrates polymorphism.
Exercise 2: University Course Enrollment System with Database

Task:
Develop a Java program for managing course enrollment in a university using polymorphism,
and store the information in a database.

Instructions:
1. Set up a database with tables `Course`, `Student`, and `Professor`.
2. Define classes `Course`, `Student`, and `Professor` as before.
3. Modify the `Course` class to include methods that insert course information into the `Course`
table in the database, enroll students, and assign a professor.
4. In the `main` method, create instances of `Course`, `Student`, and `Professor`. Enroll
students in a course and assign a professor. Store the information in the database.

Exercise 3: Online Shopping System with Database

Task:
Create a Java program for an online shopping system using abstraction, and store the product
information in a database.

Instructions:
1. Set up a database with tables `Product`, `PhysicalProduct`, and `DigitalProduct`.
2. Define classes `Product`, `PhysicalProduct`, and `DigitalProduct` as before.
3. Modify the classes to include methods that insert product information into the respective
tables in the database and calculate the total price.
4. In the `main` method, create instances of `PhysicalProduct` and `DigitalProduct`. Calculate
and display the total price. Store product information in the database.

You might also like