Learning how to create and use classes and objects in Java is one of the most important concepts you will learn this semester. This is a KEY chapter on learning how to program in an object-oriented la

Java Programming – Creating a Class Learning how to create and use classes and objects in Java is one of the most important concepts you will learn this semester. This is a KEY chapter on learning how to program in an object -oriented language. This assignment is designed to assess your ability to create a new class using a predefined UML diagram. If needed, go back and review the format of a UML diagram in the textbook . A “driver ” program that “uses” the class you create is supplied for this assignm ent. In a real -world setting, some programmers only use classes that have been predefined by others and they simply write driver programs. Other programmers create new classes for others to use. And still other programmers do both. You will start this week by ONLY creating a new class. The driver is provided for you to test and use your new class . If your class is created per the UML diagram below, the driver will compile and run correctly. If you receive errors when compiling the Driver, you should not modify the driver, the issue is with your Horse class. Your assignment this week is to create a class called Hors e. A driver program called HorseDriver is provided for this problem. The Horse class contains instance data for a single horse: • The name of the horse (a String) • The weight of the horse (an integer) • The height of the horse (measured in whole inches – an integer) • The 4 -digit year the horse was born (an integer) • The ge nder of the horse (M or F) (a char) The UML class diagram for Horse is below: Horse Driver Horse Main (args: String[ ]): void - name : String - weight : int (in pounds) - height : int (in whole inches) - birth Year : int (4 digit year) - gender : char + getName( ) : String + getWeight( ) : int + get Height ( ) : int + getBirthYear( ) : int + getGender( ) : char + setName (String horseName ) : void + setWeight (int horseWeight ) : void + set Height (int horse Height ) : void + set BirthYear (int horseBirthYear ) : void + set Gender (char horseGender ) : void + calc Age ( ) : int + calcHands( ) : double + toString( ) : String ( + represents the public modifier and – represents the private modifier ) Steps to complete: ✓ Create the Horse class using the UML diagram on the previous page. Use the name o f the methods which are illustrated in the UML diagram so that the driver program runs correctly. ✓ Create 2 constructors for the Horse class (each constructor will be named Horse ): 1. A default constructor with no parameters . The coding for the default constructor should set • String values to a space (“ “ – a space between the double quotes) OR to the empty string (“” -- no space between the double quotes). Either will work for our example. • char values to a space (‘ ‘ -- a space between the single quotes) OR an empty char literal using one of the following : • ‘\u0000’ • ‘\0’ • (char) 0 • Numeric values to zero . 2. A constructor with 5 parameters ( a value passed in for name, we ight, height, birthYear, and gender – in this order ). Coding should use the parameters to update the instance data items. ✓ Create each of the accessors (getters) and mutators (setters) which are illustrated in the UML diagram . ✓ Create a helping method named calc Age() that will subtract the current year from the year the horse was born to calculate the age of the horse. Th e calc Age() method should return that calculated age. There is an easy way for you extract the current year from your computer’s date (do not input the current date ). There is a Calendar class in the java.util package. To extract the current year from your computer’s date , use the method below. This method returns an integer value so you can assign that value to an integer variable. Calendar.getInstance().get(Calendar.YEAR) To use the method above, include the following import statement in your class: import java.util.Calendar; Note: Thoroughbreds all age on January 1. A foal born on Dec 31 is considered a one year old on Jan 1. In other words, any foal born in 2016 became a 1 -year old on January 1 , 2017 . Any foal born in 2015 becomes a 2 -year old on January 1, 2017. This means you can simply subtract a horse ’s birthyear from the current year to calculate their age. 0 is a legitimate age for a foal until January 1 of the following year. ✓ Create a helping method named calc Hands (). Horse height is often mea sured in “hands ”. One hand is 4 inches. Thus, a horse measuring 60 inches is 15 hands (60 / 4 = 15). A horse measuring 62 inches is 15.2 hands high (15 X 4 = 60 plus 2 inches = 62). The fractional part of the hand s measurement ( .2 ) is in base 4 (modulo 4). To convert from inches to hands. Divide inc hes by 4 using integer division. Then use the remainder operator with bas e 4 for get the fractional part. Take the modulo p ortion and divide by 10 to convert to a fractional representation: 62/4 = 15 62%4 = 2 2/10 = .2 15 + .2 = 15.2 ✓ Create a toString( ) method which displays all class instance data in an easy to read format. The toString() should build a string of nicely formatted data from the class and return that string . It should not display any data. The driver program wi ll decide what to do with the string. It is critical that you use the names listed in the UML diagram . The d rive r program that was given to you to work with your Horse class expects the names listed in the UML diagram. You are not to make modifications t o the driver program. To test your Horse class : • Save the HorseD river .java file in the same folder where your Horse .java class was saved. • Compile the Horse class and debug. • Compile the HorseDriver class. Errors found at this point in the driver will be related to your Horse class and NOT the HorseDriver class. Debug Horse . • When Horse and HorseDriver both compile cleanly, execute HorseDriver . This will take a while to complete if this is your first exposure to object -oriented programming. Zip your Ho rse.java and HorseDrive.jav a file s together and submit the zip file in Blackboard for grading. START EARLY – EMAIL YOUR INSTRUCTOR IF YOU HAVE QUESTIONS – LISTEN TO THE PODCAST IN BLACKBOARD.