daniel_lawson9999

Daniel Lawson Chapter 8 Self Check 17-31

Sep 22nd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. Daniel Lawson
  2. 9/22/2016
  3.  
  4.  
  5. 17.
  6. A constructor is used to initialize the fields of a class when the instance is createed
  7. 18.
  8. First a constructor is not supposed to be void (the header should be public Point(initialX, initial)
  9. and y they created and assigned the values to a new integers called x and y in the following constructor Instead of assigning x and y to initialx and initial y to the fields x
  10. 19.
  11. public class Name{
  12.  
  13. private String firstName;
  14. private String lastName;
  15. private char middleInitial;
  16.  
  17. public Name(String f, char m, String l){
  18. firstName = f;
  19. MiddleInitial = m;
  20. lastName = l;
  21.  
  22. }
  23.  
  24. public String getNormalOrder(){
  25. return (firstName + " " +middleInitial +". " + lastName);
  26. }
  27. public String getReverseOrder(){
  28. return (lastName + ", " + firstName + " " +middleInitial +"." );
  29. }
  30. }
  31. 20.
  32. this is used to speficy what you are refering to.This is used to refer to a field instead of a variable. This is also used to call a method that you are in and with the same or different parameters
  33. 21.
  34. Public Point(Point p){
  35. this.x = p.getX();
  36. this.y = p.getX();
  37. }
  38. 22.
  39. Abstraction allows the client to know how to use something without knowing how it internally works.
  40. 23.
  41. Public allows things to be accessed outside the program while private does not. You should make a class's fields private.
  42. 24.
  43. By uses a accessor method to see the values of the fields
  44. 25.
  45. public void setX(int x){
  46. this.x = x;
  47. }
  48. public void setY(int y){
  49. this.y = y;
  50. }
  51. 26.
  52. public class Name{
  53.  
  54. private String firstName;
  55. private String lastName;
  56. private char middleInitial;
  57.  
  58. public Name(String f, char m, String l){
  59. firstName = f;
  60. MiddleInitial = m;
  61. lastName = l;
  62.  
  63. }
  64.  
  65. public String getNormalOrder(){
  66. return (firstName + " " +middleInitial +". " + lastName);
  67. }
  68. public String getReverseOrder(){
  69. return (lastName + ", " + firstName + " " +middleInitial +"." );
  70. }
  71. public String getLastName(){
  72. return lastName();
  73. }
  74. public String getFirstName(){
  75. return firstName();
  76. }
  77. public char getMiddleInitial(){
  78. return middleInitial();
  79. }
  80. }
  81. 27.
  82. public void setFirstName(String firstName){
  83. this.firstName = firstName;
  84. }
  85. public void setLastName(String lastName){
  86. this.lastName = lastName;
  87. }
  88. public void setMiddleInitial(char middleInitial){
  89. this.middleInitial = middleInitial;
  90. }
  91. 28.
  92. encapsulates makes it so the class is easy to use and values are not set to what they are not intended to be set at.
  93. 29.
  94. cohesion allows the class to represent a single clear abstraction.
  95. 30.
  96. Not including i/o allows the class to have more cohesion.
  97. 31.
  98. public String getSymbol(){
  99. return symbol;
  100. }
  101. public int getTotalShares(){
  102. return totalShares;
  103. }
  104. public double getTotalCost(){
  105. return getTotalCost;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment