Java programming Create a BirdSighting class for the Birmingham Birdwatcher’s Cl
ID: 664844 • Letter: J
Question
Java programming
Create a BirdSighting class for the Birmingham Birdwatcher’s Club that includes
data fields for a bird species sighted, the number seen, and the day of the year. For
example, April 1 is the 91st day of the year, assuming it is not a leap year. The class
also includes methods to get each field. In addition, create a default constructor that
automatically sets the species to “robin” and the number and day to 1. Create an application named TestBirdSighting that demonstrates that each method works correctly.
Create an additional overloaded constructor for the BirdSighting class you
created in Exercise 3a. This constructor receives parameters for each of the
data fields and assigns them appropriately. Add any needed statements to the
TestBirdSighting application to ensure that the overloaded constructor works
correctly, save it, and then test it.
Create a class with the same functionality as the BirdSighting class, but create
the default constructor to call the three-parameter constructor.
Explanation / Answer
package Bird_Sighting; //import package
import java.util.Calendar;
import java.util.GregorianCalendar;
public class BirdSighting //create a BirdSighting class for the Birmingham Birdwatcher’s Club
{
private String Bird_name; // data fields for a bird species sighted, the number seen, and the day of the year
private int i; // data fields for the number seen, and the day of the year
private GregorianCalendar date; //data fields for the day of the year
public BirdSighting()
{
Bird_name = "Robin"; // create a default constructor that automatically sets the species to “robin” .
i = 1; //sets the species to “robin” day to 1.
date = new GregorianCalendar(0, 12, 1); //Create calender for extract date
}
public BirdSighting(String bird, int j, int year, int month, int dayOfMonth)
{
Bird_name = bird;
i = j;
date = new GregorianCalendar(year, month, dayOfMonth);
}
public int getdate()
{
return date.get(Calendar.DAY_OF_YEAR); //get date
}
public String getBird_name() //get bird spices
{
returnBird_name;
}
public int geti() //get number of birs een
{
return i;
}
}
public class TestBirdSighting //Create an application named TestBirdSighting
{
public static void main(String[] args)
{
BirdSighting Bird = new BirdSighting();
System.out.println("Bird Species: " + Bird.getBird_name());
System.out.println("Number of Bird Seen: " + Bird.geti());
System.out.println("Day Of Year when seen Bird: " + Bird.getDate());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.