the second Objects lab.

Person.java 1014B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Write a description of class Person here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class Person
  8. {
  9. // instance variables - replace the example below with your own
  10. private String name;
  11. private int age;
  12. private String code;
  13. private int credits;
  14. /**
  15. * Constructor for objects of class Person
  16. */
  17. public Person(String myName, int myAge)
  18. {
  19. // initialise instance variables
  20. name = myName;
  21. age = myAge;
  22. }
  23. /**
  24. * accessor method returning name
  25. */
  26. public String getName()
  27. {
  28. // put your code here
  29. return name;
  30. }
  31. /**
  32. * mutator method returning name
  33. */
  34. public void setAge(int myAge)
  35. {
  36. // put your code here
  37. age = myAge;
  38. }
  39. /**
  40. * method to print details of name
  41. */
  42. public void printDetails()
  43. {
  44. // put your code here
  45. System.out.println("The name of this person is " + name);
  46. }
  47. }