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 but it will not accept it at all -  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 {    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 int 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;     } }   Here is what it is telling me -  Build Status Build Failed Build Output DemoHorses.java:10: error: cannot find symbol horse2.setName("Champion"); ^ symbol: method setName(String) location: variable horse2 of type RaceHorse DemoHorses.java:11: error: cannot find symbol horse2.setColor("black"); ^ symbol: method setColor(String) location: variable horse2 of type RaceHorse DemoHorses.java:12: error: cannot find symbol horse2.setBirthYear(2011); ^ symbol: method setBirthYear(int) location: variable horse2 of type RaceHorse DemoHorses.java:15: error: cannot find symbol System.out.println(horse2.getName() + " is " + horse2.getColor() + " and was born in " + horse2.getBirthYear() + "."); ^ symbol: method getName() location: variable horse2 of type RaceHorse DemoHorses.java:15: error: cannot find symbol System.out.println(horse2.getName() + " is " + horse2.getColor() + " and was born in " + horse2.getBirthYear() + "."); ^ symbol: method getColor() location: variable horse2 of type RaceHorse DemoHorses.java:15: error: cannot find symbol System.out.println(horse2.getName() + " is " + horse2.getColor() + " and was born in " + horse2.getBirthYear() + "."); ^ symbol: method getBirthYear() location: variable horse2 of type RaceHorse DemoHorses.java:16: error: cannot find symbol System.out.println(horse2.getName() + " has been in " + horse2.getRaces() + " races."); ^ symbol: method getName() location: variable horse2 of type RaceHorse 7 errors Test Contents@Test public void unitTest() { Horse horse = new Horse(); horse.setName("Old Paint"); assertEquals(h

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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 but it will not accept it at all - 

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
{
   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 int 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;
    }
}
 
Here is what it is telling me - 
Build Status
Build Failed
Build Output
DemoHorses.java:10: error: cannot find symbol horse2.setName("Champion"); ^
symbol: method setName(String)
location: variable horse2 of type RaceHorse DemoHorses.java:11: error: cannot find symbol horse2.setColor("black"); ^
symbol: method setColor(String)
location: variable horse2 of type RaceHorse DemoHorses.java:12: error: cannot find symbol horse2.setBirthYear(2011); ^ symbol: method setBirthYear(int) location: variable horse2 of type RaceHorse DemoHorses.java:15: error: cannot find symbol System.out.println(horse2.getName() + " is " + horse2.getColor() + " and was born in " + horse2.getBirthYear() + "."); ^ symbol: method getName() location: variable horse2 of type RaceHorse DemoHorses.java:15: error: cannot find symbol System.out.println(horse2.getName() + " is " + horse2.getColor() + " and was born in " + horse2.getBirthYear() + "."); ^ symbol: method getColor() location: variable horse2 of type RaceHorse DemoHorses.java:15: error: cannot find symbol System.out.println(horse2.getName() + " is " + horse2.getColor() + " and was born in " + horse2.getBirthYear() + "."); ^ symbol: method getBirthYear() location: variable horse2 of type RaceHorse DemoHorses.java:16: error: cannot find symbol System.out.println(horse2.getName() + " has been in " + horse2.getRaces() + " races."); ^ symbol: method getName() location: variable horse2 of type RaceHorse
7 errors
Test Contents@Test public void unitTest() { Horse horse = new Horse(); horse.setName("Old Paint"); assertEquals(horse.getName(), "Old Paint"); horse.setName("Champion"); assertEquals(horse.getName(), "Champion"); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education