Question: strong toString method in Horse class, RaceHorse method and string toString method in RaceHorse subclass import java.util. Calendar ; RaceHorse Tester -- to test the




![public class RaceHorseTester public static void main(String[] args) RaceHorse horse ; horse](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66ef3555525fc_78866ef3554aa5ed.jpg)

![rightNow.get(java.util.Calendar.YEAR); System.out.println("RaceHorse[name = Horse, year = " + year + "][trainer =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66ef3556e8c23_79066ef35565ba0c.jpg)


strong toString method in Horse class, RaceHorse method and string toString method in RaceHorse subclass
import java.util. Calendar ; RaceHorse Tester -- to test the RaceHorse class in which you have to write a default constructor, a constructor with parameters and a toString method. Change nothing here. public class RaceHorseTester public static void main(String[] args) RaceHorse horse ; horse = new RaceHorse(); System.out.println(horse) ; java.util.Calendar rightNow = java.util.Calendar.getInstance(); int year = rightNow.get(java.util.Calendar.YEAR); System.out.println("RaceHorse[name = Horse, year = " + year + "][trainer = tod, wins = 0, places = 0, losses - 0) WAS EXPECTED"); horse = new RaceHorse("Blaze", 2009, "Charles Chase"); horse.record(2) ; horse.record(); horse.record(); horse.record(2) ; horse.record(2); horse.record(1) ; System.out.println(horse) ; System.out.println("RaceHorse[name - Blaze, year = 2009] [trainer - Charles Chase, wins - 1, places - 3, losses - 21 WAS EXPECTED"); class Horse private String name ; private int year ; A default constructor method to initialize name and year with default name and year public Horse() name = "Horse"; java.util.Calendar calendar = java.util.Calendar.getInstance(); year - calendar.get(java.util.Calendar.YEAR); public Horse(String namel, int year) name = namel ; this.year = year ; Produces a string representation of the object Note: use getClass().getName() rather than Horse" subclass name will be correct. @return a string representation so that the public String toString() // ----------- Start below here. To do: approximate lines of code = 1 // -------- Start below here. To do: approximate lines of code = 1 // 1. something like: "Horse[name + Lucky Start Year - 2014]" -----End here. Please do not remove this comment. Reminder: no --- End here. Please do not remove this comment. Reminder: no w ow ffelp class RaceHorse extends Horse ---------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. private String trainer ; private int wins ; private int places ; private int losses ; A default constructor method that initializes inherited variables as well as added variables trainer, wins, place The default trainer is "tod". The wins, places, and losses start at zero. public RaceHorse() super(); trainer - tbd" ; wins = places = losses = 0; public RaceHorse(String namel, int year, String trainer) //-----------Start below here. To do: approximate lines of code = 2 --------Start below here. To do: approximate lines of code = 2 11 3. super call to initialize inherited name (HINT: use super() call with appropriate parameter ) 1/4. trainer -----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. ------- ---------- End here. Please do not remove this comment. Reminder: no changes outside the todo regions. wins - places = losses = ; Records result of a race, incrementing one of wins, places, losses @param code the result of the race: 1 = win, 2-place, loss public void record(int code) if (code == 0) losses ++ ; else if (code == 1) wins ++ ; else places ++ ; public String toString() ---------Start below here. To do: approximate lines of code - 2 // ----------- Start below here. To do: approximate lines of code = 2 // 5-6. Something like: "RaceHorse[name - Lucky Star, year 2011][trainer - Billy Wonder, wins - 1. places - 2 losses 101" and s uper call - End here. Please do not remove this comment. Reminder no changes outside the todo regions. T --- End here. Please do not remove this comment. Reminder no changes outside the todo regions public String toString() //-----------Start below here. To do: approximate lines of code = 2 // -----------Start below here. To do: approximate lines of code - 2 // 5-6. something like: "RaceHorsefname = Lucky Star, year = 2011][trainer - Billy Wonder, wins = 1, places = 2, losses - 101" and use super call -- - End here. Please do not remove this comment. Reminder: no changes outside the todo regions. T --- End here. Please do not remove this comment. Reminder no changes outside the todo regions. End here. Plea
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
