OOP Assignment 1
OOP Assignment 1
Assignment:1
Task#1:
Create a program to initialize employee details with different parameters
using constructor overloading, and test it using a separate class.
Task Details:
1. Define a class Employee with the following attributes:
• String name
• int id
• double salary
• String department
2. Constructor Overloading:
• Default Constructor: Initializes name to "Unknown", id to 0, salary to 0.0,
and department to "Not Assigned".
• Parameterized Constructor (1): Takes only name and id as
parameters and initializes salary and department with default values.
• Parameterized Constructor (2): Takes name, id, and salary as parameters
and sets department to "Not Assigned".
• Full Parameter Constructor: Takes all four attributes as parameters and
initializes each attribute.
3. Method: displayInfo()
Task Details:
1. Define a class BankAccount with the following attributes:
• String accountHolder
• String accountNumber
• double balance
• String accountType (such as "Savings" or "Current")
2. Constructor Overloading:
• Default Constructor: Initializes accountHolder to "Unknown",
accountNumber to "0000", balance to 0.0, and accountType to
“Savings".
• Parameterized Constructor (1): Accepts only accountHolder and
accountNumber and initializes balance to 0.0 and accountType to
“Savings".
• Full Parameter Constructor: Takes all four attributes as parameters and
initializes each one.
3. Method: deposit (double amount)
Objective: Create a Product class for managing inventory, including an update method.
Test the functionality with a test class.
Tasks:
2. Constructors:
• Implement a default constructor that sets attributes to default values.
• Implement a parameterized constructor that accepts initial values for all
attributes.
Method:
• Write an update_Quantity () method that adjusts the quantity based on an
action ("add" or "remove"). Ensure that quantity does not go below zero.
Test Class:
Create a separate test file, ProductTest.java.
Use a loop to add or remove products: prompt the user to enter product
details and specify an action.
After each update, display the updated inventory.
Exit the loop if the user chooses not to manage more products.
1. Class Definition: Define an Employee class with attributes name, id, salary,
and performanceScore.
2. Constructors:
• Write a default constructor that initializes each attribute to default
values. • Write a parameterized constructor to set all attributes.
3. Method:
• Implement a calculateBonus() method that returns a bonus percentage of
salary based on performanceScore:
• 90 and above: 20%
• 70–89: 10%
• Below 70: 5%
4. Test Class:
• Create a separate test file, EmployeeTest.java.
• Use a loop to process multiple employees: prompt the user for name, id,
salary, and performanceScore.
• Calculate and display each employee’s bonus and total salary (salary + bonus).
Lab Task 5: