Advertisement
chaibs

cat-program

Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. package eleven;
  2.  
  3. public class Cat {
  4.     public String name, color;
  5.     int safam;
  6.  
  7.     public Cat(String n, String c, int s) {// constructor for cat
  8.         this.name = n;
  9.         this.color = c;
  10.         this.safam = s;
  11.     }
  12.    
  13.     public String toString() {// output for cat
  14.         return "Cat Name " + this.name + " Color " + this.color + " mustache length " + this.safam;
  15.     }
  16.  
  17. }
  18. ----------------------------------------------------------------------------------------------------------
  19. package eleven;
  20.  
  21. public class StreetCat extends Cat {
  22.     public int fightNum;
  23.  
  24.     public StreetCat(String n, String c, int s, int fn) {// constructor for street cat
  25.         super(n, c, s);
  26.         this.fightNum = fn;
  27.     }
  28.    
  29.     public String toString() {// output for street cat
  30.         return super.toString() + " Number of fights " + this.fightNum;
  31.     }
  32.  
  33. }
  34. ----------------------------------------------------------------------------------------------------------
  35. package eleven;
  36.  
  37. public class SiamiCat extends Cat {
  38.     public String foodType;
  39.  
  40.     public SiamiCat(String n, String c, int s, String ft) {// constructor for siami cat
  41.         super(n, c, s);
  42.         this.foodType = ft;
  43.     }
  44.    
  45.     public String toString() {// output for siami cat
  46.         return super.toString() + " favorite food " + this.foodType;
  47.     }
  48.  
  49. }
  50. ----------------------------------------------------------------------------------------------------------
  51. package eleven;
  52.  
  53. public class MainCat {
  54.  
  55.     public static void main(String[] args) {
  56.         Cat c1 = new Cat("Lodvik", "Redhead", 5);// creating cat
  57.         StreetCat c2 = new StreetCat("Voljin", "Redhead", 4, 7);// creating a street cat
  58.         SiamiCat c3 = new SiamiCat("Cloe", "White", 3, "Fish");// creating a siami cat
  59.  
  60.         System.out.println(c1);// showing output for cat
  61.         System.out.println(c2);// showing output for street cat
  62.         System.out.println(c3);// showing out for siami cat
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement