Assignment 1
Assignment 1
Muhammad Usman
Reg # 64472
Assignment # 01
Page 1 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
Object Oriented
Course: Instructor: Sabah
Programming
Marks Allocated: 5 Marks Time Allocated: 01 Week
GA-2 Knowledge for
CLO – 2
CLO Allocated: GA Allocated: Solving Computing
(C3)
Problems
ASSIGNMENT # 01
Question # 01
You are required to Build a class hierarchy to represent different types of employees in a
company. The base class should be Employee, and it should be extended by two derived
classes: Manager and Developer.
The Employee class should also have a constructor to initialize the attributes and a
method displayDetails() that prints the employee's details.
The Manager class should inherit from Employee and have an additional attribute:
o department (String): The department the manager is in charge of.
The Manager class should override the displayDetails() method to include the
department information.
The Developer class should inherit from Employee and have an additional attribute:
o programmingLanguage (String): The programming language the developer
specializes in.
The Developer class should override the displayDetails() method to include the
programming language information.
Tasks:
1. Define the Employee class with the required attributes and methods.
2. Define the Manager and Developer classes that inherit from Employee, adding the
required attributes and methods.
Page 2 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
3. In the main class, create an array of Employee references that holds objects of both
Manager and Developer types. Iterate through the array and call displayDetails() on
each object.
package assignment;
class Employee {
private String name;
private int employeeId;
Page 3 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
}
class Main {
public static void main(String[] args) {
Question # 02
Develop a class BankAccount that represents a bank account. The class should include the
following:
Properties:
o accountNumber (String)
o balance (double)
Methods:
o A constructor that initializes the account with an account number and a
balance.
Page 4 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
o A method deposit(double amount) that deposits the specified amount into the
account.
o An overloaded method deposit(double amount, String message) that deposits
the specified amount into the account and prints a confirmation message.
o A method withdraw(double amount) that withdraws the specified amount from
the account if sufficient balance is available.
Tasks:
package assignment;
Page 5 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
} else if (amount > balance) {
System.out.println("Insufficient balance for withdrawal.");
} else {
System.out.println("Invalid withdrawal amount.");
}
}
account1.displayAccountDetails();
System.out.println();
account1.deposit(1500.00);
account1.displayAccountDetails();
System.out.println();
account1.withdraw(2500.00);
account1.displayAccountDetails();
System.out.println();
account1.wi thdraw(300
0.00);
account1.di splayAccou
ntDetails();
}
}
Page 6 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
Question # 03
Construct a JavaFX application in Eclipse that displays a registration form for a workshop.
The form should include the following components:
1. Labels for each field: "First Name", "Last Name", "Email", "Phone Number", and
"Workshop Selection".
2. Text fields for "First Name", "Last Name", "Email", and "Phone Number".
3. A ComboBox for "Workshop Selection" with the following options:
"Java Basics",
"Advanced Java",
"Web Development with JavaFX",
"Java for Mobile Applications".
4. A Submit Button that, when clicked, displays the entered information in a new
window.
Requirements:
Page 7 of 8
FACULTY OF ENGINEERING, SCIENCES AND TECHNOLOGY
Page 8 of 8