001    /**
002     * Exercise 4.6 from the book.
003     * 
004     * @author Kristian Torp, torp (at) cs (dot) aau (dot) dk
005     * @version 1.0
006     */
007    public class Dog {
008            /** The name of the dog --- an instance variable */
009            String name;
010    
011            /** The default constructor */
012            public Dog() {
013                    // just assign name to dog
014                    name = "John Doe";
015            }
016    
017            /**
018             * The constructor that gives the dog a name
019             * 
020             * @param name
021             *            the name of the dog
022             */
023            public Dog(String name) {
024                    // note the usage of this
025                    this.name = name;
026            }
027    
028            /**
029             * A bark method that takes no parameters.
030             */
031            public void bark() {
032                    System.out.println("Just barking");
033            }
034    
035            /**
036             * Overloaded bark method that takes a single boolean parameter.
037             * 
038             * @param b
039             */
040            public void bark(boolean b) {
041                    System.out.println("Boolean " + b + " barking");
042            }
043    
044            /**
045             * Overloaded bark method that takes a single character parameter.
046             * 
047             * @param c
048             */
049            public void bark(char c) {
050                    System.out.println("Char " + c + " barking");
051            }
052    
053            /**
054             * Overloaded bark method that takes a single byte parameter.
055             * 
056             * @param b
057             */
058            public void bark(byte b) {
059                    System.out.println("Byte " + b + " barking");
060            }
061    
062            /**
063             * Overloaded bark method that takes a single byte parameter.
064             * 
065             * @param s
066             */
067            public void bark(short s) {
068                    System.out.println("Short " + s + " barking");
069            }
070    
071            /**
072             * Overloaded bark method that takes a single integer parameter.
073             * 
074             * @param i
075             */
076            public void bark(int i) {
077                    System.out.println("Int " + i + " barking");
078            }
079    
080            /**
081             * Overloaded bark method that takes a single long parameter.
082             * 
083             * @param l
084             */
085            public void bark(long l) {
086                    System.out.println("Long " + l + " barking");
087            }
088    
089            /**
090             * Overloaded bark method that takes a single float parameter.
091             * 
092             * @param f
093             */
094            public void bark(float f) {
095                    System.out.println("Float " + f + " barking");
096            }
097    
098            /**
099             * Overloaded bark method that takes a single double parameter.
100             * 
101             * @param d
102             */
103            public void bark(double d) {
104                    System.out.println("Double " + d + " barking");
105            }
106    
107            /**
108             * The main method that exercises all bark methods.
109             * 
110             * @param args
111             */
112            public static void main(String[] args) {
113                    // makes some variables of basic types
114                    boolean bo = true;
115                    char ch = 'k';
116                    byte by = -34;
117                    short sh = 434;
118                    int in = 83438;
119                    long lo = 2244545;
120                    float fl = .14e-5f;
121                    double dd = 2.781828e38d;
122    
123                    // create a dog object
124                    Dog d = new Dog("Pluto");
125                    // bark in many ways
126                    d.bark();
127                    d.bark(bo);
128                    d.bark(ch);
129                    d.bark(by);
130                    d.bark(sh);
131                    d.bark(in);
132                    d.bark(lo);
133                    d.bark(fl);
134                    d.bark(dd);
135            }
136    }
137