C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
Bartleby Related Questions Icon

Related questions

Question

complete the following Horse Class with the guidelines provided below

public class Horse {
    // Fields of class Horse
    
    // Constructor of class Horse
    /**
     * Constructor for objects of class Horse
     */
    public Horse(char horseSymbol, String horseName, double horseConfidence) {
    }
    
    // Other methods of class Horse
    public void fall() {
    }
    
    public double getConfidence() {
    }
    
    public int getDistanceTravelled() {
    }
    
    public String getName() {
    }
    
    public char getSymbol() {
    }
    
    public void goBackToStart() {
    }
    
    public boolean hasFallen() {
    }

    public void moveForward() {
    }

    public void setConfidence(double newConfidence) {
    }
    
    public void setSymbol(char newSymbol) {
    }   
}

Horse object
1. The Horse objects represent the horses in the race.
2. Each horse has a name and a symbol (1 character). The symbol is used for display during the
race, while the name is used to announce the winner.
3. During the race, a horse may fall, resulting in its elimination from the race.
4. Horses are assigned a confidence rating ranging from 0 to 1. A higher confidence rating
indicates faster running speed, but also increases the likelihood of falling.
5. Winning a race slightly increases a horse's confidence, while falling during a race slightly
decreases it.
expand button
Transcribed Image Text:Horse object 1. The Horse objects represent the horses in the race. 2. Each horse has a name and a symbol (1 character). The symbol is used for display during the race, while the name is used to announce the winner. 3. During the race, a horse may fall, resulting in its elimination from the race. 4. Horses are assigned a confidence rating ranging from 0 to 1. A higher confidence rating indicates faster running speed, but also increases the likelihood of falling. 5. Winning a race slightly increases a horse's confidence, while falling during a race slightly decreases it.
1. Write the Horse class according to the following specification:
a) The class should be named Horse
b) It should have 5 fields to store:
i.
The name of the horse (e.g., "PIPPI LONGSTOCKING")
ii.
A single (Unicode) character used to represent the horse (e.g., a)
iii.
iv.
V.
The distance travelled by the horse as a whole number
A boolean indicating whether or not the horse has fallen.
The confidence rating of the horse, represented as a decimal number between 0 and
1.
c) The constructor of the class should have the following signature:
public Horse (char horseSymbol, String horseName, double horseConfidence)
d) The class should provide the following public methods:
.
fall(): Sets the horse as fallen.
•
•
•
•
•
getConfidence(): Returns the confidence rating of the horse.
getDistance Travelled(): Returns the distance traveled by the horse.
getName(): Returns the name of the horse.
getSymbol(): Returns the character used to represent the horse.
goBackToStart(): Resets the horse to the start of the race.
hasFallen(): Returns true if the horse has fallen, false otherwise.
moveForward(): Increments the distance traveled by the horse by 1.
setConfidence(double newConfidence): Sets the confidence rating of the
horse to the given value.
setSymbol(char newSymbol): Sets the character used to represent the horse to
the given character."
c) Encapsulation should be implemented to ensure that the values of the fields are always
acceptable.
(Note: It's crucial that your Horse class precisely meets this specification to ensure
compatibility with the Race class written by McFarewell).
expand button
Transcribed Image Text:1. Write the Horse class according to the following specification: a) The class should be named Horse b) It should have 5 fields to store: i. The name of the horse (e.g., "PIPPI LONGSTOCKING") ii. A single (Unicode) character used to represent the horse (e.g., a) iii. iv. V. The distance travelled by the horse as a whole number A boolean indicating whether or not the horse has fallen. The confidence rating of the horse, represented as a decimal number between 0 and 1. c) The constructor of the class should have the following signature: public Horse (char horseSymbol, String horseName, double horseConfidence) d) The class should provide the following public methods: . fall(): Sets the horse as fallen. • • • • • getConfidence(): Returns the confidence rating of the horse. getDistance Travelled(): Returns the distance traveled by the horse. getName(): Returns the name of the horse. getSymbol(): Returns the character used to represent the horse. goBackToStart(): Resets the horse to the start of the race. hasFallen(): Returns true if the horse has fallen, false otherwise. moveForward(): Increments the distance traveled by the horse by 1. setConfidence(double newConfidence): Sets the confidence rating of the horse to the given value. setSymbol(char newSymbol): Sets the character used to represent the horse to the given character." c) Encapsulation should be implemented to ensure that the values of the fields are always acceptable. (Note: It's crucial that your Horse class precisely meets this specification to ensure compatibility with the Race class written by McFarewell).
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage