Lab 4
Get started now

Objectives

  • Translation problem statement into a software design
  • Make use of interfaces in software design
  • Implement a small software project based off of a software design

Assignment

Bantum Fjord is a farmer and precious metals trader. He is a strange fellow with some interesting software needs. You will design a set of classes and one or more interfaces to meet a set of requirements.

Details

Bantum currently has horses and chickens on his farm. To supplement his income, he trades gold and silver.

For this assignment you will need to do the following:

  • Read and understand Mr. Fjord's requirements
  • Create a software design and use a UML class diagram to illustrate it
  • Implement a software solution

Bantum wants you to write a software program that will help him with his business and with his emotions. The program will list all of the animals and precious metals in his portfolio and each one's value. This will help Bantum run his business. Bantum is a very sentimental person and he is concerned that transitioning to running his business on a computer will cause him to treat his animals as property rather than the wonderful animals he knows and loves. To help aleviate this concern, Bantum has required that the program be able to play the sound that each animal makes.

Resources Available for Your Use

Bantum doesn't know anything about writing software, but he does know how to use Google and was able to find a few files that he thinks would be useful to you.

  • MetalsPricing.java - A class that fetches the current market price for an ounce of gold and an ounce of silver.
  • WavPlayer.java - A class that can be used to play .wav audio files.
  • animalSounds.zip - A collection of .wav files containing animal sounds.

Both the MetalsPricing and WavPlayer classes are in the edu.msoe.se1021.lab4 package (create the appropriate folder structure and place these files in the correct folder for you project).

What Needs to be Done

Mr. Fjord has all of his silver holdings in 1 oz bars and his gold holdings in 1/2 oz American Gold Eagle coins. He would like you to design and write software that will allow him to enter the number of horses and chickens that he has along with the amount of gold and silver (in ounces). Your program should create an object for each horse and chicken on his farm and the appropriate number of gold coins and silver bars to represent his precious metal collection.

In order to reduce the amount of data entry for your program a random number generator should be used to assign a specific age and weight to each horse when it is created. Similarly, each chicken should be assigned an age and weight. In addition, each chicken should be designated was either a layer (good for eggs) or a broiler (good for meat). To keep things simple, horses should range in age from 2 to 25 years old and chickens should range in age from 0 to 8 years old. Horses should weigh between 500 and 1500 pounds and chickens should weigh between 2.5 and 6.5 pounds.

All of the items in Bantum's portfolio (animals and precious metals) should be placed in a list and shuffled. If your list is called portfolio, you can shuffle the list with the following line of Java code:

  Collections.shuffle(portfolio);

Once shuffled, the program should display the market price of each item in the portfolio along with a description of the object. The total value of the portfolio should then be displayed on the last line. Your output should look similar to the following:

$560.00 for A 11 year old horse weighing 1,483.00 pounds
$615.35 for A half ounce American Gold Eagle
$2.61 for A 3 year old, broiler weighing 2.51 pounds
$17.43 for A one ounce silver bar
$17.43 for A one ounce silver bar
$3.07 for A 3 year old, broiler weighing 2.95 pounds
$17.43 for A one ounce silver bar
$392.56 for A 23 year old horse weighing 1,402.00 pounds
$24.00 for A 0 year old, egg layer weighing 4.69 pounds
Total price: $1,674.20

Dollar amounts and weights should be display with two digits to the right of the decimal place. As the information about each animal is displayed, the sound the animal makes should be played.

Calculating the Value of the Portfolio

Market Price for Horse

If the horse is less than 90% of the maximum age for a horse, then the market price is determined by: $1000 * (the percentage of life remaining for the horse). You should assume that every horse lives to the maximum age of a horse.

Otherwise, the market price is: $0.28 * (weight in pounds).

Market Price for Chicken

If the chicken is a broiler (not a layer), the market price is: $1.04 * (weight in pounds).

Otherwise, the market price is the larger of the above price and: $3 * ( (maximum chicken age) - (age) ).

Market Price for Precious Metals

Use the MetalsPricing class to look up the market prices for gold and silver (by the ounce).

Making Sounds

In addition to displaying all of the items in Bantum's portfolio, whenever an animal is encountered, the program should play the sound the animal makes. This will help bring back fond memories of his animals and make Bantum happier when using your software. The WavPlayer class and .wav files in the animalSounds.zip file should be used to accomplish this.

Design Constraints

You are required to create a design for your software and document this design with a UML class diagram that shows the appropriate relationships between the classes. Your design must meet the following specifications:

  • You must make use of at least one interface.
  • You must have a separate class to represent each animal and precious metal type.
  • Your design must allow for all animals and precious metals to be stored in one ArrayList.
  • All of your classes/interfaces must be in a package that is your username.
  • Your program may assume that only positive integer values are entered by the user.

Just For Fun

Bantum does have dreams of one day expanding his operation to include sheep, turkeys, cattle, and pigs. His daughter would like to have a dog or two. Animal sound files for these animals are included in the lab4.zip file. You may want to use these to add additional animals to the mix. Feel free to invent your own schemes for determining the market price of these animals.

Lab Deliverables

See your professor's instructions for details on submission guidelines and due dates.
Dr. Dennis' students: See Blackboard
See Dr. Rebenitsch for instructions
Dr. Taylor's students: See below
See Prof. Ung for instructions
If you have any questions, consult your instructor.

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.

Tuesday, 10-Jan-2017 00:00:33 EST