Complete the Stadium class so that it has an inner class singleton Comparator (sorting strategy) called ByKidZoneCityName that sorts using the following rules: The primary sort field should be if the stadium has a "kid zone" playground. Stadiums that have a kid zone should be listed before stadiums that do not have a kid zone. If two stadiums have the same value for the kid zone, the city (in ascending alphabetical order) should be used to determine the order. If two stadiums have the same value for the kid zone and the city, the stadium name (in ascending alphabetical order) should be used to determine the order. When you are done, your program should produce the following output: Coors Field, located in Denver, has a kidzone. Angels Stadium, located in Los Angeles, has a kidzone. Dodgers Stadium, located in Los Angeles, has a kidzone. PNC Park, located in Pittsburgh, has a kidzone. AT&T Park, located in San Francisco, has a kidzone. Citi Field, located in New York, does not have a kidzone. Yankee Stadium, located in New York, does not have a kidzone. Citizens Bank Park, located in Philadelphia, does not have a kidzone. Notice that stadiums with a kid zone are shown before stadiums without a kid zone. This is because kid zone is the primary sort field. However, for stadiums with the same value for kid zone, the city name is used to break the tie, For example, Coors Field is listed before Angels Stadium because Denver comes before Los Angeles (alphabetically). Finally, for stadiums with the same value for kid zone and city name, the stadium name is used as the tie breaker. For example, City Field is listed before Yankee stadium because Citi Field comes before Yankees Stadium (alphabetically).   import java.util.*; public class Main {     public static void main(String[] args)     {         Main m = new Main();         m.go();     }          private void go()     {         List parks = new ArrayList();                  parks.add(new Stadium("PNC Park", "Pittsburgh", 38362, true));         parks.add(new Stadium("Dodgers Stadium", "Los Angeles", 56000, true));         parks.add(new Stadium("Citizens Bank Park", "Philadelphia", 43035, false));         parks.add(new Stadium("Coors Field", "Denver", 50398, true));         parks.add(new Stadium("Yankee Stadium", "New York", 54251, false));         parks.add(new Stadium("AT&T Park", "San Francisco", 41915, true));         parks.add(new Stadium("Citi Field", "New York", 41922, false));         parks.add(new Stadium("Angels Stadium", "Los Angeles", 45050, true));                  Collections.sort(parks, Stadium.ByKidZoneCityName.getInstance());         for (Stadium s : parks)             System.out.println(s);     } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Complete the Stadium class so that it has an inner class singleton Comparator (sorting strategy) called ByKidZoneCityName that sorts using the following rules:

  • The primary sort field should be if the stadium has a "kid zone" playground. Stadiums that have a kid zone should be listed before stadiums that do not have a kid zone.
  • If two stadiums have the same value for the kid zone, the city (in ascending alphabetical order) should be used to determine the order.
  • If two stadiums have the same value for the kid zone and the city, the stadium name (in ascending alphabetical order) should be used to determine the order.

When you are done, your program should produce the following output:

Coors Field, located in Denver, has a kidzone.

Angels Stadium, located in Los Angeles, has a kidzone.

Dodgers Stadium, located in Los Angeles, has a kidzone.

PNC Park, located in Pittsburgh, has a kidzone.

AT&T Park, located in San Francisco, has a kidzone.

Citi Field, located in New York, does not have a kidzone.

Yankee Stadium, located in New York, does not have a kidzone.

Citizens Bank Park, located in Philadelphia, does not have a kidzone.

Notice that stadiums with a kid zone are shown before stadiums without a kid zone. This is because kid zone is the primary sort field. However, for stadiums with the same value for kid zone, the city name is used to break the tie, For example, Coors Field is listed before Angels Stadium because Denver comes before Los Angeles (alphabetically). Finally, for stadiums with the same value for kid zone and city name, the stadium name is used as the tie breaker. For example, City Field is listed before Yankee stadium because Citi Field comes before Yankees Stadium (alphabetically).

 

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Main m = new Main();
        m.go();
    }
    
    private void go()
    {
        List<Stadium> parks = new ArrayList<Stadium>();
        
        parks.add(new Stadium("PNC Park", "Pittsburgh", 38362, true));
        parks.add(new Stadium("Dodgers Stadium", "Los Angeles", 56000, true));
        parks.add(new Stadium("Citizens Bank Park", "Philadelphia", 43035, false));
        parks.add(new Stadium("Coors Field", "Denver", 50398, true));
        parks.add(new Stadium("Yankee Stadium", "New York", 54251, false));
        parks.add(new Stadium("AT&T Park", "San Francisco", 41915, true));
        parks.add(new Stadium("Citi Field", "New York", 41922, false));
        parks.add(new Stadium("Angels Stadium", "Los Angeles", 45050, true));
        
        Collections.sort(parks, Stadium.ByKidZoneCityName.getInstance());
        for (Stadium s : parks)
            System.out.println(s);
    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY