1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
larisa [96]
3 years ago
8

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.
Computers and Technology
1 answer:
kozerog [31]3 years ago
6 0

Answer:

The program to this question can be given as:

Program:

class Horse   //define class Horse

{  

private String name;   //define variables.

private String color;  

private int birthYear;  

//define set method.

public void setName(String name)  

{  

this.name = name; //set value of name.

}

public void setColor(String color)  

{  

this.color = color; //set value of color.  

}  

public void setBirthYear(int birthYear)

{  

this.birthYear = birthYear;  //set value of birthYear

}  

//define get method.

public String getName()  

{  

return name;  //return name.

}  

public String getColor()

{  

return color;  //return color.

}  

public int getBirthYear()

{  

return birthYear;  //return birthYear.

}  

}

class RaceHorse extends Horse     //define class RaceHorse  

{

private String raceNum;            //define variable.

public void setRace(String raceNum)    //define set method.

{

 this.raceNum=raceNum;      //set value of raceNum.

}

public String getRace()

{

 return raceNum;   //return raceNum

}

}

public class Main      //define main class.

{

public static void main(String[] args) //define main method.

{

 Horse ob= new Horse();  //creating class objects.

 RaceHorse ob1 = new RaceHorse();

 ob.setName("XXX");       //calling function

 ob.setColor("BLACK");

 ob.setBirthYear(2008);

 ob1.setRace("Five hundred meter");

 //print return values.

       System.out.println("The name of the horse is " + ob.getName()+"." +"\n"+  

   "The horse's color is " + ob.getColor()+"."+"\n"+ "It was born in " + ob.getBirthYear() +  

   "."+"\n"+ ob.getName()+" has taken part in " + ob1.getRace() + " races.");

   

}

}

Output:

The name of the horse is XXX.

The horse's color is BLACK.

It was born in 2008.

XXX has taken part in Five hundred meter races.

Explanation:

In the above program firstly we declare the class that is Horse in this class we define a variable that name is already given in the question which are name, color, and birthYear. In these variables are name and color datatype is string and the birthYear datatype is an integer because it stores the number. Then we use the get and set function in the get function we return all variable value. and in the set function, we set the values of the variable by this keyword. Then we declare another class that is RaceHorse this class inherit Horse class. In the RaceHorse class, we define a variable that is raceNum that's data type is a string in this class we also used the get and set function. Then we declare the main class in the main class we define the main method in the main method we create the above class object and call the set and get function and print the values of the function.

You might be interested in
Betty was sitting at a coffee shop reading her favorite book. She heard an explosion nearby. In a few, she could hear ambulance
enot [183]
B or D are the options I would suggest.
4 0
2 years ago
Read 2 more answers
Rachel wants to make sure that she uses effective communication skills at work. Which of the following is an example of somethin
BartSMP [9]

dont use slang or words like lol

5 0
3 years ago
Read 2 more answers
An experimenter discovers that the time for people to detect a string of letters on a computer screen is 400 milliseconds, and t
nadya68 [22]

Answer:

The correct answer to the following question will be Option D (Subtractive method ).

Explanation:

  • This approach essentially requests a participant to construct two activities that are already in almost every way similar, except for a mental process that is assumed to also be included in any of the activities although omitted in another.
  • This method will be much more valuable when deciding the period for phonemic awareness, despite text-string identification.

The other three options are not related to the given scenario. So that Option D is the right answer.

3 0
2 years ago
Who is Carl Thompson?
pishuonlain [190]
Carl Thompson was a well know Jazz player back in the mid 1900s
7 0
2 years ago
A town government is desinging anew bus system
Kamila [148]

Answer:

Umm what? Are you talking about the type of problem it is? If so it is an optimization problem.

Explanation:

I had something like this for one of my tests and I chose the optimization problem because it finds the values of decision variables that result in a maximum or minimum of a function.

But ion know if it's this that you are talking about

3 0
2 years ago
Other questions:
  • While designing a website, a(n) ____ allows you to identify the specific amount of space used on a particular page before it con
    15·2 answers
  • My mom works from home selling her craft work online to people all over the world. She can do this from home because we have acc
    13·2 answers
  • Explain how touch-tone dialing sends digits to the switch and write the name given to define touch-tone dialing.
    10·1 answer
  • Read each statement below. If the statement describes a peer-to-peer network, put a P next to it. If the statement describes a s
    12·1 answer
  • What is the difference of expository and reflexive documentary
    14·1 answer
  • Which picture should i put as my profile picture.
    15·2 answers
  • What is the force that resists the motion of an object through a fluid?
    6·1 answer
  • Help! Picture provided
    7·2 answers
  • Consider the following code:
    7·1 answer
  • How do I fix this on my HiSense Roku tv this is on Xfinity Stream Beta the error number is -500
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!