Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Student implements Serializable{
- private String name;
- private int ssNum;
- private int coursesCompleted;
- private char[] grades;
- public Student(String n, int num, int c){
- n = name;
- num = ssNum;
- c = coursesCompleted;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getSsNum() {
- return ssNum;
- }
- public void setSsNum(int ssNum) {
- this.ssNum = ssNum;
- }
- public int getCoursesCompleted() {
- return coursesCompleted;
- }
- public void setCoursesCompleted(int coursesCompleted) {
- this.coursesCompleted = coursesCompleted;
- }
- public char[] getGrades() {
- return grades;
- }
- public void setGrades(char[] grades) {
- this.grades = grades;
- }
- public double gpa(char[] grades){
- double gpa = 0;
- for (int i = 0; i < grades.length; i++){
- if (grades[i] == 'A'){
- gpa += 4.0;
- }
- else if (grades[i] == 'B'){
- gpa += 3.0;
- }
- else if (grades[i] == 'C'){
- gpa += 2.0;
- }
- else if (grades[i] == 'D'){
- gpa += 1.0;
- }
- else if (grades[i] == 'F'){
- gpa += 0.0;
- }
- }
- return gpa / grades.length;
- }
- public void ReadObject(ObjectInputStream in) throws IOException{
- String readTitle = "";
- for(int i = 0; i < name.length(); i++){
- readTitle += in.readChar();
- }
- ssNum = in.readInt();
- coursesCompleted = in.readInt();
- for (int i = 0; i < grades.length; i++){
- grades[i] = in.readChar();
- }
- }
- public void WriteObjectOverride(ObjectOutputStream out) throws IOException, ClassNotFoundException{
- out.writeChars(name);
- out.writeInt(ssNum);
- out.writeInt(coursesCompleted);
- for (int i = 0; i < grades.length; i++){
- out.writeChar(grades[i]);
- }
- gpa(grades);
- }
- public String toString(){
- String student = name + " " + "\nGPA: " + gpa(grades);
- return student;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement