Professional Documents
Culture Documents
Lab4 Oop
Lab4 Oop
Lab4 Oop
Faculty of Computing
LAB 4
(Object Oriented Programming)
Subject : SECR1033
Code
Subject : Computer Organization & Architecture
Name
Session-Sem : 2022/2023-2
import java.util.ArrayList;
employee works.
IV. position: a string that holes the employee's job title.
number.
VI. A constructor that accepts the following values as arguments and
VIII. appropriate accesor method that return the value in these member
variables
public class Employee {
public Employee() {
this.name = null;
this.idNumber = 0;
this.department = null;
this.position = null;
}
// Mutator Methods
public void setName(String name) {
this.name = name;
}
// Accessor Methods
public String getName() {
return name;
}
employee1.setName("John Doe");
employee1.setIdNumber(12345);
employee1.setDepartment("IT");
employee1.setPosition("Software Engineer");
II. Create an object from class Arraylist and populate it with the Employee
objects using method add () .
// ii. Create an object from class ArrayList and populate it with
Employee objects using method add().
ArrayList<Employee> employeeList = new ArrayList<>();
employeeList.add(emp1);
employeeList.add(emp2);
employeeList.add(emp3);
employeeList.add(emp4);
employeeList.add(emp5);
IV. Invoke other available methods from class ArrayList such as: contains (),
VII. Appropriate accessor functions that return the values in the attributes
// Constructors
// No-argument constructor
public Student() {
// Default values
this.name = "";
this.age = 0;
this.majoring = "";
this.country = "";
}
// Mutator methods
public void setName(String name) {
this.name = name;
}
// Accessor methods
public String getName() {
return name;
}
// Example Usage
public static void main(String[] args) {
// Creating an instance of the Student class using no-argument
constructor
Student student1 = new Student();
// Constructors
// No-argument constructor
public Student() {
// Default values
this.name = "";
this.age = 0;
this.majoring = "";
this.country = "";
}
// Mutator methods
public void setName(String name) {
this.name = name;
}
// Accessor methods
public String getName() {
return name;
}
// Example Usage
public static void main(String[] args) {
// Creating an instance of the Student class using no-
argument constructor
Student student1 = new Student();