-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay19.java
More file actions
143 lines (126 loc) · 3.9 KB
/
Day19.java
File metadata and controls
143 lines (126 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// ---------------------------------------------------
// Author : Benjamin Kataliko Viranga
// Community : Stunt Business
// Community website : www.stuntbusiness.com
//
// 30 Days - Q&A Java basic
// Day 19 : Mini Store : Employees, Items and the Store | Employees.
// Day 19 | IG : https://www.instagram.com/benjivrik/
// ----------------------------------------------------
// what would be the output of this program ?
/**
* Create an object Employee
* Give your employee a name, an ID and a Salary
* Give your employee to know if is working or not.
*/
class Employee
{
private static int totalEmployee = 0;
private String employeeName;
private String employeeID;
private double employeeSalary;
private boolean isWorking;
public Employee(String employeeName, double employeeSalary)
{
// increment the instance number
this.totalEmployee++;
// employee not working
this.isWorking = false;
// Assuming their ID will be their instance number (totalEmployee)
this.employeeID = Integer.toString(this.totalEmployee);
//
this.employeeName = employeeName;
this.employeeSalary = employeeSalary;
}
// a function for the updating the status of the employee
public boolean status()
{
if(this.isWorking)
{
this.isWorking = false;
System.out.println(this.employeeName +" is no longer working.");
}
else
{
this.isWorking = true;
System.out.println(this.employeeName +" is currently working.");
}
return this.isWorking;
}
// getters
public boolean getWorkStatus()
{
return this.isWorking;
}
public String getName()
{
return this.employeeName;
}
public double getSalary()
{
return this.employeeSalary;
}
public String getID()
{
return this.employeeID;
}
// setters
public void setName(String employeeName)
{
this.employeeName = employeeName;
}
public void setID(String employeeID)
{
this.employeeID = employeeID;
}
public void setSalary(double employeeSalary)
{
this.employeeSalary = employeeSalary;
}
// the number of employee created.
public int getEmployeeNumber()
{
return this.totalEmployee;
}
// for displaying your object
public String toString()
{
System.out.println("\n************** DISPLAYING EMPLOYEE INFO **************\n");
String employee = String.format(
"\nEmployee name : %s\nEmployee ID : %s\nEmployee Salary : %s CAD per hour\n",this.employeeName,this.employeeID,this.employeeSalary
);
return employee;
}
}
public class Day19
{
public static void main(String[] args)
{
Employee emp = new Employee("Jivrik",21.5);
// display the employee info
System.out.println(emp);
// to create a delay of 2 seconds and see the effect of the employee
try
{
emp.status();
Thread.sleep(3000);
emp.status();
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
System.out.printf("\nChanging the salary of %s\n", emp.getName());
// change the salary of your employee using your setter
emp.setSalary(22.5);
// display the employee info
System.out.println(emp);
System.out.println("Creating a new Employee");
// create a second object employee and display the number of existing employees
emp = new Employee("Vrik",24);
System.out.println(emp);
// print the number of Employee's object created.
System.out.printf("\nThe total number of existing employees is %d\n", emp.getEmployeeNumber());
System.out.println("\nEnd of program.");
}
}