-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeacher.java
44 lines (35 loc) · 1.2 KB
/
Teacher.java
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
import java.io.PrintWriter;
public class Teacher implements CSVPrintable{
private String name;
private int studentID;
private int teacherID;
private long longPhone;
private int phone;
public Teacher(String name, int studentID, int teacherID, long phone){
this.name = name;
this.studentID = studentID;
this.teacherID = teacherID;
longPhone = phone;
}
public String getName(){
return name;
}
public int getID(){
return teacherID;
}
public int getPostfix(){
//method to get postfix(last four digits of phone)
String temp = String.valueOf(longPhone);
int postfix = (int) Long.parseLong(temp.substring(6,10));
return postfix;
}
public void csvPrintln(PrintWriter out){
//this method parses entry in correct format
StringBuilder sb = new StringBuilder();
String nameWithoutComma = getName();
nameWithoutComma = nameWithoutComma.replace(",", " ");
sb.append(nameWithoutComma + "," + getID() + "," + getPostfix());
sb.append("\n");
out.write(sb.toString());
}
}