Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/main/java/org/codedifferently/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.codedifferently;

// Concrete Person type used for employees whose work hours are tracked.
public class Employee extends Person {
// Running total of employee hours.
private double hoursworked;

// Builds an employee with profile data plus starting hour balance.
public Employee(int id, String firstname, String lastname, String email, double hoursworked){
super(id, firstname, lastname, email);
this.hoursworked=hoursworked;
}

@Override
// Returns a formatted, multi-line summary used by the menu print options.
public String getSummary(){
return "[Employee]" + " " + getFirstname() + " " + getLastname() + "\n"
+ "ID: " + getId() + "\n" + "Hours Worked" + " " + hoursworked;
}

// Replaces the current hour total with a new total.
public void setHoursWorked(double hoursworked) {
this.hoursworked = hoursworked;
}

// Returns the current hour total.
public double getHoursworked() {
return hoursworked;
}
}

56 changes: 56 additions & 0 deletions src/main/java/org/codedifferently/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.codedifferently;

// Base abstraction for every person record in the system.
// Shared identity/contact fields live here, while child classes define custom summaries.
public abstract class Person {
// Unique identifier used for login/lookup.
private int id;
// Basic profile values shared by all roles.
private String firstname;
private String lastname;
private String email;

// Constructor initializes all shared Person data at object creation time.
public Person(int id, String firstname, String lastname, String email){
this.id=id;
this.firstname=firstname;
this.lastname=lastname;
this.email=email;

}
// Setters allow future updates to profile data.
public void setLastname(String lastname) {
this.lastname = lastname;
}

public void setId(int id) {
this.id = id;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setEmail(String email) {
this.email = email;
}
// Getters expose read-only access to stored profile values.
public String getLastname() {
return lastname;
}

public String getFirstname() {
return firstname;
}

public int getId() {
return id;
}

public String getEmail() {
return email;
}

// Each subclass provides its own summary.
public abstract String getSummary();
}
48 changes: 48 additions & 0 deletions src/main/java/org/codedifferently/siteManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.codedifferently;

import java.util.ArrayList;

// Manager role that tracks on-site location and a list of assigned employees.
public class siteManager extends Person{
// Current location text for this manager.
private String location;
// Employees currently assigned to this manager/site.
private ArrayList<Employee> employeesonsite;
// Counter used when printing summary details.
private int totalemployees;

// Initializes manager profile, location, and an empty employee list.
public siteManager(int id, String firstname, String lastname, String email, String location){
super(id, firstname, lastname, email);
this.location=location;
this.employeesonsite= new ArrayList<>();
this.totalemployees=totalemployees;
}

public void setLocation(String location) {
this.location = location;
}

public String getLocation() {
return location;
}

// Adds an employee object to the manager's on-site roster.
public void addemployee(Employee employee){
employeesonsite.add(employee);
}
@Override
// Prints each employee summary and manager details, then returns a total count label.
public String getSummary() {
for (Employee e : employeesonsite) {
++totalemployees;
System.out.println("\n" + e.getSummary());
System.out.println("[Site Manager]" + getFirstname() + " " + getLastname()
+ "\n" + " Location: " + location);

}
return "Total employees" + " " + totalemployees;

}

}