-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeachers.java
More file actions
142 lines (122 loc) · 3.55 KB
/
Teachers.java
File metadata and controls
142 lines (122 loc) · 3.55 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
import java.io.FileWriter;
import java.io.IOException; // Importing IOException class to handle errors
public class Teachers extends mySchoolManagementSystem {
/* private data members */
private String name;
private static int idCounter = 100;
private int myID;
private String subjectTeaches;
private double salary;
private boolean salaryPaidStatus;
/* Default contructor */
Teachers() {
name = "";
subjectTeaches = "";
myID = ++idCounter;
salary = 25000;
salaryPaidStatus = false;
}
/* Parameterized constructor */
Teachers(String name_, String Subject_) {
this.name = name_;
this.subjectTeaches = Subject_;
//below, all data feilds are set to default
myID = ++idCounter;
this.salary = 25000;
this.salaryPaidStatus = false;
}
//encapsulation --> setters /getters
public void setName(String name_) {
this.name = name_;
}
public void setSubject(String subject_) {
this.subjectTeaches = subject_;
}
public void setSalary(double salary_) {
this.salary = salary_;
}
public void setPaidStatus(Boolean status_) {
this.salaryPaidStatus = status_;
}
public String getName() {
return this.name;
}
public int getId() {
return this.myID;
}
public String getSubjectTeaches() {
return this.subjectTeaches;
}
public double getSalary() {
return this.salary;
}
public boolean getPaidStatus() {
return this.salaryPaidStatus;
}
public void updateMe() {
System.out.println("**** Update Teacher's Data Here ****");
System.out.print("Update Teacher's Name : ");
this.name = input.nextLine();
System.out.print("Update Subject He/She wanna teach : ");
this.subjectTeaches = input.nextLine();
System.out.println();
}
/**
* Over-ridden methods
* These method are inherited from abstract parent class
* Hence, Polymorphism is being used here.
*/
@Override
void menu() {
System.out.println("1. Display Teacher's Data");
System.out.println("2. Update Teacher's Data");
System.out.println("3. Delete Teacher's Data");
if (!this.salaryPaidStatus) {
System.out.println("4. Get your salary?");
}
}
@Override
void writeToFile() throws IOException {
// creating file writer object
FileWriter myObj = null;
try {
/*
creating file name 'Teachers.txt' 2nd parameter true
means, append the new data to existing file */
myObj = new FileWriter("Teachers.txt", true);
// As on console, we use print, to write in file, write is used
myObj.write(this.myID + "\n");
myObj.write(this.name + "\n");
myObj.write(this.subjectTeaches + "\n");
myObj.write(this.salary + "\n");
myObj.write(this.salaryPaidStatus + "\n");
}
/* Once data has been written to file, Now close the file */
finally {
try {
myObj.close();
}
/* In case any exception occurs. */
catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
@Override
void printData() {
System.out.println("\tTeacher's ID : " + this.myID);
System.out.println("\tTeacher's Name : " + this.name);
System.out.println("\tSubject Teaches : " + this.subjectTeaches);
System.out.println("\tTeacher's Salary : " + this.salary);
System.out.println("\tSalary Paid? : " + this.salaryPaidStatus);
System.out.println("\t\t -***- \n");
}
}
/*
1) name of teacher
2) idCounter of teacher
3) subject of teacher
4) Salary of the teacher.
6) Current salary status paid or not.
*/