-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudents.java
More file actions
134 lines (115 loc) · 3.41 KB
/
Students.java
File metadata and controls
134 lines (115 loc) · 3.41 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
import java.io.FileWriter;
import java.io.IOException; // Importing IOException class to handle errors
/* Class Teacher being inherited from abstract class*/
public class Students extends mySchoolManagementSystem {
/* private data members */
private String name;
private static int idCounter = 1000;
private int myID;
private char grade; //A,B,C,D or F
private double totalFee;
private boolean feePaidStatus;
/**Default Constructor */
Students() {
name = "";
myID = ++idCounter;
grade = 'A';
totalFee = 30000;
feePaidStatus = false;
}
/*Parameterized Constructor */
Students(String name_, char grade_) {
name = name_;
grade = grade_;
myID = ++idCounter;
totalFee = 30000;
feePaidStatus = false;
}
//encapsulation --> setters /getters
public void setName(String name) {
this.name = name;
}
public void setGrade(char grade) {
this.grade = grade;
}
public void setTotalFee(double totalFee) {
this.totalFee = totalFee;
}
public void setFeePaidStatus(boolean feePaidStatus) {
this.feePaidStatus = feePaidStatus;
}
public String getName() {
return this.name;
}
public int getId() {
return this.myID;
}
public char getGrade() {
return this.grade;
}
public double getTotalFee() {
return this.totalFee;
}
public boolean getFeePaidStatus() {
return this.feePaidStatus;
}
public void updateMe() {
System.out.println("**** Update Student's Data Here ****");
System.out.print("Update Student's Name : ");
this.name = input.nextLine();
System.out.print("Update Student's Grades : ");
this.grade = input.next().charAt(0);
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 Student's Data");
System.out.println("2. Update Student's Data");
System.out.println("3. Delete Student's Data");
if (!this.feePaidStatus) {
System.out.println("4. Fee not yet Paid, Pay your fee.");
}
}
@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("Students.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.grade + "\n");
myObj.write(this.feePaidStatus + "\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("\tStudent's ID : " + this.myID);
System.out.println("\tStudent's Name : " + this.name);
System.out.println("\tStudent's Grade : " + this.grade);
System.out.println("\tStudent's Fee : " + this.totalFee);
System.out.println("\tFee Paid? : " + this.feePaidStatus);
System.out.println("\t\t -***- \n");
}
}
/* 1) name of student
2) idCounter of student
3) grade of student
4) total fees of the student.
5) current fees status paid or not. */