Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Student here.
- *
- * Stefan Howansky
- * @version (a version number or a date)
- */
- public class Student
- {
- // instance variables
- private int test1;
- private int test2;
- private int test3;
- private String name;
- /*
- *Constructor
- */
- public Student()
- {
- name = "";
- test1 = 0;
- test2 = 0;
- test3 = 0;
- }
- public Student(int t1, int t2, int t3, String nm)
- {
- name = nm;
- test1 = t1;
- test2 = t2;
- test3 = t3;
- }
- /*
- *MUTATOR METHOD
- */
- public void setName(String nm) //Sets the student's name
- {
- name=nm;
- }
- /*
- * ACCESSOR METHOD
- */
- public String getName() //Gets the student's name
- {
- return name;
- }
- public void setGrade(int t1, int t2, int t3)
- {
- test1 = t1;
- test2 = t2;
- test3 = t3;
- }
- /*
- * returns the grade asked for by the input parameter
- */
- public int getGrade(int t)
- {
- if (t==1)
- return test1;
- else if (t==2)
- {
- return test2;
- }
- else
- {
- return test3;
- }
- }
- public int sumGrades()
- {
- return (test1 + test2 + test3);
- }
- public double calculateAverage()
- {
- double average;
- average = sumGrades()/3.0;
- return average;
- }
- public String toString()
- {
- String str;
- str = "Name: " + name + "\n" +
- "Test 1: " + test1 + "\n" +
- "Test 2: " + test2 + "\n" +
- "Test 3: " + test3 + "\n" +
- "Sum: " + sumGrades()+ "\n" +
- "Average: " + calculateAverage();
- return str;
- }
- public boolean compareStudent(Student s2)
- {
- if(this.toString().equals(s2.toString()))
- return true;
- else
- return false;
- //this.toString == other.toString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement