CSCE 145 Lab Test 2

Section 4

This lab is to be done with NO COMMUNICATION with others. You MAY use your book, notes, class slides on Blackboard, APIs (Java and Robots), past labs, and past homework; basically any materials directly related to the class. Outside materials or help from others is not allowed. You must dropbox the .java files by the end of this lab period (see bottom of page).

Overview

You will create a simple program to keep track of horses owned by a farm.

Program

You need to create 2 classes, Horse and Farm. Horse has 2 instance variables: (String) breed, and (String) name. Farm holds exactly 3 Horse objects as instance variables. The Farm class has a method called public void showFarm( ) that prints out the all the horses on the farm. EACH CLASS should have accessors and mutators for all instance variables and 2 constructors: one a default (no parameters) and the other accepts parameters for all variables.

Create a driver that interacts with a user via the console. The program should ask the user for the 3 horses, put them into a  new Farm object, then print the entire contents of the Farm. You can assume the user will enter the information in exactly the same format (name, a comma, breed) as shown in the example below.

In order to use a 'comma' as the delimiter when reading in the Shoe information from the console, use the following piece of code to instantiate the Scanner object.
Scanner console = new Scanner(System.in).useDelimiter(",");
In the past we have used the Scanner class with the default 'space' delimiter. Using a 'comma' as the delimiter will result in console.next( ) returning the next sequence of characters until a 'comma' is encountered. This said, you might have to do multiple console.next( ) calls to get all the console input.

Example Output

Please enter horse 1:

Pretty Fairy, Albanian

Please enter horse 2:

Joe, Gotland

Please enter horse 3:

Galoppy, Hackney

The horses on the farm are:

Pretty Fairy, a(n) Albanian

Joe, a(n) Gotland

Galoppy, a(n) Hackney

 

DROPBOX YOUR .java FILES BEFORE 12:55pm (end of lab)! Don't wait until the last minute!