Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. /**Each instance of this class is a new Student.
  2. *
  3. * @author Stefan Idriceanu
  4. */
  5. public class Student
  6. {
  7. private final String name;
  8. private Phone phone;
  9.  
  10. //the constructor for a Student
  11. //the student will come with no phone
  12. public Student(String theName)
  13. {
  14. name=theName;
  15. phone=null;
  16. }//student
  17.  
  18. /**Used to make a new purchase.
  19. *
  20. * @param thePhone The name of the phone that is bought
  21. */
  22. //when a student purchases a phone the current phone is discarded
  23. public void purchasePhone(Phone thePhone)
  24. {
  25. phone=thePhone;
  26. }//purchasePhone
  27.  
  28. /**The name of the student
  29. *
  30. * @return The name of the student.
  31. */
  32. //is used to give back the name instance variable of the student
  33. public String theName()
  34. {
  35. return name;
  36. }//theName
  37.  
  38. /**The phone of the student.
  39. *
  40. * @return The object that represents the phone of the student.
  41. */
  42. //is used to give back the phone instance variable of the student
  43. public Phone getPhone()
  44. {
  45. return phone;
  46. }//getPhone
  47.  
  48. /**Used to create a view upon the details of the student.
  49. *
  50. * @return A string with the details of the student.
  51. */
  52. //creates the way a Student will be printed out
  53. //we can see that the return is using an instance of the phone class
  54. public String toString()
  55. {
  56. if(phone==null)
  57. return "Student("+name+","+phone+")";
  58. else
  59. return "Student("+name+","+phone.toString();
  60. }//toString
  61. }//class Student
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement