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

a.Create a BirdSighting class for the Birmingham Birdwatcher’s Club that include

ID: 3762035 • Letter: A

Question

a.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, createa default constructor that automatically sets the species to “robin” and the number and day to 1. Save the file as BirdSighting.java. Create an application named TestBirdSighting that demonstrates that each method works correctly. Save the file as TestBirdSighting.java.

b. 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.

c.Create a class with the same functionality as the BirdSighting class, but create the default constructor to call the three - parameter constructor. Save the class as BirdSighting2.java. Create an application to test the new version of the class, and name it TestBirdSighting2.java.

At the beginning of the program add the following comments.

See pages 31 through 33

//Filename <the class name of your java program>

//Written by <your name>

//Written on <the date you started writing the program>

//Assignment number

//Program description

Explanation / Answer

A.package Bird_Sighting;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* Project: Java Programming
* Package: Bird_Sighting
* File: BirdSighting
* Created by MR. XYZ
* On 12-Nov-2015
* BirdSighting.java.
*/
public class BirdSighting
   {
       private String birdSeen;
       private int numberSeen;
       private GregorianCalendar dateSeen;
       public BirdSighting()
           {
               birdSeen = "Robin";
               numberSeen = 1;
               dateSeen = new GregorianCalendar(0, 12, 1);
           }
       public BirdSighting(String bird, int seen, int year, int month, int dayOfMonth)
           {
               birdSeen = bird;
               numberSeen = seen;
               dateSeen = new GregorianCalendar(year, month, dayOfMonth);
           }
       public int getDateSeen()
           {
               return dateSeen.get(Calendar.DAY_OF_YEAR);
           }
       public String getBirdSeen()
           {
               return birdSeen;
           }
       public int getNumberSeen()
           {
               return numberSeen;
           }
   }

B.

package Bird_Sighting;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* Project: Java Programming
* Package: Bird_Sighting
* File: BirdSighting
* Created by MR. XYZ
* On 12-Nov-2015
* BirdSighting.java.
*/
class TestBirdSighting
   {
       public static void main(String[] args)
           {
               BirdSighting test001 = new BirdSighting();
               System.out.println("Bird Species: " + test001.getBirdSeen());
               System.out.println("Number Seen: " + test001.getNumberSeen());
               test001.getDateSeen();
               System.out.println("Day Of Year Seen: " + test001.getDateSeen());
               BirdSighting test002 = new BirdSighting("Blue Jay", 6, 2014, 6, 20);
               System.out.println("Bird Species: " + test002.getBirdSeen());
               System.out.println("Number Seen: " + test002.getNumberSeen());
               test001.getDateSeen();
               System.out.println("Day Of Year Seen: " + test002.getDateSeen());
           }
   }

C.

package Bird_Sighting;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* Project: Java Programming
* Package: Bird_Sighting
* File: BirdSighting
* Created by MR. XYZ
* On 12-Nov-2015
* BirdSighting2.java.
*/
public class BirdSighting2
   {
       private String birdSeen;
       private int numberSeen;
       private GregorianCalendar dateSeen;
       public BirdSighting2(int year, int month, int dayOfMonth)
           {
               birdSeen = "Robin";
               numberSeen = 1;
               this.dateSeen = new GregorianCalendar(year, month, dayOfMonth);
           }
       public int getDateSeen()
           {
               return dateSeen.get(Calendar.DAY_OF_YEAR);
           }
       public String getBirdSeen()
           {
               return birdSeen;
           }
       public int getNumberSeen()
           {
               return numberSeen;
           }
   }