Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Implement the Bird class using BlueJ. The Bird class has the following fields

ID: 3722372 • Letter: 4

Question

4. Implement the Bird class using BlueJ. The Bird class has the following fields: name (String): Stores the name of the bird size (double): Stores the size of the bird flying speed (int): Stores the flying speed of the bird weight (double): Stores the weight of the bird current elevation (int): Stores the current elevation of the bird count: Stores the number of birds created . GRAVITY: A constant with a value of 9.8 The class should have the following constructor and methods: A constructor that accepts the following arguments and assigns them to the appropriate fields: name, size, flying speed, and weight. Constructor should assign 0 to current elevation and increment the count field by 1 Get methods for all the fields Set methods for the name field. . Eat method will accept amount of food as parameter and will update the size and weight fields using the following formulae: size= size + amount of food * 2 100 weight weight + amount of food#5 100 · Fly Up method will update the current elevation and weight fields using the following formulae: Flying Speed ightGRAVITY Current Elevation=Current Elevation+ Weight Weight-3

Explanation / Answer

Bird Class:

-------------------

package com.chegg;

public class Bird {

public String name;

public double size;

public int flying_speed;

public double weight;

public int current_elevation;

public static int count;

public final double GRAVITY=9.8;

Bird(String name,double size,int flying_speed,double weight){

this.name = name;

this.size = size;

this.flying_speed = flying_speed;

this.weight = weight;

current_elevation = 0;

count+=1;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getSize() {

return size;

}

public int getFlying_speed() {

return flying_speed;

}

public double getWeight() {

return weight;

}

public int getCurrent_elevation() {

return current_elevation;

}

public void eat(double amount_of_food){

size = size+(amount_of_food*2/100);

weight = weight + (amount_of_food*5/100);

}

public void flyUp(){

current_elevation = (int) (current_elevation + ((flying_speed)/(weight *GRAVITY)));

weight-=3;

}

public void flyDown(){

current_elevation = (int) (current_elevation - ((flying_speed)/(weight *GRAVITY)));

weight-=1;

}

}

Main Class:

-------------------

package com.chegg;

public class MainClass {

public static void main(String args[]){

Bird bird1 = new Bird("BlueJ 1", 10, 100, 3.8);

Bird bird2 = new Bird("BlueJ 2", 12, 95, 3.5);

Bird bird3 = new Bird("BlueJ 3", 15, 125, 3);

System.out.println("Total number of birds: "+Bird.count);

System.out.println("********************************");

System.out.println("Information about BlueJ 1: ");

System.out.println("Name: "+bird1.getName());

System.out.println("Size: "+bird1.getSize());

System.out.println("Flying Speed: "+bird1.getFlying_speed());

System.out.println("Weight: "+bird1.getWeight());

System.out.println("Current Elevation: "+bird1.getCurrent_elevation());

System.out.println("*********************************");

bird1.eat(10);

System.out.println();

System.out.println("********************************");

System.out.println("Information about BlueJ 1: ");

System.out.println("Name: "+bird1.getName());

System.out.println("Size: "+bird1.getSize());

System.out.println("Flying Speed: "+bird1.getFlying_speed());

System.out.println("Weight: "+bird1.getWeight());

System.out.println("Current Elevation: "+bird1.getCurrent_elevation());

System.out.println("*********************************");

System.out.println();

System.out.println("********************************");

System.out.println("Information about BlueJ 2: ");

System.out.println("Name: "+bird2.getName());

System.out.println("Size: "+bird2.getSize());

System.out.println("Flying Speed: "+bird2.getFlying_speed());

System.out.println("Weight: "+bird2.getWeight());

System.out.println("Current Elevation: "+bird2.getCurrent_elevation());

System.out.println("*********************************");

System.out.println();

bird2.flyUp();

System.out.println("********************************");

System.out.println("Information about BlueJ 2: ");

System.out.println("Name: "+bird2.getName());

System.out.println("Size: "+bird2.getSize());

System.out.println("Flying Speed: "+bird2.getFlying_speed());

System.out.println("Weight: "+bird2.getWeight());

System.out.println("Current Elevation: "+bird2.getCurrent_elevation());

System.out.println("*********************************");

System.out.println();

System.out.println("********************************");

System.out.println("Information about BlueJ 3: ");

System.out.println("Name: "+bird3.getName());

System.out.println("Size: "+bird3.getSize());

System.out.println("Flying Speed: "+bird3.getFlying_speed());

System.out.println("Weight: "+bird3.getWeight());

System.out.println("Current Elevation: "+bird3.getCurrent_elevation());

System.out.println("*********************************");

System.out.println();

bird3.flyDown();

System.out.println("********************************");

System.out.println("Information about BlueJ 3: ");

System.out.println("Name: "+bird3.getName());

System.out.println("Size: "+bird3.getSize());

System.out.println("Flying Speed: "+bird3.getFlying_speed());

System.out.println("Weight: "+bird3.getWeight());

System.out.println("Current Elevation: "+bird3.getCurrent_elevation());

System.out.println("*********************************");

System.out.println();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote