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]
4 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]4 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
Which statement is correct about operating systems? They are hardware devices. They include programs that help people do certain
katrin2010 [14]
<span>They include programs that help people do certain tasks. They include programs that control a computer. They store information being used by the CPU.</span>
3 0
3 years ago
When you open a browser window it opens in a _____________.
postnew [5]
The answer is D window
7 0
3 years ago
What is an entity supertype, and why is it used?
marissa [1.9K]

Answer:

Correct answer is option B (The reason for using supertypes is to minimize the number of nulls and to minimize the likelihood of redundant relationships)

Explanation:

Entity supertype

A  entity supertype is a generic entity type which is related with one or more subtypes.

Use of entity supertype:

The reason for using entity supertype is to reduce redundant relationships and it is also used to minimize the number of nulls.

5 0
3 years ago
How can I find all the answers for the NWEA MAP Math, English, Reading, and Science tests? Please help!!!!! I found some answers
Gala2k [10]

Answer:

if its a test try to just do it on your own ,you got nothing to lose from a test, its just to understand what you know on the concepts, but if you would still like answers just search around the net or here and you can always post the questions to ask people for help someone would eventually answer your questions but then beware of bots that post links as answer!

Explanation:

6 0
3 years ago
Claudia has a bachelor's degree in computer information systems, and she has learned to use some popular software testing tools.
Studentka2010 [4]
She should be a great software programmer!
3 0
4 years ago
Read 2 more answers
Other questions:
  • Sarah believes that thanks to the ability of science and technology to create progress problems will be solved and life will imp
    11·1 answer
  • After unit and integration testing are completed, _________ testing ensures that all hardware and software components work toget
    7·1 answer
  • Convert 234.43 (base 7) to base 10
    7·1 answer
  • What is the working principle of computer?
    9·1 answer
  • You would like to conduct a survey and ask your web page visitors to indicate the computer operating systems that they use. Each
    10·1 answer
  • Blank spaces or unseen control characters in a data file are referred to as
    5·2 answers
  • Which of the following is the correct financial function that returns the periodic payment for a loan?
    10·1 answer
  • Instructions:Type the correct answer in the box. Spell all words correctly.
    9·2 answers
  • You began a small mobile app company. To help market your apps, you create a social media site. The site allows users to join co
    15·1 answer
  • Write a program to sort the (name, age, score) tuples by descending order where name is string, age and score are numbers. The s
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!