Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Jason Ngu
- * 10/25/16
- * 4.8 Project
- * Period 4A
- */
- public class Student
- {
- private String firstName, lastName;
- private Address homeAddress, schoolAddress;
- private int test1, test2, test3, avg;
- public Student( String first, String last, Address home, Address school )
- { //initializes the following variables
- firstName = first;
- lastName = last;
- homeAddress = home;
- schoolAddress = school;
- } //end constructor method Student
- public Student( int test1, int test2, int test3 )
- { //overloads the constructor so each test score starts at zero
- test1 = 0;
- test2 = 0;
- test3 = 0;
- } //end constructor method Student
- public void setTestScore( int test, int score )
- { //uses the set method to initializes variables
- if( test == 1 )
- test1 = score;
- else
- if( test == 2 )
- test2 = score;
- else
- test3 = score;
- avg = average( test1, test2, test3 );
- } //end of method setTestScore
- public int getTestScore( int test )
- { //uses the get method to return variables
- if( test == 1 )
- return test1;
- else
- if( test == 2 )
- return test2;
- else
- return test3;
- } //end of method getTestScore
- public int average( int test1, int test2, int test3 )
- { //returns the calculation of the average test scores
- return ( test1 + test2 + test3 ) / 3;
- } //end of method average
- public String toString()
- { //uses the toString method to print out information on the name, addresses, and scores
- String result;
- result = firstName + " " + lastName + "\n";
- result += "Home Address:\n" + homeAddress + "\n";
- result += "School Address:\n" + schoolAddress + "\n" ;
- result += "Test Scores and Average:\n" + test1 + "\n" + test2 + "\n" + test3 + "\n" + avg;
- return result;
- } //end of method toString
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement