Starting from:
$35

$29

PMT: Farmer Fisher’s Livestock Solution

James Fisher owns a farm on the outskirts of Wichita Falls, Texas. He raises livestock and sells them for profit. Farmer Fisher wants to automate the accounting for his livestock sales. He currently raises three types of animals on his farm: Alpacas, Camels, and Donkeys. The prices for the animals are determined as follows:




Alpacas: An alpaca three years of age or below is sold for $10,000. An alpaca above three years of age, weighing 300 pounds (lbs) or less is sold for $80,000 while one weighing more than 300lbs is sold for $100,000.




Camels: A camel three years or younger sells for $50,000. The price for camels above three years old depends on how many humps they have: camels with two humps are sold for $150,000 while camels with three humps are sold for $200,000.




Donkeys: There are three breeds on Farmer Fisher’s farm: Miniature, Burro, and American Mammoth Jack. All donkeys below three years of age are sold for $20,000. Miniature donkeys above three years are sold for $100,000, Burros above three are sold for $120,000, while American Mammoth Jacks above three are sold for $180,000.




Write a Java application to assist Farmer Fisher in computing revenue from the sale of his livestock.

Your application should have the following classes along with the interfaces provided:




Livestock (an abstract class) which implements the ILivestock interface;



Classes Alpaca, Camel, and Donkey which are subclasses of Livestock.



Class FarmApp which implements the interface IFarmApp.



The test class FarmTestClass which is provided and should not be modified.



You may add additional methods as needed in your classes.




public interface ILivestock {

/**




Return this animal's age.



@return This animal's age.
*/




int getAge();




/**

Return the type of this animal (Alpaca, Camel or Donkey)



@return The type of this animal
*/

String getAnimalType();




/**




Determine and return the price of this animal.



@return The price of this animal.
*/




double getPrice();




}

public interface IFarmApp {

/**




Return an arrayList of the animals sold



@return A list of the animals sold
*/

List<ILivestock getLivestock();




/**

Add the animal object to the list of livestock sold.



@param mThe animal to be added
*/




void addLivestock(ILivestock m);




/**




Computes and returns the total price of all the animals sold.



@return Total price of all animals sold.
*/




double getTotalPrice();




}




Also, you should test your classes using the test class below:




public class FarmTestClass {




public static void main(String[] args) {




TODO Auto-generated method stub IFarmApp farm = new FarmApp();
ILivestock animal1 = new Alpaca(5, 600); // Parameters:(int age, int

weight)




ILivestock animal2 = new Camel(5, 3); // Parameters: (int age, int numberOfHumps)




ILivestock animal3 = new Donkey(6, "Miniature"); // Parameters: (int age, String breed)




farm.addLivestock(animal1);

farm.addLivestock(animal2);

farm.addLivestock(animal3);




List<ILivestock animals = farm.getLivestock();




System.out.println("List of Animals Sold"); System.out.println("====================\n");




for(int i = 0; i < animals.size(); i++) { System.out.printf("%s \t$ %,10.2f\n",

animals.get(i).getAnimalType(), animals.get(i).getPrice());




}




System.out.printf("\nTotal Sales: \t$ %,10.2f\n\n", farm.getTotalPrice());




ILivestock animal4 =
new
Donkey(2, "American Mammoth Jack"); //
Parameters: (int age, String
breed)












ILivestock animal5 =
new
Donkey(7, "Burro"); // Parameters: (int
age, String breed)






ILivestock animal6 = new Alpaca(2, 250); // Parameters:(int age, int

weight)




farm.addLivestock(animal4);




farm.addLivestock(animal5);

farm.addLivestock(animal6);




for(int i = 0; i < animals.size(); i++) { System.out.printf("%s \t$ %,10.2f\n",

animals.get(i).getAnimalType(), animals.get(i).getPrice());

}




System.out.printf("\nTotal Sales: \t$ %,10.2f\n", farm.getTotalPrice());







}




}




Expected output:

List of Animals Sold




====================




Alpaca
$ 100,000.00
Camel
$ 200,000.00
Donkey
$ 100,000.00
Total Sales:


$ 400,000.00
Alpaca
$ 100,000.00
Camel
$ 200,000.00
Donkey
$ 100,000.00
Donkey
$
20,000.00
Donkey
$ 120,000.00
Alpaca
$
10,000.00
Total Sales:


$ 550,000.00



PMT Submission

Ask the lab instructor to test your program before you turn it in to the dropbox in elearning.

More products