Create a class to represent a Infant object that inherits from (extends) the Person class. Use the description provided below in UML. Create a nested class named InfantToy within the Infant class   Infant InfantToy //an inner class (non-static) infantToyName: String infantToyRating: int         + InfantToy(String, int)       + toString() : String Infant (continued) toys : BabyToy [ ] numBabyToys : int   Infant() //an Infant with zero InfantToys but array capacity of 10 Infant(String, int, double, double, char, int) //pass values to parent class’s overloaded constructor //Infant cannot have offSpring therefore pass a zero to the parent constructor addInfantToy(String,int) //uses the InfantToy constructor, do not resize array getInfantToyAsString(int) : String //when the index is invalid, return "invalid index "+index  getNumInfantToys() : int getInfantToyName(int) : String getInfantToyRating(int) : int getHighestInfantToyRating(): int //should return the highest rating, or 0 if the array is empty printDetails() : void @Override //see NOTE below for formatting toString() : String @Override //see NOTE below for formatting NOTE1:  For both the printDetails() and toString() methods include the data from the Passenger class, as well as Person attributes.  Format the Infant data as “Infant: Number of Toys: %4d | Infant Toys:\n” followed by the  formatted InfantToy String for each toy on its own line as  “InfantToy: Toy Name: %20s | Rating %4d\n”   NOTE2: In the Infant class do not override the equals method inherited from the Person class NOTE3: In the Infant class do not resize the toys array. The max capacity should remain 10   Hint1: Use super.printDetails() and super.toString() Hint2: InfantToy is immutable (i.e. no setter methods, it’s values cannot be changed) Hint3: InfantToy belongs to Infant only, which is why it is a nested class Hint4: toString() inside the InfantToy should be formatted as “InfantToy: Toy Name: %20s | Rating %4d\n” Hint5: toString() inside the Infant should iterate through toys and append the String returned from each InfantToy

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Create a class to represent a Infant object that inherits from (extends) the Person class. Use the description provided below in UML. Create a nested class named InfantToy within the Infant class

 

Infant

InfantToy //an inner class (non-static)

  • infantToyName: String
  • infantToyRating: int

 

      + InfantToy(String, int)

      + toString() : String

Infant (continued)

  • toys : BabyToy [ ]
  • numBabyToys : int

 

  • Infant() //an Infant with zero InfantToys but array capacity of 10
  • Infant(String, int, double, double, char, int) //pass values to parent class’s overloaded constructor

//Infant cannot have offSpring therefore pass a zero to the parent constructor

  • addInfantToy(String,int) //uses the InfantToy constructor, do not resize array
  • getInfantToyAsString(int) : String //when the index is invalid, return "invalid index "+index 
  • getNumInfantToys() : int
  • getInfantToyName(int) : String
  • getInfantToyRating(int) : int
  • getHighestInfantToyRating(): int //should return the highest rating, or 0 if the array is empty
  • printDetails() : void @Override //see NOTE below for formatting
  • toString() : String @Override //see NOTE below for formatting



NOTE1: 

For both the printDetails() and toString() methods include the data from the Passenger class, as well as Person attributes. 

Format the Infant data as “Infant: Number of Toys: %4d | Infant Toys:\n” followed by the 

formatted InfantToy String for each toy on its own line as  “InfantToy: Toy Name: %20s | Rating %4d\n”

 

NOTE2:

In the Infant class do not override the equals method inherited from the Person class

NOTE3:

In the Infant class do not resize the toys array. The max capacity should remain 10

 

Hint1: Use super.printDetails() and super.toString()

Hint2: InfantToy is immutable (i.e. no setter methods, it’s values cannot be changed)

Hint3: InfantToy belongs to Infant only, which is why it is a nested class

Hint4: toString() inside the InfantToy should be formatted as “InfantToy: Toy Name: %20s | Rating %4d\n”

Hint5: toString() inside the Infant should iterate through toys and append the String returned from each InfantToy



Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Reference Types in Function
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education