-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
156 lines (127 loc) · 3.8 KB
/
Student.java
File metadata and controls
156 lines (127 loc) · 3.8 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
144
145
146
147
148
149
150
151
152
153
154
155
156
/* Student
* Created by: Johnson Duong
* Updated on: 2019/05/21
* The Student Account class
*/
import java.io.*;
import java.util.*;
public class Student
{
//instance variables
private String username;
private String password;
private String teacherPath;
private int stagesUnlocked;
private float accuracy;
private int topTypeSpeed;
private ArrayList<Integer> typeSpeedArray = new ArrayList<Integer>();
//first constructor for the creation of a new Student
public Student(String username, String password, String teacher)
{
this.username = username;
this.password = password;
this.teacherPath = teacher+"Class//"+username+".tta";
this.stagesUnlocked = 1;
this.accuracy = 0;
this.topTypeSpeed = 0;
this.typeSpeedArray.add(0);
this.createAccount();
}//end first constructor
//second constructor for an existing Student
public Student(String username, String password, int stagesUnlocked, float accuracy, int topTypeSpeed, ArrayList<Integer> typeSpeedArray, String teacherName)
{
this.username = username;
this.password = password;
this.stagesUnlocked = stagesUnlocked;
this.accuracy = accuracy;
this.topTypeSpeed = topTypeSpeed;
this.typeSpeedArray = typeSpeedArray;
this.teacherPath = teacherName;
System.out.println(teacherPath);
}//end second constructor
//accessor method to get password
public String getPassword()
{
return this.password;
}//end getPassword
//accessor method to get the number of unlocked stages
public int getStagesUnlocked()
{
return this.stagesUnlocked;
}//end getStagesUnlocked
//accessor method to get the user's accuracy
public float getAccuracy()
{
return this.accuracy;
}//end getAccuracy
//accessor method to get the top type speed
public int getTopTypeSpeed()
{
return this.topTypeSpeed;
}//end getTopTypeSpeed
//accessor method to get the list of type speeds
public ArrayList<Integer> getTypeSpeedArray()
{
return this.typeSpeedArray;
}//end getTypeSpeedArray
//gets input from a model and changes the password
public void changePassword(String newPassword)
{
this.password = newPassword;
//outputs updated information to the Student account file
this.createAccount();
}//end changePassword
//gets a type speed from a model and adds it into the Student account's file
public void addTypeSpeed(int typeSpeed)
{
this.typeSpeedArray.add(typeSpeed);
//replaces the current top type speed with the new speed if it is faster
if(typeSpeed > topTypeSpeed)
{
this.topTypeSpeed = typeSpeed;
}//fi
//outputs updated information to the Student account file
this.createAccount();
}//end addTypeSpeed
//creates a Student Account file containing the user's data
private void createAccount()
{
try
{
File studentFile = new File(this.teacherPath);//CHANGE PATH
PrintWriter out = new PrintWriter(studentFile);
//outputs Student information into a text file in the following order
out.println(this.password);
out.println(this.stagesUnlocked);
out.println(this.accuracy);
out.println(this.topTypeSpeed);
for(Integer i : this.typeSpeedArray)
{
out.print(i + " ");
}//rof
out.close();
}
catch(FileNotFoundException ex)
{
System.out.println("NOT DONE");
}
}//end createAccount
public String getUserName()
{
return this.username;
}
public void unlockNextStage()
{
if(this.stagesUnlocked<10)
{
this.stagesUnlocked++;
this.createAccount();
}
}
public void addAccuracy(int accuracyToAdd)
{
int sessions = this.typeSpeedArray.size();
float newAccuracy = ((this.accuracy*(sessions-2))+accuracyToAdd)/(float)((sessions-1)*1.0);
this.accuracy=newAccuracy;
}
}//ssalc