Guest User

Untitled

a guest
Jul 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package ex6;
  2.  
  3. public class Student {
  4.  
  5. /* invariant:
  6. * To take a students full name id and print on one line.
  7. *
  8. */
  9.  
  10. private String forename;
  11. private String surname;
  12.  
  13. private int id;
  14. private static int uniqueID;
  15.  
  16. /* constructor
  17. * requires: nothing
  18. * ensures: a new student instane is created.
  19. */
  20.  
  21. public Student(String forname , String surname){
  22. uniqueID= 1010000;
  23. id= (uniqueID + 1);
  24. }
  25. /* getter for forname
  26. * requires: nothing
  27. * ensures:
  28. * forename of student is got
  29. */
  30.  
  31. public String getForename (){
  32. return forename;
  33. }
  34. /* getter for surname
  35. * requires: nothing
  36. * ensures:
  37. * surname of student is got
  38. */
  39. public String getSurname (){
  40. return surname;
  41. }
  42. /* getter for ID
  43. * requires: nothing
  44. * ensures:
  45. * ID of student is got
  46. */
  47. public int getID(){
  48. return id;
  49. }
  50. /* Setter for forename
  51. * requires: nothing
  52. * ensures:
  53. * forename of the student is to be updated
  54. */
  55. public void setForename (String newFor){
  56. forename = newFor;
  57.  
  58. }
  59. /* Setter for surname
  60. * requires: nothing
  61. * ensures:
  62. * surname of the student is to be updated
  63. */
  64. public void setSurname (String newSur){
  65. surname = newSur;
  66.  
  67. }
  68.  
  69. /* method to return students full name
  70. * requires: surname and forename of student
  71. * ensures:
  72. * the full name of the student is returned
  73. */
  74. public String getName (){
  75.  
  76. return surname.toUpperCase()+", " +forename;
  77.  
  78. }
  79.  
  80. public String toString() {
  81.  
  82. return getID() + "\t" + getName();
  83. }
  84.  
  85.  
  86.  
  87. }
Add Comment
Please, Sign In to add comment