QestionPaPer
QestionPaPer
QestionPaPer
• 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
Page 2 of 6
Inheritance and Polymorphism
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)
Interfaces
• 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();
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 ∗ 𝑓𝑙𝑎𝑡𝐷𝑖𝑠𝑐𝑜𝑢𝑛𝑡𝑃𝑒𝑟𝑐𝑒𝑛𝑡)
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:
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.
Good Luck ☺
Page 6 of 6