Tuesday 11 August 2015

Java Tutorial : What is a Class[dog]?


Click here to watch in Youtube :
https://www.youtube.com/watch?v=VYFUNZiZ7MQ&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : What is a Class[dog]? 

Dog.java
/**
 * Dog class is the blueprint from which individual dog objects can be created.
 */
public class Dog
{
    private String name;
    private String color;
    private String height;
    private String length;
    private String weight;

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getColor()
    {
        return color;
    }

    public void setColor(String color)
    {
        this.color = color;
    }

    public String getHeight()
    {
        return height;
    }

    public void setHeight(String height)
    {
        this.height = height;
    }

    public String getLength()
    {
        return length;
    }

    public void setLength(String length)
    {
        this.length = length;
    }

    public String getWeight()
    {
        return weight;
    }

    public void setWeight(String weight)
    {
        this.weight = weight;
    }

    public void sit(String string)
    {
        System.out.println(string);
    }

    public void layDown(String string)
    {
        System.out.println(string);
    }

    public void shake(String string)
    {
        System.out.println(string);
    }

    public void walk(String string)
    {
        System.out.println(string);
    }
}
DogDemo.java
public class DogDemo
{
    public static void main(String[] args)
    {

        Dog jimmyDog = new Dog();
        jimmyDog.setName("Jimmy");
        jimmyDog.setColor("Brown");
        jimmyDog.setHeight("18 Inches");
        jimmyDog.setLength("36 Inches");
        jimmyDog.setWeight("30 Pounds");

        System.out.println("Properties");
        System.out.println("----------");
        
        displayDogInformation(jimmyDog);
        
        System.out.println("\nBehaviors");
        System.out.println("----------");
        
        jimmyDog.sit("Sit fast");
        jimmyDog.layDown("Laydown fast");
        jimmyDog.shake("Shake fast with one leg");
        jimmyDog.walk("Walk fast");

        System.out.println("*********************************************");
        
        Dog tommyDog = new Dog();
        tommyDog.setName("Tommy");
        tommyDog.setColor("white");
        tommyDog.setHeight("28 Inches");
        tommyDog.setLength("46 Inches");
        tommyDog.setWeight("40 Pounds");

        System.out.println("Properties");
        System.out.println("----------");
        
        displayDogInformation(tommyDog);
        
        System.out.println("\nBehaviors");
        System.out.println("----------");
        
        tommyDog.sit("Sit slowly");
        tommyDog.layDown("Laydown slowly");
        tommyDog.shake("Shake slowly with two legs");
        tommyDog.walk("Walk slowly");

    }

    public static void displayDogInformation(Dog dog)
    {
        System.out.println("Name : "+ dog.getName());
        System.out.println("Color : "+dog.getColor());
        System.out.println("Height : "+dog.getHeight());
        System.out.println("Length : "+dog.getLength());
        System.out.println("Weight : "+dog.getWeight());
    }
}

Output
Properties
----------
Name : Jimmy
Color : Brown
Height : 18 Inches
Length : 36 Inches
Weight : 30 Pounds

Behaviors
----------
Sit fast
Laydown fast
Shake fast with one leg
Walk fast
*********************************************
Properties
----------
Name : Tommy
Color : white
Height : 28 Inches
Length : 46 Inches
Weight : 40 Pounds

Behaviors
----------
Sit slowly
Laydown slowly
Shake slowly with two legs
Walk slowly

To Download DogDemoStateAndMethods Project Click the below link
https://sites.google.com/site/javaee4321/java/DogDemoStateAndMethods.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment