dm6801

171127 - Class 08 - Cat

Nov 28th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. package Cats;
  2.  
  3. public class Cat {
  4.     /* Properties */
  5.     protected String    name,
  6.                         colour;
  7.     protected float     whiskersLength;
  8.    
  9.  
  10.     /* Get, Set Methods */
  11.     public void setName(String name) {
  12.         this.name = name;
  13.     }
  14.     public String getName() {
  15.         return this.name;
  16.     }
  17.    
  18.     public void setColour(String colour) {
  19.         this.colour = colour;
  20.     }
  21.     public String getColour() {
  22.         return this.colour;
  23.     }
  24.    
  25.     public void setWhiskersLength(float whiskersLength) {
  26.         this.whiskersLength = whiskersLength;
  27.     }
  28.     public String setColour() {
  29.         return this.colour;
  30.     }
  31.    
  32.    
  33.     /* Constructors */
  34.     public Cat(String name, float whiskersLength, String colour) {
  35.         this.name = name;
  36.         this.colour = colour;
  37.         this.whiskersLength = whiskersLength;
  38.     }
  39.     public Cat(String name, float whiskersLength) {
  40.         this(name, whiskersLength, "");
  41.     }
  42.     public Cat(String name) {
  43.         this(name, 0, "Ginger");
  44.     }
  45.     public Cat() {
  46.         this("Blacky, the Black Cat", 10, "Black");
  47.     }
  48.     /* Copy Constructor */
  49.     public Cat(Cat catObj) {
  50.         this.name = catObj.name;
  51.         this.colour = catObj.colour;
  52.         this.whiskersLength = catObj.whiskersLength;
  53.     }
  54.    
  55.    
  56.     /* Methods */
  57.     public String toString() {
  58.         String output = String.format("(%s@%h)\tname=\"%s\"\tcolour=\"%s\"\twhiskers=%.2fcm",
  59.                                     this.getClass().getName(), this, name, colour, whiskersLength);
  60.         return output;
  61.     }
  62.    
  63.    
  64. }
Add Comment
Please, Sign In to add comment