KEMBAR78
Sample Class Test Question 1 OOP Lab | PDF
0% found this document useful (0 votes)
29 views2 pages

Sample Class Test Question 1 OOP Lab

The document outlines a lab assignment for a Computer Science course at United International University, focusing on Object-Oriented Programming. It includes tasks to create a Product class for an online shopping cart simulation and a BankAccount class for managing bank transactions. Students are required to implement methods for calculating total prices, depositing, withdrawing, and transferring money, along with displaying account information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Sample Class Test Question 1 OOP Lab

The document outlines a lab assignment for a Computer Science course at United International University, focusing on Object-Oriented Programming. It includes tasks to create a Product class for an online shopping cart simulation and a BankAccount class for managing bank transactions. Students are required to implement methods for calculating total prices, depositing, withdrawing, and transferring money, along with displaying account information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

United International University (UIU)

Dept. of Computer Science & Engineering (CSE)


Summer Trimester: 2024
CT-1
CSI 1116: OOP LAB

Q1. You are simulating an Online Shopping Cart.

 Create a class named Product with instance variables name, price, and quantity.
 Initialize these attributes using a constructor.
 Implement a method getTotalPrice() to calculate the total price for the product.

 Take User Input and Perform Calculations in the Main Method:

 Create an array of Product objects to hold the products.


 Create 5 Product objects with values of your choice.
 Add each Product object to the array.
 Calculate the total bill by summing the total prices of all products in the array.
 Print the total bill to the console.

Q2. Create a class named BankAccount that has the following four attributes.
 bankName (String)
 accountName (String)
 balance (double)
 accountNumber (int)
a) Create two constructors:
i. The first constructor is a default constructor that only prints “Welcome to the Bank
Account System”
ii. The second constructor will take three parameters named accountNumber, accountName,
and balance and initialize the instance variables using this reference.

b) Create the following methods:


 Deposit(double amount): Add the amount to the balance and print a message
indicating the amount deposited.
 Withdraw(double amount): Subtract the amount from the balance if sufficient funds
are available; otherwise, print a message indicating insufficient funds.
 DisplayAccountInfo(): Display detailed information about the bank account.
 TransferMoney(BankAccount b, double amount): Transfer the given amount to
the BankAccount b given in the parameter, also keep check for insufficient balance and
print a message if insufficient.

c) Create another class named Bank. This class contains the main method of the file.
d) Create two instances of BankAccount objects for two different constructors.

● Perform the following tasks:


1. Deposit money into an account
2. Withdraw money from an account
3. Transfer money from a BankAccount to another
4. Display account information after each operation

You might also like