Advertisement
rushdie

הורשות תרגיל 1

Dec 11th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. package CatsTester;
  2.  
  3. public class SiameesCat extends Cats{
  4. private String _favoriteFood;
  5.  
  6. public SiameesCat(String _CatName, double _catWiskers, String _CatColor, String _favoriteFood) {
  7. super(_CatName, _catWiskers, _CatColor);
  8. this._favoriteFood = _favoriteFood;
  9. }
  10.  
  11. public String get_favoriteFood() {
  12. return _favoriteFood;
  13. }
  14.  
  15. public void set_favoriteFood(String _favoriteFood) {
  16. this._favoriteFood = _favoriteFood;
  17. }
  18.  
  19. public String toString() {
  20. return super.toString() + "\t Cat Favorite Food: " + _favoriteFood;
  21. }
  22.  
  23.  
  24. }//End of Siamees CAt
  25.  
  26.  
  27. package CatsTester;
  28.  
  29. public class streetCat extends Cats{
  30. private int _NumKills;
  31. /**
  32. * @param _CatName // Store Cat Name
  33. * @param _catWiskers // Holds the length of Cat whiskers
  34. * @param _CatColor // Hold cat color
  35. *New constructor to hold number of kills for street cat */
  36.  
  37. public streetCat(String _CatName, double _catWiskers, String _CatColor) {
  38. super(_CatName, _catWiskers, _CatColor);
  39. this._NumKills = _NumKills;
  40. }
  41.  
  42.  
  43. public int get_NumKills() {
  44. return _NumKills;
  45. }
  46.  
  47.  
  48. public void set_NumKills(int _NumKills) {
  49. this._NumKills = _NumKills;
  50. }
  51.  
  52.  
  53. public String toString() {
  54. return super.toString() + "\t Cat Number of Kills: " + _NumKills;
  55. }
  56. public Object print(String string) {
  57. return super.toString()+ "-CAT Number of Kills :"+_NumKills;
  58. }
  59. }//end of Street CATS
  60.  
  61. package CatsTester;
  62.  
  63. // Cat class tester to check the Classes
  64. public class CatsProgram {
  65.  
  66. public static void main(String[] args) {
  67. // made 1 cat of each kind
  68. Cats filthy = new Cats("Feefe", 5, "Blond");
  69. streetCat SC1 = new streetCat("Meeme", 7, "Gray");
  70. SiameesCat simee1 = new SiameesCat("Sosos", 8.5, "Biege", null);
  71. SC1.set_NumKills(4);
  72.  
  73. // Print out the results
  74. simee1.set_favoriteFood("French Toast");
  75. System.out.println(filthy);
  76. System.out.println(SC1);
  77. System.out.println(simee1);
  78.  
  79.  
  80. }
  81.  
  82. }
  83. package CatsTester;
  84.  
  85.  
  86. public class Cats {
  87. protected String _CatName;
  88. protected double _catWiskers;
  89. protected String _CatColor;
  90.  
  91. /**
  92. * @param _CatName // Store Cat Name
  93. * @param _catWiskers // Holds the length of Cat whiskers
  94. * @param _CatColor // Hold cat color
  95. */
  96. public Cats(String _CatName, double _catWiskers, String _CatColor) {
  97. //Constructor for Class Cats
  98. this._CatName = _CatName; // construct cat name
  99. this._catWiskers = _catWiskers; // construct cat whiskers length
  100. this._CatColor = _CatColor; // construct cat color
  101. }
  102. // cat name getter
  103. public String get_CatName() {
  104. return _CatName;
  105. }
  106. // cat name setter
  107. public void set_CatName(String _CatName) {
  108. this._CatName = _CatName;
  109. }
  110. //cat whiskers length getter
  111. public double get_catWiskers() {
  112. return _catWiskers;
  113. }
  114. //cat whiskers length setter
  115. public void set_catWiskers(double _catWiskers) {
  116. this._catWiskers = _catWiskers;
  117. }
  118. //cat color getter
  119. public String get_CatColor() {
  120. return _CatColor;
  121. }
  122. //cat color setter
  123. public void set_CatColor(String _CatColor) {
  124. this._CatColor = _CatColor;
  125. }
  126. // to string function to avoid printing Pointers and print data
  127. public String toString() {
  128. return "Cat Name: :" + _CatName + "\t Cat Wiskers Length: " + _catWiskers + "\t Cat Color : " + _CatColor;
  129. }
  130.  
  131. }// End of Cats Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement