SI (Lab Exam) : COMSATS Institute of Information Technology, Lahore

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Student’s Name: _________________________ ID: ________________________

COMSATS Institute of Information Technology, Lahore


Department of Computer Science
SI (Lab Exam)
Course Title: Object Oriented Programming Lab Instructor: Shahid Bhatti
Course Code: CSC 241 Credit hours: 4(3, 1)
Class: BCS-FA10 Semester: Spring 11
Max Marks: 10 Contribution in final: 10%

Develop software for the Book shop. The software is very simple and may consist of a
single class only (i.e. no need to write the test class). The shopkeeper wants to record the
only the following attributes regarding each book:

1. Book Id
2. Title of the Book
3. Category of the Book
4. Unit Price of the Book
5. Quantity of the Book
6. Total Revenue

Following methods are required

1. Constructors
2. Getters and Setters Methods
3. isAvailable
4. Sale a Book
5. Print Total Revenue
6. Overload toString equals
7. Overload equlas method.

Detail of Methods:

Constructor:
It should be used to initialize the instance variables. Book Id should be assigned
automatically starting from 1 and incrementing by one onwards. Category of the book is
an optional attribute. Assign “Category Not Available” as default.

Getters and Setters Methods


All the attributes as must be declared private, and methods as public. Provide
getter and setter methods for all private attributes.

isAvailable Method
Returns false if the quantity of the book is zero, and true otherwise.

Page 1 of 2
Student’s Name: _________________________ ID: ________________________

Sale a Book:
The following points must be kept in mind while selling a book:-
 The caller will pass the quantity of the book he wants to sell.
 If the quantity is less than the requested amount, print a message that requested
book is short of stock and return false, otherwise decrement the quantity of the
desired book and return true.
 Increment the total revenue.

Print Total Revenue:


Print amount of the total revenue generated through sales so far.

toString Method
Return the String in the following format
“Detail of the Book
-------------------------
Book Id = <value>
Book Title = <value>
Book Category = <value>
Unit Price = <value>
Quantity in Stock = <value>”

equals Method
Two books are equal only if title and category is equal.

Note:
 Use proper naming conventions of java.
 Code must be properly indented
 Write appropriate comments
 Perform proper error handling in the Book class or the test class.

Submittion Details:

Write the test class yourself to ensure that all the functions are written correctly.
A viva vice will be conducted from every individual student during the scheduled lab of
their respective section. That’s why make sure this program is in your z-drive before the
lab. You may also have a back up in the USB disk drive.

Page 2 of 2

You might also like