This is the question I am struggling on -  Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. This is the code I have done but I am not sure what I am missing and/or doing wrong -  public class DemoHorses {     public static void main(String args[])     {        Horse horse1 = new Horse();        RaceHorse horse2 = new RaceHorse();        horse1.setName("Old Paint");        horse1.setColor("brown");        horse1.setBirthYear(2009);        horse2.setName("Champion");        horse2.setColor("black");        horse2.setBirthYear(2011);        horse2.setRaces(4);        System.out.println(horse1.getName() + " is " +           horse1.getColor() + " and was born in " + horse1.getBirthYear() + ".");        System.out.println(horse2.getName() + " is " +           horse2.getColor() + " and was born in " + horse2.getBirthYear() + ".");        System.out.println(horse2.getName() + " has been in " +           horse2.getRaces() + " races.");     } } --------------------------------------------------------- public class Horse {    // Define the Horse class here    private String name;    private String color;    private int birthYear;    public void setName(String n)     {        name = n;    }    public String getName()    {        return name;    }     public void setColor(String c)     {        color = c;    }    public String getColor()    {        return color;    }     public void setBirthYear(int yr)     {        birthYear = yr;    }    public String getBirthYear()    {        return birthYear;    } } -------------------------------------------------------------- public class RaceHorse {     // Define the RaceHorse class here     private int races;     public void setRaces(int numR)     {         races = numR;     }     public int getRaces()     {         return races;     } }

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

This is the question I am struggling on - 

Create a class named Horse that contains the following data fields:

  • name - of type String
  • color - of type String
  • birthYear - of type int

Include get and set methods for these fields.

Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field.

This is the code I have done but I am not sure what I am missing and/or doing wrong - 

public class DemoHorses
{
    public static void main(String args[])
    {
       Horse horse1 = new Horse();
       RaceHorse horse2 = new RaceHorse();
       horse1.setName("Old Paint");
       horse1.setColor("brown");
       horse1.setBirthYear(2009);
       horse2.setName("Champion");
       horse2.setColor("black");
       horse2.setBirthYear(2011);
       horse2.setRaces(4);
       System.out.println(horse1.getName() + " is " +
          horse1.getColor() + " and was born in " + horse1.getBirthYear() + ".");
       System.out.println(horse2.getName() + " is " +
          horse2.getColor() + " and was born in " + horse2.getBirthYear() + ".");
       System.out.println(horse2.getName() + " has been in " +
          horse2.getRaces() + " races.");
    }
}
---------------------------------------------------------
public class Horse
{
   // Define the Horse class here
   private String name;
   private String color;
   private int birthYear;
   public void setName(String n) 
   {
       name = n;
   }
   public String getName()
   {
       return name;
   }
    public void setColor(String c) 
   {
       color = c;
   }
   public String getColor()
   {
       return color;
   }
    public void setBirthYear(int yr) 
   {
       birthYear = yr;
   }
   public String getBirthYear()
   {
       return birthYear;
   }
}
--------------------------------------------------------------
public class RaceHorse
{
    // Define the RaceHorse class here
    private int races;
    public void setRaces(int numR)
    {
        races = numR;
    }
    public int getRaces()
    {
        return races;
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,