Answered! Create a class named Horse that contains data fields for the name, color, and birth year. Include get and set methods…

1. Create a class named Horse that contains data fields for the name, color, and birth year. Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field that holds the number of races in which the horse has competed and additional methods to get and set the new field. Write an application that demonstrates using objects of each class. Save the files as Horse Java, RaceHorse Java, and DemoHorses.java.

Create a class named Horse that contains data fields for the name, color, and birth year. Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field that holds the number of races in which the horse has competed and additional methods to get and set the new field. Write an application that demonstrates using objects of each class. Save the files as Horse.java, RaceHorse.java, and DemoHorses.java.

Expert Answer

 DemoHorses.java

/*
Assignment: Create a class named Horse that contains data fields for the name, color, and birth year.
Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains
an additional field that holds the number of races in which the horse has competed and additional methods
to get an dset the new field. Write an application that demonstrates using objects of each class.
Save the files as Horse.java, RaceHorse.java, and DemoHorses.java.
*/

import java.util.*;

public class DemoHorses
{
// Race horse attribute weights
private int speedWeight = 5;
private int strengthWeight = 3;
private int accelWeight = 4;

public static void main(String[] args)
{

// Create two parent instances of the Horse class and apply unique attributes
Horse studHorse = new Horse();
Horse mareHorse = new Horse();

// Stud Horse Attributes
studHorse.setName(“Wilber”);
studHorse.setColor(“Dark Brown”);
studHorse.setDate(“12/21/2010”);

// Mare Horse Attributes
mareHorse.setName(“Old Gray Mare”);
mareHorse.setColor(“Light Brown”);
mareHorse.setDate(“01/29/2011”);

// Create two children race horses for the Preakness
// RaceHorse (speed, strength, acceleration)
RaceHorse Seabiscut = new RaceHorse(9, 7, 3);
Seabiscut.setName(“Seabiscut”);
RaceHorse Secretariat = new RaceHorse(6, 3, 10);
Secretariat.setName(“Secretariat”);

String SeabiscutName = Seabiscut.getName();
int SeabiscutRaces =   Seabiscut.getRaces();
//int SeabiscutLastPos = Seabiscut.getPlace();

String SecretariatName = Secretariat.getName();
int SecretariatRaces =   Secretariat.getRaces();
//int SecretariatLastPos = Secretariat.getPlace();

System.out.print(“You have two horses: “);
System.out.print(”          Races        Wins       LastPosition”);
System.out.println(”          —–        —-       ————“);
System.out.println(“[+] ” + SeabiscutName + ”              ” + SeabiscutRaces);// + ”            ” + SeabiscutLastPos);
System.out.println(“[+] ” + SecretariatName + ”              ” + SecretariatRaces);// + ”            ” + SecretariatLastPos);
System.out.println(“Race them? (Y/N) “);
Scanner scan = new Scanner(System.in);
String response = scan.nextLine();
//System.out.println(response);

try
{
if (response.equals(“Y”))
{
System.out.println(“OKAY”);
}
else if (response.equals(“N”))
{
System.out.println(“See ya!”);
}
else
{
System.out.println(“Invalid input.”);
}
}
catch (Exception e)
{
System.out.println(“Something went wrong.”);
}

}

}

/*

//Read in the secondsValue
System.out.print(“Enter seconds: “);
Scanner scan = new Scanner(System.in);
try
{
int secondsValue = scan.nextInt();
if (secondsValue < 0)
{
System.out.println(“Invalid input.”);
}

else if ((secondsValue < 60) && (secondsValue > 0))
{
System.out.println(secondsValue + ” seconds.”);
System.out.print(13/4);
}
*/

RaceHorse.java

/*
Assignment: Create a class named Horse that contains data fields for the name, color, and birth year.
Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains
an additional field that holds the number of races in which the horse has competed and additional methods
to get an dset the new field. Write an application that demonstrates using objects of each class.
Save the files as Horse.java, RaceHorse.java, and DemoHorses.java.

Add an additional data field to the RaceHorseclass that stores the place that the horse came in, including
its get() and set() methods. Demonstrate the usages of the various data fields in the DemoHorseclass by using
their get and set method.

*/

public class RaceHorse extends Horse
{
private int completedRaces;
private int placePosition;
private int speed;
private int strength;
private int acceleration;

public RaceHorse()
{
}

public RaceHorse(int horseSpeed, int horseStrength, int horseAcceleration)
{
speed = horseSpeed;
strength = horseStrength;
acceleration = horseAcceleration;
}

public int getRaces()
{
return completedRaces;
}
public void setRaces(int raceCount)
{
completedRaces = raceCount;
}

// Get/Set methods for speed
public int getSpeed()
{
return speed;
}
public void setSpeed(int horseSpeed)
{
speed = horseSpeed;
}

// Get/Set methods for strength
public int getStrength()
{
return strength;
}
public void setStrength(int horseStrength)
{
strength = horseStrength;
}

// Get/Set methods for Acceleration
public int getAcceleration()
{
return acceleration;
}
public void setAcceleration(int horseAccel)
{
acceleration = horseAccel;
}

// Get/Set methods for placePosition
public int getPlace()
{
return placePosition;
}
public void setPlacePosition(int place)
{
placePosition = place;
}

}

Horse.java

/*
Assignment: Create a class named Horse that contains data fields for the name, color, and birth year.
Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains
an additional field that holds the number of races in which the horse has competed and additional methods
to get an dset the new field. Write an application that demonstrates using objects of each class.
Save the files as Horse.java, RaceHorse.java, and DemoHorses.java.
*/

public class Horse
{
private String name;
private String color;
private String birthdate;

public String getName()
{
return name;
}
public void setName(String HorseName)
{
name = HorseName;
}
public String getColor()
{
return color;
}
public void setColor(String HorseColor)
{
color = HorseColor;
}
public String getDate()
{
return birthdate;
}
public void setDate(String HorseDate)
{
birthdate = HorseDate;
}
}

Still stressed from student homework?
Get quality assistance from academic writers!