Guest User

Untitled

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