Advertisement
RexyBadDog

Lesson012_28_08_19_Task1 CLASSES

Aug 30th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 KB | None | 0 0
  1. // this Class is for java homework name: Lesson012_28_08_19_Task1
  2.  
  3. public class Cat {
  4.     private String name, color;
  5.     private int whiskersLenght;
  6.     static private int i=1;        // object creation count
  7.  
  8.     // builders:
  9.     public Cat(String name, int whLen, String color) {
  10.         this.name = name;
  11.         this.whiskersLenght = whLen;
  12.         this.color = color;
  13.     }
  14.     public Cat() {
  15.         this("Cat No"+i, (int)(Math.random()*4), "black");
  16.         i += 1;
  17.     }
  18.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  19.     @Override
  20.     public String toString() {
  21.         return "Cat{" +
  22.                 "name='" + name + '\'' +
  23.                 ", color='" + color + '\'' +
  24.                 ", whiskersLenght=" + whiskersLenght +
  25.                 '}';
  26.     }
  27. }
  28. // ####################################################################################################
  29. // this Class is for java homework name: Lesson012_28_08_19_Task1
  30.  
  31. public class Cat {
  32.     private String name, color;
  33.     private int whiskersLenght;
  34.     static private int i=1;        // object creation count
  35.  
  36.     // builders:
  37.     public Cat(String name, int whLen, String color) {
  38.         this.name = name;
  39.         this.whiskersLenght = whLen;
  40.         this.color = color;
  41.     }
  42.     public Cat() {
  43.         this("Cat No"+i, (int)(Math.random()*4), "black");
  44.         i += 1;
  45.     }
  46.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  47.     @Override
  48.     public String toString() {
  49.         return "Cat{" +
  50.                 "name='" + name + '\'' +
  51.                 ", color='" + color + '\'' +
  52.                 ", whiskersLenght=" + whiskersLenght +
  53.                 '}';
  54.     }
  55. }
  56. // ####################################################################################################
  57.  
  58. // this Class is for java homework name: Lesson012_28_08_19_Task1
  59.  
  60. public class SiamiCat extends Cat {
  61.     private String favoriteFood;
  62.  
  63.     // builders:
  64.     public SiamiCat(String name, int whLen, String color,  String food) {
  65.         super(name, whLen, color);
  66.         this.favoriteFood = food;
  67.     }
  68.  
  69.     public SiamiCat() {
  70.         super();
  71.         this.favoriteFood = "Tuna";
  72.     }
  73.  
  74.     public SiamiCat(String food) {
  75.         super();
  76.         this.favoriteFood = food;
  77.     }
  78.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  79.     @Override
  80.     public String toString() {
  81.         return super.toString() + "  SiamiCat{" +
  82.                 "favoriteFood=" + favoriteFood +
  83.                 '}';
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement