Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. /* Jason Ngu
  2. * 10/25/16
  3. * 4.8 Project
  4. * Period 4A
  5. */
  6.  
  7.  
  8.  
  9. public class Student
  10. {
  11. private String firstName, lastName;
  12. private Address homeAddress, schoolAddress;
  13. private int test1, test2, test3, avg;
  14.  
  15. public Student( String first, String last, Address home, Address school )
  16. { //initializes the following variables
  17. firstName = first;
  18. lastName = last;
  19. homeAddress = home;
  20. schoolAddress = school;
  21. } //end constructor method Student
  22.  
  23. public Student( int test1, int test2, int test3 )
  24. { //overloads the constructor so each test score starts at zero
  25. test1 = 0;
  26. test2 = 0;
  27. test3 = 0;
  28. } //end constructor method Student
  29.  
  30. public void setTestScore( int test, int score )
  31. { //uses the set method to initializes variables
  32. if( test == 1 )
  33. test1 = score;
  34. else
  35. if( test == 2 )
  36. test2 = score;
  37. else
  38. test3 = score;
  39.  
  40. avg = average( test1, test2, test3 );
  41. } //end of method setTestScore
  42.  
  43. public int getTestScore( int test )
  44. { //uses the get method to return variables
  45. if( test == 1 )
  46. return test1;
  47. else
  48. if( test == 2 )
  49. return test2;
  50. else
  51. return test3;
  52. } //end of method getTestScore
  53.  
  54. public int average( int test1, int test2, int test3 )
  55. { //returns the calculation of the average test scores
  56. return ( test1 + test2 + test3 ) / 3;
  57. } //end of method average
  58.  
  59. public String toString()
  60. { //uses the toString method to print out information on the name, addresses, and scores
  61. String result;
  62.  
  63. result = firstName + " " + lastName + "\n";
  64. result += "Home Address:\n" + homeAddress + "\n";
  65. result += "School Address:\n" + schoolAddress + "\n" ;
  66. result += "Test Scores and Average:\n" + test1 + "\n" + test2 + "\n" + test3 + "\n" + avg;
  67.  
  68. return result;
  69. } //end of method toString
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement