Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. public class Student //Student Class
  2. {
  3. Address home = new Address("1027 Charleston St","Lincoln", "Ne", 68508);
  4. Address school = new Address("1534 E St", "Lincoln", "Ne", 68508);
  5. Student mike = new Student("Mike", "Vinci", home, school);
  6. Student john = new Student("John", "Doe", home, school, 90, 80, 199);
  7.  
  8. //Below are the ints used
  9. int test1 = 0;
  10. int test2 = 0;
  11. int test3 = 0;
  12. int avg2;
  13. int error = 0;
  14.  
  15. public void setTestScore(int testNum, int score)
  16. {
  17. if (testNum == 1)
  18. test1 = score;
  19. else if (testNum == 2)
  20. test2 = score;
  21. else if (testNum == 3)
  22. test3 = score;
  23. }
  24.  
  25. public int getTestScore(int testNum)
  26. {
  27. if (testNum == 1)
  28. return test1;
  29. else if (testNum == 2)
  30. return test2;
  31. else if (testNum == 3)
  32. return test3;
  33. else
  34. return error;
  35. }
  36.  
  37. public int average(int test1, int test2, int test3)
  38. {
  39. int avg2 = ((test1 + test2 + test3)/3); //finds the average of the tests
  40. return avg2;
  41. }
  42.  
  43. private String firstName, lastName; //private ints for coding
  44. private Address homeAddress, schoolAddress;
  45.  
  46. public Student (String first, String last, Address home, Address school)
  47. {
  48. firstName = first;
  49. lastName = last;
  50. homeAddress = home;
  51. schoolAddress = school;
  52. }
  53.  
  54. public Student (String first, String last, Address home, Address school, int test11, int test22, int test33)
  55. {
  56. firstName = first;
  57. lastName = last;
  58. homeAddress = home;
  59. schoolAddress = school;
  60. test11 = test1;
  61. test22 = test2;
  62. test33 = test3;
  63. }
  64.  
  65. public String toString()
  66. {
  67. String result;
  68. result = firstName + " " + lastName + "n";
  69. result += "Home Address:n" + homeAddress + "n";
  70. result += "School Address:n" + schoolAddress + "n";
  71. result += "Average=" + avg2 + " with Tests: " + test1 + ", " + test2 + ", " + test3;
  72. return result; //returns the result
  73. }
  74.  
  75. class Address
  76. {
  77. private String streetAddress, city, state;
  78. private long zipCode;
  79.  
  80. public Address(String street, String town, String st, long zip)
  81. {
  82. streetAddress = street;
  83. city = town;
  84. state = st;
  85. zipCode = zip;
  86. }
  87.  
  88. public String toString()
  89. {
  90. String result;
  91. result = streetAddress + "n";
  92. result += city + "," + state + " " + zipCode;
  93. return result; //returns the result
  94. }
  95. }
  96. }
  97. public class Course extends Student //Course class
  98. {
  99. private String course;
  100. private Student s1, s2, s3, s4, s5;
  101. private int studentcount = 1;
  102.  
  103. public Course (String name)
  104. {
  105. course = name;
  106. }
  107.  
  108. public Student addStudent(String first, String last, Address home, Address school)
  109. {
  110.  
  111. if (studentcount == 1){
  112. s1 = new Student(first,last,home,school);
  113. studentcount++;
  114. return s1;
  115. }
  116.  
  117. if (studentcount == 2) {
  118. s2 = new Student(first,last,home,school);
  119. studentcount++;
  120. return s2;
  121.  
  122. }
  123. else if (studentcount == 3){
  124. s3 = new Student(first,last,home,school);
  125. studentcount++;
  126. return s3;
  127.  
  128. }
  129. else if (studentcount == 4){
  130. s4 = new Student(first,last,home,school);
  131. studentcount++;
  132. return s4;
  133.  
  134. }
  135. else if (studentcount == 5) {
  136. s5 = new Student(first,last,home,school);
  137. studentcount++;
  138. return s5;
  139.  
  140. }
  141. else {
  142. System.out.println("No More students allowed in the class");
  143. return null;
  144. }
  145.  
  146. }
  147.  
  148. public double average()
  149. {
  150. return (s1.average() + s1.average() + s1.average() + s1.average() + s1.average()) / 5.0;
  151. }
  152.  
  153. public String roll()
  154. {
  155. String results = "";
  156.  
  157. if (studentcount == 1){
  158. results += s1.toString () +"n";
  159. return results;
  160. }
  161.  
  162. if (studentcount == 2) {
  163. results += s1.toString () +"n";
  164. results += s2.toString () +"n";
  165. return results;
  166.  
  167. }
  168. else if (studentcount == 3){
  169. results += s1.toString () +"n";
  170. results += s2.toString () +"n";
  171. results += s3.toString () +"n";
  172. return results;
  173.  
  174. }
  175. else if (studentcount == 4){
  176. results += s1.toString () +"n";
  177. results += s2.toString () +"n";
  178. results += s3.toString () +"n";
  179. results += s4.toString () +"n";
  180. return results;
  181.  
  182. }
  183. else if (studentcount == 5) {
  184. results += s1.toString () +"n";
  185. results += s2.toString () +"n";
  186. results += s3.toString () +"n";
  187. results += s4.toString () +"n";
  188. results += s5.toString () +"n";
  189.  
  190. return results;
  191. }
  192. else{
  193. return null;
  194. }
  195.  
  196. }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement