Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. Assignemnets.java
  2. abstract public class Assignment {
  3. String assignmentName;
  4. int section , essay1 ,test1 , essay2 , test2 , finalGrade;
  5.  
  6. System.outprintln("Program 7: Class Stats by Alexandra Ott.")
  7.  
  8. public String getAssignmentName() {
  9. return assignmentName;
  10. }
  11.  
  12. public void setAssignmentName(String assignmentName) {
  13. this.assignmentName = assignmentName;
  14. }
  15.  
  16. public int getSection() {
  17. return section;
  18. }
  19.  
  20. public void setSection(int section) {
  21. this.section = section;
  22. }
  23.  
  24. public int getEssay1() {
  25. return essay1;
  26. }
  27.  
  28. public void setEssay1(int essay1) {
  29. this.essay1 = essay1;
  30. }
  31.  
  32. public int getTest1() {
  33. return test1;
  34. }
  35.  
  36. public void setTest1(int test1) {
  37. this.test1 = test1;
  38. }
  39.  
  40. public int getEssay2() {
  41. return essay2;
  42. }
  43.  
  44. public void setEssay2(int essay2) {
  45. this.essay2 = essay2;
  46. }
  47.  
  48. public int getTest2() {
  49. return test2;
  50. }
  51.  
  52. public void setTest2(int test2) {
  53. this.test2 = test2;
  54. }
  55.  
  56. public int getFinalGrade() {
  57. return finalGrade;
  58. }
  59.  
  60. public void setFinalGrade(int finalGrade) {
  61. this.finalGrade = finalGrade;
  62. }
  63.  
  64. }
  65.  
  66. Student.java
  67. public class Student {
  68.  
  69. private String firstName , lastName;
  70. private int essay1, test1 , essay2, test2 , finalGrade;
  71.  
  72. public Student(String firstName, String lastName, int essay1, int test1, int essay2, int test2, int finalGrade) {
  73. super();
  74. this.firstName = firstName;
  75. this.lastName = lastName;
  76. this.essay1 = essay1;
  77. this.test1 = test1;
  78. this.essay2 = essay2;
  79. this.test2 = test2;
  80. this.finalGrade = finalGrade;
  81. }
  82.  
  83.  
  84. public String getFirstName() {
  85. return firstName;
  86. }
  87. public void setFirstName(String firstName) {
  88. this.firstName = firstName;
  89. }
  90. public String getLastName() {
  91. return lastName;
  92. }
  93. public void setLastName(String lastName) {
  94. this.lastName = lastName;
  95. }
  96. public int getEssay1() {
  97. return essay1;
  98. }
  99. public void setEssay1(int essay1) {
  100. this.essay1 = essay1;
  101. }
  102. public int getTest1() {
  103. return test1;
  104. }
  105. public void setTest1(int test1) {
  106. this.test1 = test1;
  107. }
  108. public int getEssay2() {
  109. return essay2;
  110. }
  111. public void setEssay2(int essay2) {
  112. this.essay2 = essay2;
  113. }
  114. public int getTest2() {
  115. return test2;
  116. }
  117. public void setTest2(int test2) {
  118. this.test2 = test2;
  119. }
  120. public int getFinalGrade() {
  121. return finalGrade;
  122. }
  123. public void setFinalGrade(int finalGrade) {
  124. this.finalGrade = finalGrade;
  125. }
  126.  
  127. }
  128.  
  129. Utilities.java
  130. import java.io.BufferedReader;
  131. import java.io.FileReader;
  132. import java.io.IOException;
  133. import java.util.ArrayList;
  134. import java.util.List;
  135.  
  136. public class Utilities extends Assignment{
  137.  
  138. private String fileName;
  139. private StringBuilder builder = new StringBuilder();
  140. private String assignmentName;
  141. int section , essay1 ,test1 , essay2 , test2 , finalGrade;
  142.  
  143. public List<Student> getAllStudent() throws IOException{
  144. builder.setLength(0);
  145. List<Student> list = new ArrayList<Student>();
  146. int counter = 0;
  147. for(String line: readFile(fileName).split("\n")){
  148. if((counter += 1) > 2)
  149. builder.append(line + ":");
  150.  
  151. }
  152.  
  153. for(String line : builder.toString().split(":")){
  154. String attribute[] = line.split(",");
  155. list.add(new Student(attribute[0] , attribute[1] , Integer.parseInt(attribute[2]) ,
  156. Integer.parseInt(attribute[3]) , Integer.parseInt(attribute[4]) , Integer.parseInt(attribute[5]) , Integer.parseInt(attribute[6])));
  157. }
  158. return list;
  159. }
  160.  
  161. public void setAssigment() throws IOException{
  162. int counter = 0;
  163. builder.setLength(0);
  164. for(String line: readFile(fileName).split("\n")){
  165. if((counter += 1) == 2)
  166. builder.append(line);
  167. }
  168.  
  169. String attribute[] = builder.toString().split(",");
  170. this.setAssignmentName(attribute[0]);
  171. this.setSection(Integer.parseInt(attribute[1]));
  172. this.setEssay1(Integer.parseInt(attribute[2]));
  173. this.setTest1(Integer.parseInt(attribute[3]));
  174. this.setEssay2(Integer.parseInt(attribute[4]));
  175. this.setTest2(Integer.parseInt(attribute[5]));
  176. this.setFinalGrade(Integer.parseInt(attribute[6]));
  177.  
  178. }
  179.  
  180. private String readFile(String file) throws IOException {
  181. BufferedReader reader = new BufferedReader( new FileReader (file));
  182. String line = null;
  183. StringBuilder stringBuilder = new StringBuilder();
  184. String ls = System.getProperty("line.separator");
  185.  
  186. while( ( line = reader.readLine() ) != null ) {
  187. stringBuilder.append(line).toString();
  188. stringBuilder.append(ls);
  189. }
  190. reader.close();
  191. return stringBuilder.toString();
  192. }
  193.  
  194.  
  195. public void setFileName(String fileName){
  196. this.fileName = fileName;
  197. }
  198.  
  199. public String getFileName(String fileName){
  200. return fileName;
  201. }
  202.  
  203. public void help(){
  204. System.out.println("Accepted commands:");
  205. System.out.println("exit");
  206. System.out.println("help");
  207. System.out.println("load [filename");
  208. System.out.println("students");
  209. System.out.println("search [partial name");
  210. System.out.println("assignments");
  211. System.out.println("grades");
  212. System.out.println("student [student name");
  213. System.out.print("assignment [assignment name]");
  214. }
  215.  
  216. public void grades(){
  217.  
  218. }
  219.  
  220. public char gradeRating(int points){
  221. if(points >= 90 && points <= 100)
  222. return 'A';
  223. else if(points >= 80 && points < 90)
  224. return 'B';
  225. else if(points >= 70 && points < 80)
  226. return 'C';
  227. else if(points >= 60 && points < 70)
  228. return 'D';
  229. else if(points >= 0 && points < 80)
  230. return 'F';
  231. else
  232. return '-';
  233. }
  234.  
  235. public String setWordAllignment(String word){
  236. if(word.length() <= 8){
  237. int length = word.length();
  238. for(int ctr = 0; ctr < 9 - length ; ctr++){
  239. word += " ";
  240. }
  241.  
  242. return word;
  243. }
  244. return word;
  245. }
  246.  
  247. public Student searchStudent(List<Student> list , String studentName){
  248. for(Student student : list){
  249. if(student.getFirstName().contains(studentName) || student.getLastName().contains(studentName))
  250. return student;
  251. }
  252. return null;
  253. }
  254.  
  255. public void studentGrade(List<Student> list){
  256. int grades[] = new int[5];
  257. for(Student student : list){
  258.  
  259. int points = student.getEssay1() + student.getEssay2() + student.getTest1() + student.getTest2() + student.getFinalGrade();
  260. if(String.valueOf(this.gradeRating(points)).equals("A"))
  261. grades[0] += 1;
  262. else if(String.valueOf(this.gradeRating(points)).equals("B"))
  263. grades[1] += 1;
  264. else if(String.valueOf(this.gradeRating(points)).equals("C"))
  265. grades[2] += 1;
  266. else if(String.valueOf(this.gradeRating(points)).equals("D"))
  267. grades[3] += 1;
  268. else if(String.valueOf(this.gradeRating(points)).equals("F"))
  269. grades[4] += 1;
  270. }
  271.  
  272. System.out.println("A: "+ grades[0]);
  273. System.out.println("B: "+ grades[1]);
  274. System.out.println("C: "+ grades[2]);
  275. System.out.println("D: "+ grades[3]);
  276. System.out.println("F: "+ grades[4]);
  277. }
  278.  
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement