Advertisement
Guest User

Untitled

a guest
Aug 15th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Student implements Serializable{
  4. private String name;
  5. private int ssNum;
  6. private int coursesCompleted;
  7. private char[] grades;
  8.  
  9. public Student(String n, int num, int c){
  10. n = name;
  11. num = ssNum;
  12. c = coursesCompleted;
  13. }
  14.  
  15. public String getName() {
  16. return name;
  17. }
  18.  
  19. public void setName(String name) {
  20. this.name = name;
  21. }
  22.  
  23. public int getSsNum() {
  24. return ssNum;
  25. }
  26.  
  27. public void setSsNum(int ssNum) {
  28. this.ssNum = ssNum;
  29. }
  30.  
  31. public int getCoursesCompleted() {
  32. return coursesCompleted;
  33. }
  34.  
  35. public void setCoursesCompleted(int coursesCompleted) {
  36. this.coursesCompleted = coursesCompleted;
  37. }
  38.  
  39. public char[] getGrades() {
  40. return grades;
  41. }
  42.  
  43. public void setGrades(char[] grades) {
  44. this.grades = grades;
  45. }
  46. public double gpa(char[] grades){
  47.  
  48. double gpa = 0;
  49.  
  50. for (int i = 0; i < grades.length; i++){
  51. if (grades[i] == 'A'){
  52. gpa += 4.0;
  53. }
  54. else if (grades[i] == 'B'){
  55. gpa += 3.0;
  56. }
  57. else if (grades[i] == 'C'){
  58. gpa += 2.0;
  59. }
  60. else if (grades[i] == 'D'){
  61. gpa += 1.0;
  62. }
  63. else if (grades[i] == 'F'){
  64. gpa += 0.0;
  65. }
  66. }
  67.  
  68. return gpa / grades.length;
  69.  
  70. }
  71.  
  72. public void ReadObject(ObjectInputStream in) throws IOException{
  73. String readTitle = "";
  74.  
  75. for(int i = 0; i < name.length(); i++){
  76. readTitle += in.readChar();
  77. }
  78. ssNum = in.readInt();
  79. coursesCompleted = in.readInt();
  80.  
  81. for (int i = 0; i < grades.length; i++){
  82. grades[i] = in.readChar();
  83. }
  84. }
  85. public void WriteObjectOverride(ObjectOutputStream out) throws IOException, ClassNotFoundException{
  86.  
  87. out.writeChars(name);
  88. out.writeInt(ssNum);
  89. out.writeInt(coursesCompleted);
  90.  
  91. for (int i = 0; i < grades.length; i++){
  92. out.writeChar(grades[i]);
  93. }
  94. gpa(grades);
  95. }
  96. public String toString(){
  97. String student = name + " " + "\nGPA: " + gpa(grades);
  98. return student;
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement