Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

QestionPaPer

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

COMSATS University Islamabad

Lahore Campus, Defence Road, Off Raiwind Road Lahore


Ph: 042-99203109 Fax: 042-99205253
Department of Electrical and Computer Engineering
Terminal Lab Examination – Spring 2024
Course Title: Object Oriented Programming Course Code: CSC241 Credit Hours: 4(3,1)

Course Instructor/s: Munawar ul Zaman Programme Name: BSEE

Semester: Batch: Fall-2023 Section: C Date: Dec 18, 2024


Time Allowed: 180 Minutes Maximum Marks: 50

Student’s Name: Reg. No. FA -BEE-

Important Instructions / Guidelines:

• Write your name and Student registration No. clearly on the first page.
• All Lab Tasks are compulsory.
• Internet access and mobile phones are not allowed during. However, internet access on Lab systems
will be provided during last 10 minutes to upload the files on Google classroom.
• The first line of your each Java app (class with main method) should include the following line as a
first line in its main method. Where xxx is the last three digits of your Registration id.
System.out.println("Name: " + "Your Full Name" + " Reg. No: " + "FA23-BEE-xxx");

You are instructed to build an application for the shopping mart. In this regard, proceed through following tasks
to build an app.

Workspace

[CLO4-PLO5-P4]: (4 Points)
For this terminal lab exam,
1. Create a new folder in D:\ (or any drive except C:\ drive) and rename it as Terminal_FA23BEE. Here
2. Open IDE IntelliJ Idea. Start a New Project, name it as LABTERMINAL and select location in
Terminal_FA23BEE.
3. Right click on src folder of the newly created project LABTERMINAL., select New, then Package. Name
the new package as your registration id without dashes or hyphen ( - ). For example, for a student with
his/her id FA23-BEE-001, the package should be named as: FA23BEE001. This package will be considered
as base package for all other packages in your exam.
4. Create subpackage task1: Create a subpackage task1 within the base package (eg. FA23BEE001.task1)
5. Create subpackage task2: Create a subpackage task2 within the base package (eg. FA23BEE001.task2)
6. Create subpackage task3: Create a subpackage task3 within the base package (eg. FA23BEE001.task3)
7. Create subpackage task4: Create a subpackage task4 within the base package (eg. FA23BEE001.task4)

Page 1 of 6
8. Remove Main.java file. You will create test class later.

Java Basics

Task 1: [CLO4-PLO5-P4]: (10 Points)


Perform the following steps in Task 1.

Preparation for Task 1


You will use subpackage task1 for this task.

Create base classes


• class ProductEntity:
o Create class ProductEntity in subpackage task1.
o Add following attributes to class ProductEntity:
▪ private double attributes: id
▪ private String attribute: name
▪ private double attribute: price
▪ private int attribute: numAvailableInStock,
o add fully parameterized constructor method.
o add getter and setter methods for private attributes.
o override toString() method to display readable information
• class CustomerEntity:
o Create class CustomerEntity in subpackage task1.
o Add following attributes to class CustomerEntity:
▪ private double attributes: id
▪ private String attribute: name and phone
▪ private double attribute: currentPurchaseBill
o add fully parameterized constructor method.
o add getter and setter methods for private attributes.
o override toString() method to display readable information

Page 2 of 6
Inheritance and Polymorphism

Task 2: [CLO4-PLO5-P4]: (13 Points)


Perform the following steps in Task 2.

Preparation for Task 2


• You will use subpackage task2 for this task.
• Copy the base class: From Project explorer on the right of IntelliJ IDE, copy ProductEntity.java (i.e. class
ProductEntity) from subpackage task1 and paste it in subpackage task2

Convert class ProductEntity to an abstract class


• make ProductEntity an abstract class: public abstract class ProductEntity
• Add following abstract method:
o public abstract boolean isLowInStock ();

Create subclasses from class ProductEntity


• class GroceryItem: create class GroceryItem derived from class ProductEntity in subpackage task2.
o Add following attributes to class GroceryItem:
▪ private String attribute: company, category
▪ private int attribute: minStockThreshold
▪ private final double attribute with value of 98: maxStockThreshold
o Add fully parameterized constructor method which must also call ProductEntity’s constructor
using super.
o Add getter and setter methods for private attributes.
o Implement (Override) inherited abstract method isLowInStock () which must return true if
(numAvailableInStock − minStockThreshold ≤ 0), otherwise false.
• class BakeryItem: create class BakeryItem derived from class ProductEntity in subpackage task2.
o Add following attributes to class BakeryItem:
▪ private String attribute: supplier, category
▪ private double attribute: weightInPounds
▪ private final double attribute with value of 10: maxStockThreshold
o add fully parameterized constructor method which must also call constructor of ProductEntity
using super.
o add getter and setter methods for private attributes.
o Implement (Override) inherited abstract method isLowInStock () which returns true if
(numAvailableInStock ≤ maxStockThreshold/2), otherwise false
Create test class
• Create ShoppingMartTask2 class with main() method
• Create one objects of the GroceryItem class with the following details.
Reference Constructor
Variable Name GroceryItem(id, name, price, numAvailableInStock, company, category,
minStockThreshold)
grocery1 GroceryItem(1, "Rooh-Afza", 750, 95, "Hamdard", "Soft Drinks", 5)

Page 3 of 6
• Create one objects of the BakeryItem class with the following details.
Reference Constructor
Variable Name BakeryItem(id, name, price, numAvailableInStock, supplier, category,
weightInPounds)
bakery1 BakeryItem( 2, "Butter-Puff", 150, 8, "ABC", "Pastry", 0.1)

• Create reference variable named productEntity of base class ProductEntity to demonstrate


polymorphism by printing respective stock status (by calling isLowInStock mehtod) of the two product
objects

Interfaces

Task 3: [CLO4-PLO5-P4]: (13 Points)


Perform the following steps in Task 3.

Preparation for Task 3


• You will use subpackage task3 for this task.
• Copy the classes from task2: From Project explorer on the right of IntelliJ IDE, copy following files from
subpackage task2 and paste them in subpackage task3
o ProductEntity.java (i.e. class ProductEntity)
o GroceryItem.java (i.e. class GroceryItem)
o BakeryItem.java (i.e. class BakeryItem)
• Copy the class from task1: From Project explorer on the right of IntelliJ IDE, copy CustomerEntity.java
(i.e. class CustomerEntity) from subpackage task1 and paste it in subpackage task3

Create interface Promotions

• interface Promotions:
o Create interface Promotions in subpackage task3.
o Add public final double attribute with value 2.0: flatDiscountPercent
o Add method public void applyPromoDiscount(double discountPercent);
o Add method public void applyFlatDiscount();

Modify class BakeryItem so that it implements interface Promotions

• Modify BakeryItem so that it implements interface Promotions


• Add definition for interface method – public void applyPromoDiscount(double discountPercent) – in class
BakeryItem to reduce is price by discountPercent using formula 𝑝𝑟𝑖𝑐𝑒 = 𝑝𝑟𝑖𝑐𝑒 − (𝑝𝑟𝑖𝑐𝑒 ∗
𝑑𝑖𝑠𝑐𝑜𝑢𝑛𝑡𝑃𝑒𝑟𝑐𝑒𝑛𝑡)
• Add definition for interface method – public void applyFlatDiscount() – in class BakeryItem to reduce is
price by flatDiscountPercent using formula 𝑝𝑟𝑖𝑐𝑒 = 𝑝𝑟𝑖𝑐𝑒 − (𝑝𝑟𝑖𝑐𝑒 ∗ 𝑓𝑙𝑎𝑡𝐷𝑖𝑠𝑐𝑜𝑢𝑛𝑡𝑃𝑒𝑟𝑐𝑒𝑛𝑡)

Create subclass from class CustomerEntity which also implements interface Promotions
• class RetailCustomer: create class RetailCustomer in subpackage task3 which is derived from class
CustomerEntity and implements interface Promotions
o Add following attributes to class RetailCustomer:

Page 4 of 6
▪ private int attribute: trustScore
▪ private String attribute: badge
o add fully parameterized constructor method.
o add getter and setter methods for private attributes.
o Add definition for interface method – public void applyPromoDiscount(double discountPercent)
– in class RetailCustomer to reduce is price by discountPercent using formula
currentPurchaseBill = currentPurchaseBill − (currentPurchaseBill ∗ 𝑑𝑖𝑠𝑐𝑜𝑢𝑛𝑡𝑃𝑒𝑟𝑐𝑒𝑛𝑡)
o Add definition for interface method – public void applyFlatDiscount() – in class RetailCustomer
to reduce is price by flatDiscountPercent using formula currentPurchaseBill =
currentPurchaseBill − (currentPurchaseBill ∗ 𝑓𝑙𝑎𝑡𝐷𝑖𝑠𝑐𝑜𝑢𝑛𝑡𝑃𝑒𝑟𝑐𝑒𝑛𝑡)

Generics and Collections

Task 4: [CLO4-PLO5-P4]: (10 Points)


Perform the following steps in Task 4.

Preparation for Task 4


• You will use subpackage task4 for this task.
• Copy classes/interface from task3: From Project explorer on the right of IntelliJ IDE, copy following files
from subpackage task3 and paste them in subpackage task4
o BakeryItem.java (i.e. class BakeryItem)
o GroceryItem.java (i.e. class GroceryItem)
o ProductEntity.java (i.e. class ProductEntity)
o Promotions.java (i.e. interface Promotions)

Create class ShoppingCart


• class ShoppingCart: create class ShoppingCart in subpackage task4
o Add following attributes to class ShoppingCart:
▪ public ArrayList of GroceryItem’s objects
▪ public ArrayList of BakeryItem’s objects
▪ private int attribute: customerId
o add constructor method with private attributes in argument.
o add getter and setter methods for private attributes.

Create test class


• Create ShoppingMartTask4 class with main() method
• Create object of class ShoppingCart in reference variable myCart – use dummy values in constructor
• Create 3 objects of the GroceryItem class and add them to ArrayList of GroceryItem in the myCart –
use dummy values in constructor
• Create 3 objects of the BakeryItem class and add them to ArrayList of BakeryItem in the myCart - use
dummy values in constructor

P.T.O

Page 5 of 6
• In ShppingMartTask4 class, if we add the following method, it will print details of objects in ArrayList
of myCart:

public static void printRecords(ArrayList< GroceryItem > arr) {


for(GroceryItem obj: arr)
System.out.println(obj);
}

Modify it so that it become generic and accepts an ArrayList of objects of any type (e.g. GroceryItem
and BakeryItem objects). Furthermore, use this generic method to print objects details of both
ArrayLists (an ArrayList of GroceryItem and an ArrayList of GroceryItem). Override toString()
methods where necessary in order to display readable information.

Submission Folder Instructions:


• Click on the base package of task1, task2 and task3 (e.g., FA23BEExxx) under src folder
of the project LABTERMINAL. Select FA23BEExxx ➔ Open In ➔ Explorer.
• The Package folder (e.g., FA23BEExxx) will open Windows File Explorer.
• Zip the folder (e.g., FA23BEExxx) and upload the zipped file through the Google Classroom
Link.

Good Programming Practices to Obtain the Max Credit:


• Zip file containing the source code files is submitted as per given instructions.
• The source code compiles and run with no warnings or errors.
• The source code aligns with the Programs Specifications as defined in the respective tasks’
descriptions and the programming style, including code readability, variable naming, and
commenting, adheres to acceptable standards.

Good Luck ☺

Page 6 of 6

You might also like