Tuesday, 11 August 2015

Java Tutorial : What is a Class[Bird]?


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

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

Bird.java
/**
 * Bird class is the blueprint from which individual bird objects can be
 * created.
 */
public class Bird
{
    private String name;
    private String color;
    private String canSwim;
    private String avgLifeTime;
    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 getCanSwim()
    {
        return canSwim;
    }

    public void setCanSwim(String canSwim)
    {
        this.canSwim = canSwim;
    }

    public String getAvgLifeTime()
    {
        return avgLifeTime;
    }

    public void setAvgLifeTime(String avgLifeTime)
    {
        this.avgLifeTime = avgLifeTime;
    }

    public String getWeight()
    {
        return weight;
    }

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

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

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

}
BirdDemo.java
public class BirdDemo
{
    public static void main(String[] args)
    {

        Bird sparrowBird = new Bird();
        sparrowBird.setName("Sparrow");
        sparrowBird.setColor("Brown");
        sparrowBird.setCanSwim("No");
        sparrowBird.setAvgLifeTime("3y");
        sparrowBird.setWeight("0.024kg");

        System.out.println("Characteristics");
        System.out.println("--------------");
        
        displayBirdInformation(sparrowBird);
        
        System.out.println("\nBehaviors");
        System.out.println("----------");
        
        sparrowBird.fly("Can fly 46km/h");
        sparrowBird.walk("Can walk 1km/h");
        
        System.out.println("*********************************************");
        
        Bird penguinBird = new Bird();
        penguinBird.setName("Penguin");
        penguinBird.setColor("White and Black");
        penguinBird.setCanSwim("Yes");
        penguinBird.setAvgLifeTime("20y");
        penguinBird.setWeight("15kg");

        System.out.println("Characteristics");
        System.out.println("-------------");
        
        displayBirdInformation(penguinBird);
        
        System.out.println("\nBehaviors");
        System.out.println("----------");
        
        penguinBird.fly("Cannot fly");
        penguinBird.walk("Can walk 3 to 4 km/h");

    }

    public static void displayBirdInformation(Bird bird)
    {
        System.out.println("Name : "+ bird.getName());
        System.out.println("Color : "+bird.getColor());
        System.out.println("Can Swim : "+bird.getCanSwim());
        System.out.println("Avg Life time : "+bird.getAvgLifeTime());
        System.out.println("Weight : "+bird.getWeight());
    }
}

Output
Characteristics
--------------
Name : Sparrow
Color : Brown
Can Swim : No
Avg Life time : 3y
Weight : 0.024kg

Behaviors
----------
Can fly 46km/h
Can walk 1km/h
*********************************************
Characteristics
-------------
Name : Penguin
Color : White and Black
Can Swim : Yes
Avg Life time : 20y
Weight : 15kg

Behaviors
----------
Cannot fly
Can walk 3 to 4 km/h

To Download BirdDemoStateAndMethods Project Click the below link
https://sites.google.com/site/javaee4321/java/BirdDemoStateAndMethods.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