
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Create a class to represent a Farm object containing instances of the Animal objects
Java code
![Homework 8-2
Create a class to represent a Farm object containing instances of the Animal objects
Farm
animals Animal []
farmName : String
numAnimals : int
+ Farm()
+ Farm(String)
+ Farm(int)
+ Farm(String, int)
+ addAnimal(Animal) : void
+ getFarmName(): String
+ setFarmName(String) : void
+ getAnimal(int) : Animal
+ getNumAnimals(): int
+ getFirstAnimal(): Animal
+ getLastAnimal(): Animal
+ getAnimals(): Animal[]
+ printAllDetails(): void
+ removeAnimal (int) : Animal
+ removeAllAnimals(): void
//calculated controlled variable no setter
//default 10 animals
//default 10 animals
//size of array
//return null if index is invalid
//notice no setter... this is a controlled variable
// prints Farm attributes followed by Animal attributes as formatted below:
// "FarmName: %20s | Number of Animals: %4d | Farm Size: %4d\n"
// "Name: %20s | Year of Birth: %4d | Weight: %10.2f | Gender: %c\n"
+ getTotalWeightOfAllAnimals(): double
+ getAverageWeightOfAllAnimals(): double
+ getNumberOfAnimals Above Weight(double): int
+ getNumberOfAnimals BelowWeight(double): int
+ increaseWeightOfAllAnimals(): void
+ increaseWeightOfAllAnimals (double): void](https://content.bartleby.com/qna-images/question/5c5ad030-3ec8-4fd2-8d64-821b0d0d0877/7c05e5d6-c6c1-4cc0-8653-2360d16a4228/1rgashp_thumbnail.png)
Transcribed Image Text:Homework 8-2
Create a class to represent a Farm object containing instances of the Animal objects
Farm
animals Animal []
farmName : String
numAnimals : int
+ Farm()
+ Farm(String)
+ Farm(int)
+ Farm(String, int)
+ addAnimal(Animal) : void
+ getFarmName(): String
+ setFarmName(String) : void
+ getAnimal(int) : Animal
+ getNumAnimals(): int
+ getFirstAnimal(): Animal
+ getLastAnimal(): Animal
+ getAnimals(): Animal[]
+ printAllDetails(): void
+ removeAnimal (int) : Animal
+ removeAllAnimals(): void
//calculated controlled variable no setter
//default 10 animals
//default 10 animals
//size of array
//return null if index is invalid
//notice no setter... this is a controlled variable
// prints Farm attributes followed by Animal attributes as formatted below:
// "FarmName: %20s | Number of Animals: %4d | Farm Size: %4d\n"
// "Name: %20s | Year of Birth: %4d | Weight: %10.2f | Gender: %c\n"
+ getTotalWeightOfAllAnimals(): double
+ getAverageWeightOfAllAnimals(): double
+ getNumberOfAnimals Above Weight(double): int
+ getNumberOfAnimals BelowWeight(double): int
+ increaseWeightOfAllAnimals(): void
+ increaseWeightOfAllAnimals (double): void
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In the class diagram below we have a parking charge class for an object-oriented parking system that is to be designed using java. Briefly explain any implementation decisions and the reasoning behind those without writing the complete code. N.B explain how the implementation will proceed instead of writing codearrow_forwardC# LANGUAGE polymorphism to iterate across different employees. SEE PICTURE FOR EXAMPLE OUTPUT Employee 1 is HourlyEmployeeEmployee 2 is PerDaymployeeEmployee 3 is MonthlyEmployeearrow_forwardIn java Define and create an array (called emps) of object references for objects of class Employee of length 100. (b) Create three objects for classes SalariedEmp, WeeklyEmp, and HourlyEmp (where these 3 classes are subclasses of class Employee); and with references e1, e2, e3 for the 3 objects:(c) Assign e1,e2, e3 to the first three elements of array emps:(d) Print the earnings of the 100 employee in the array emps in one loop (with polymorphism) where earnings are calculated with method earnings():arrow_forward
- Define Object .arrow_forwardJavascript Question: Part 1 Design a Pet object. A Pet is created with a language argument string and a stomach represented by an array. The Pet should support functions: eat() and speak(). Use the prototype property to define your object's interface. eat(food) will store the passed argument into its stomach and return what it has eaten thus far. speak(sentence) will simply return the passed in phrase. function Pet(language) {// create stomach// set language}// takes a food_item STRING and returns everything eaten so far ARRAYPet.prototype.eat = function(food_item) {// ... complete }// takes in a sentence STRING and returns the passed in sentence STRING with no changePet.prototype.speak = function(sentence) {// ... complete} You may also use the newer class notation. Part 2 Create an object, Dog, that implements the Pet interface and takes the same argument language. Dogs eat the same way all pets do. Dogs speak differently. Dogs replace each word in a sentence with its only known…arrow_forwardJAVA programming languagearrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education