Create a class with the same functionality as the BirdSghting class, but create
ID: 644622 • Letter: C
Question
Create a class with the same functionality as the BirdSghting class, but create the default
constructor to call the three-parameterconstructor. Save the class as BirdSighting2.java.
Create an application to test the new version of the class and name it TestBirdSighting2.java.
Here is my BirdSighting class:
class BirdSighting {
private String species;
private int noseen;
private int dayofyear;
public BirdSighting()
{
species="robin";
noseen=1;
dayofyear=1;
}
public BirdSighting(String a, int b,int c)
{
species=a;
noseen=b;
dayofyear=c;
}
public String getSpecies()
{
return this.species;
}
public int getNoSeen()
{
return this.noseen;
}
public int getDayofyear()
{
return this.dayofyear;
}
public void setSpecies(String a)
{
species=a;
}
public void setNoSeen(int a)
{
noseen=a;
}
public void setDayofyear(int a)
{
dayofyear=a;
}
}
Thank You!
Explanation / Answer
Program:
public class BirdSighting
{
private String birdSeen;
private int numberSeen;
private GregorianCalendar dateSeen;
public BirdSighting()
{
birdSeen = "Robin";
numberSeen = 1;
dateSeen = new GregorianCalendar();
}
public GregorianCalendar getDateSeen()
{
dateSeen.set(Calendar.DAY_OF_YEAR, 1);
dateSeen.get(Calendar.DAY_OF_YEAR);
return dateSeen;
}
public String getBirdSeen()
{
return birdSeen;
}
public int getNumberSeen()
{
return numberSeen;
}
}
public 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());
System.out.println("Day Of Year Seen: " + test001.getDateSeen());
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.