Question: Simple JAVA program, Please fill in the bolded italicized part. import java.util.Calendar ; /** HorseTester -- to test the Horse class in which you have

Simple JAVA program, Please fill in the bolded italicized part.

import java.util.Calendar ;

/**

HorseTester -- to test the Horse class in which you have to write

a default constructor and a toString method.

Note that the code below shows you how to get the current year.

Change nothing here.

*/

public class HorseTester

{

public static void main(String[] args)

{

Horse horse ;

horse = new Horse() ;

System.out.println(horse) ;

java.util.Calendar rightNow = java.util.Calendar.getInstance() ;

int year = rightNow.get(java.util.Calendar.YEAR) ;

System.out.println("Horse[name = Horse, year = " + year

+ "] WAS EXPECTED.") ;

horse = new Horse("Thunder", 2011) ;

System.out.println(horse) ;

System.out.println("Horse[name = Thunder, year = 2011] WAS EXPECTED.") ;

}

}

/**

A Horse object has a name and a year of birth.

The day of birth is always January 1.

There are two todo regions ... one for the default constructor and

one for the toString method.

Note: a nice way to get the current year is:

java.util.Calendar calendar = java.util.Calendar.getInstance() ;

year = calendar.get(java.util.Calendar.YEAR) ;

or if you import java.util.Calendar:

Calendar calendar = Calendar.getInstance() ;

year = calendar.get(Calendar.YEAR) ;

Similarly for the current month.

*/

class Horse

{

private String name ;

private int year ;

/**

Constructs a Horse object with default name and year

*/

//-----------Start below here. To do: approximate lines of code = 4

// 1-4. write a default constructor which sets name to "Horse" and year to the current year

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

/**

Constructs a Horse object with given name and year of birth

@param name1 the given name

@param year the year of birth

*/

public Horse(String name1, int year)

{

name = name1 ;

this.year = year ;

}

/**

Produces a string representation of the object

Note: use getClass().getName() rather than "Horse", so that the

subclass name will be correct.

@return a string representation

*/

//-----------Start below here. To do: approximate lines of code = 2

// 5-6. write a toString method that produces something like: "Horse[name = Lucky Star, year = 2014]"

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!