Question: In this problem you will implement a solution using the design pattern for collecting objects. We are going to model a PreSchool. A PreSchool uses

In this problem you will implement a solution using the design pattern for collecting objects. We are going to model a PreSchool. A PreSchool uses an ArrayList to keep track of Toddlers. You will write the PreSchool class. You need to copy the starter code from Codecheck The Toddler class is provided for you in Codecheck. A Toddler represents a 1 to 3 year old child. A Toddler has a String name, a double height, and an int weight. It also has a toString method. You can view the documentation in Bluej. A PreSchool has an ArrayList of Toddlers as an instance variable. Call the instance variable "kids". It has a constructor that takes no parameters. The constructor needs to initialize the ArrayList of Toddlers to an empty ArrayList. You can get the starter code from Codecheck It has methods public void add(Toddler t) adds the specified Toddler to the PreSchool public Toddler tallest() gets the Toddler with the greatest height. If two have that same height, get the first one that occurs in the list. If the ArrayList is empty, return null public int studentCount() gets the number of Toddlers in this PreSchool. This is provided for you. (That is why you need to name the instance variable kids.)

WRITE CODE IN JAVA

Use the following files:

PreSchoolTester.java

public class PreSchoolTester { public static void main(String[] args) { PreSchool school = new PreSchool(); school.add(new Toddler("Sean", 38.0, 40)); school.add(new Toddler("Anwen", 42.0, 47)); school.add(new Toddler("Taran", 36.0, 40)); school.add(new Toddler("Jaime", 40.0, 44)); System.out.println(school.studentCount()); System.out.println("Expected: 4"); System.out.println(school.tallest()); System.out.println("Expected: Toddler[name=Anwen,height=42.0,weight=47]"); PreSchool empty = new PreSchool(); System.out.println(empty.tallest()); System.out.println("Expected: null"); } } 

Toddler.java

/** * Models a toddler - a one to three year * old child */ public class Toddler { private String name; private double height; private int weight; /** * Constructs a Toddler with the given parameters * @param name the name of this Toddler * @param height the height of this Toddler * @param weight the weight of this Toddler */ public Toddler(String name, double height, int weight) { this.name = name; this.height = height; this.weight = weight; } /** * Gets the name of this Toddler * @return the name of this Toddler */ public String getName() { return name; } /** * Gets the height of this Toddler * @return the height of this Toddler */ public double getHeight() { return height; } /** * Gets the weight of this Toddler * @return the weight of this Toddler */ public int getWeight() { return weight; } @Override public String toString() { String s = "Toddler[name=" + name + ",height=" + height + ",weight=" + weight +"]"; return s; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!