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
What provision of the Government Paperwork Elimination Act was designed to encourage a paperless society?
Liula [17]
<span>The answer would be "Validation of electronic signatures"</span>
3 0
3 years ago
Read 2 more answers
Rock, Paper, Scissors is a two-player game in which each player chooses one of three items. If both players choose the same item
mezya [45]

Answer:

The answer is c

Explanation:

7 0
4 years ago
1. Identify a local or regional cause or issue for Social Change related to specific professional tracks that can be addressed o
alexgriva [62]

Answer:

56 J

Explanation:

Formula to find the kinetic energy is :

E_kEk = \frac{1}{2}21  × m × v²

Here ,

m ⇒ mass

v ⇒  velocity

Let us solve now

 E_kEk = \frac{1}{2}21 × m × v²

     = \frac{1}{2}21 × 7 kg × ( 4 ms⁻¹ )²

     = \frac{1}{2}21 × 7 × 16

     = \frac{1}{2}21 × 112

     = 56 J

Hope this helps you :-)

Let me know if you have any other questions :-)

5 0
2 years ago
Write a program 10 enter 3 number and find smallest.​
timama [110]

10 + 3 = 13

13 - 10 = 3

5 0
2 years ago
oftware that is free and whose code can be accessed and potentially modified by anyone is referred to as _____. shared source fi
ad-work [718]

Answer:

open source software

Explanation:

A software that is free and whose code can be accessed and potentially modified by anyone is referred to as an open source software. The license used by the developer of an open source software grants all users the permission to use, distribute and modify the software at any time.

Some examples of an open source software are Firefox, gimp, OpenOffice etc.

8 0
3 years ago
Other questions:
  • A __________ network is good for connecting computer clusters.
    13·2 answers
  • Nathan wants to create multiple worksheet containing common formatting styles for his team members. Which file extension helps h
    5·1 answer
  • Davia draws a shape with 5 sides. two sides are each 5 inches long. two other sides are each 4 inches long. the perimeter of the
    15·1 answer
  • Using a for loop, print the decimal equivalents of ½, 1/3, ¼, … 1/10. Also, using a while loop, print the decimal equivalents of
    6·1 answer
  • Felicia has been having problems with her computer. Her documents won’t open, her computer is running slow, and programs automat
    7·1 answer
  • Which of the following is not a property of a constructor?A. The name of a constructor can be chosen by the programmerB. A const
    11·1 answer
  • In reference to computer communications, what does the term noise mean?
    8·2 answers
  • Software built and delivered in pieces is known as
    14·2 answers
  • Consider the following class interfaces:
    8·1 answer
  • What should you remember about typography while creating your résumé?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!