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

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

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);
    }
}

 

 

import java.util.*;

public class Stadium
{
    private String m_name;
    private String m_city;
    private int m_capacity;
    private boolean m_kidzone;
    
    public Stadium(String name, String city, int capacity, boolean kidzone)
    {
        m_name = name;
        m_city = city;
        m_capacity = capacity;
        m_kidzone = kidzone;
    }
    
    public String getName()
    { return m_name; }
    
    public String getCity()
    { return m_city; }
    
    public int getCapacity()
    { return m_capacity; }
    
    public boolean getKidzone()
    { return m_kidzone; }
    
    @Override
    public String toString()
    { 
        String kz = getKidzone() ? "has a" : "does not have a";
        return String.format("%s, located in %s, %s kidzone.", getName(), getCity(), kz); 
    
    }
    
    static class ByKidZoneCityName implements Comparator<Stadium>
    {
      // your code goes here...
    }
}

 

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
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