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
Como realizar un cuadro comprativo?​
Kruka [31]
How to make a comparison chart?
3 0
3 years ago
Distinguish between principles, guidelines and standards, using examples of each to illustrate​
AleksAgata [21]

Explanation:

principles is what governs a place

guidelines is what you read to guide you

standards is what build up in your self

5 0
3 years ago
Read 2 more answers
An investor’s stock portfolio consists of four Exchange Traded Funds (SPY, QQQ, EEM, and VXX). Write a program that requests the
Allisa [31]

Answer:

The solution code is written in Python 3

  1. SPY = float(input("Enter SPY Amount: "))
  2. QQQ = float(input("Enter QQQ Amount: "))
  3. EEM = float(input("Enter EEM Amount: "))
  4. VXX = float(input("Enter VXX Amount: "))
  5. totalAmount = SPY + QQQ + EEM + VXX
  6. print("Total amount invested: $" + str(totalAmount))
  7. print("Percentage invested for SPY: " + str(SPY / totalAmount * 100) + "%")
  8. print("Percentage invested for QQQ: " + str(QQQ / totalAmount * 100) + "%")
  9. print("Percentage invested for EEM: " + str(EEM / totalAmount * 100) + "%")
  10. print("Percentage invested for VXX: " + str(VXX / totalAmount * 100) + "%")

Explanation:

Firstly, let's declare four variables, SPY, QQQ, EEM and VXX and use input() function to prompt user to input the amount invested in each fund (Line 1 - 4).

Next, sum up all the funds' amount and assign the total to totalAmount variable (Line 6).

Next display the total amount invested and the percentage invested for each fund using print function (Line 7 - 11). Please note the formula to calculate the percentage of investment is

(fund / totalAmount ) * 100

3 0
3 years ago
All of the following are likely to be the benefits of a college graduate except:
Firdavs [7]
B. Earn less money over time

Over time, the interest is added to the principal, earning more interest. That's the power of compounding interest. If it is not invested, the value of the money erodes over time.
8 0
2 years ago
Logical design is tied to a specific hardware and software platform. a. True b. False
cluponka [151]

Answer:B false

Explanation:

3 0
3 years ago
Other questions:
  • An operating system cannot run from an external drive. true or false
    15·1 answer
  • Assume you have written a method with the header num mymethod(string name, string code). the method's type is
    5·1 answer
  • You want to find information about Paris, France in the last five years, written in English. What is the best way to search for
    5·2 answers
  • Given the following characteristics for a magnetic disk pack with 10 platters yielding 18 recordable surfaces (not using the top
    14·1 answer
  • Is techonalygy harmful or useful
    6·2 answers
  • The keys in the computer's keyboard are represented by a numeric code agreement (ASCII). For example A is 65 and a is 97.
    12·1 answer
  • A ________ is a powerful analytical tool to size up Apple Inc.'s competitive assets in order to determine whether or not those a
    9·1 answer
  • Natalie is a secretary and must complete a large amount of filing this afternoon. At 1:00 PM, the office receptionist gets sick
    10·1 answer
  • Mary is working on joining of a new domain tree to an existing forest, but before starting the process, she should have at least
    7·1 answer
  • What are the MOST likely reasons that a student would research a topic using the internet?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!