Can you add the comments in this code and tell whats happening in code please import java.util.*; class Main {   static int max_kids;   HashMap> sports;   public Main(int max) {     max_kids = max;     sports = new HashMap<>();   }   static class Person {     String name;     int age;     public Person(String name, int age) {       this.name = name;       this.age = age;     }   }   static class Trainer extends Person {     int id;     public Trainer(int id, String name, int age) {       super(name, age);       this.id = id;     }   }   static class Kid extends Person {     int id;     public Kid(int id, String name, int age) {       super(name, age);       this.id = id;     }   }   static class Section {     int section;     String sports;     Trainer instructor;     int size;     HashMap Kids;     public Section(int section, String sports, Trainer instructor) {       this.section = section;       this.sports = sports;       instructor = this.instructor;       Kids = new HashMap<>();       this.size = 0;     }     public void addKid(int id, Kid s1) {       if (Kids.containsKey(id) || size == max_kids) {         System.out.println("Adding Kids to Section is not succesful");       } else {         Kids.put(id, instructor);         size++;         System.out.println("Adding Kids to Section is succesful");       }     }     public void removeKids(int id) {       if (!Kids.containsKey(id) || size == 0) {         System.out.println("Removing Kids from Section is not succesful");       } else {         Kids.remove(id);         size--;         System.out.println("Removing Kids from Section is succesful");       }     }     private void removekids(int i) {       // To change body of generated methods, choose Tools | Templates.     }   }     public void addSection(String sportscourse, Section s) {     if (!sports.containsKey(sportscourse))       sports.put(sportscourse, new ArrayList());     sports.get(sportscourse).add(s);   }   public void DisplaySection() {     for (String key : sports.keySet()) {       System.out.print("Sports with sections : ");       for (Section s : sports.get(key)) {         System.out.print(s.section + " ");       }       System.out.println();     }   }   public static void main(String args[]) {     Main cm = new Main(2);     Kid s1 = new Kid(123, "Amir", 15);     Kid s2 = new Kid(456, "Parkash", 16);     Kid s3 = new Kid(789, "JOHN CENA", 15);     Kid s4 = new Kid(901, "Monty", 17);     Trainer t1 = new Trainer(1234, "Zidane", 28);     Trainer t2 = new Trainer(1000, "IMMI Boy", 40);     Section sec1 = new Section(11, "Football", t1);     cm.addSection("Football", sec1);     Section sec2 = new Section(22, "Cricket", t2);     cm.addSection("Cricket", sec2);     sec1.addKid(123, s1);     sec1.addKid(456, s2);     sec1.addKid(789, s3);     sec1.removekids(123);     sec2.addKid(901, s4);     cm.DisplaySection();   } }

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
Can you add the comments in this code and tell whats happening in code please
import java.util.*;

class Main {
  static int max_kids;
  HashMap<String, ArrayList<Section>> sports;

  public Main(int max) {
    max_kids = max;
    sports = new HashMap<>();
  }

  static class Person {
    String name;
    int age;

    public Person(String name, int age) {
      this.name = name;
      this.age = age;
    }
  }

  static class Trainer extends Person {
    int id;

    public Trainer(int id, String name, int age) {
      super(name, age);
      this.id = id;

    }

  }

  static class Kid extends Person {
    int id;

    public Kid(int id, String name, int age) {
      super(name, age);
      this.id = id;

    }

  }

  static class Section {
    int section;
    String sports;
    Trainer instructor;
    int size;

    HashMap<Integer, Trainer> Kids;

    public Section(int section, String sports, Trainer instructor) {

      this.section = section;
      this.sports = sports;
      instructor = this.instructor;
      Kids = new HashMap<>();
      this.size = 0;

    }

    public void addKid(int id, Kid s1) {

      if (Kids.containsKey(id) || size == max_kids) {
        System.out.println("Adding Kids to Section is not succesful");

      } else {
        Kids.put(id, instructor);
        size++;
        System.out.println("Adding Kids to Section is succesful");
      }
    }

    public void removeKids(int id) {
      if (!Kids.containsKey(id) || size == 0) {
        System.out.println("Removing Kids from Section is not succesful");

      } else {
        Kids.remove(id);
        size--;
        System.out.println("Removing Kids from Section is succesful");
      }
    }

    private void removekids(int i) {
      // To change body of generated methods, choose Tools | Templates.
    }

  }

    public void addSection(String sportscourse, Section s) {
    if (!sports.containsKey(sportscourse))
      sports.put(sportscourse, new ArrayList<Section>());
    sports.get(sportscourse).add(s);

  }

  public void DisplaySection() {
    for (String key : sports.keySet()) {
      System.out.print("Sports with sections : ");
      for (Section s : sports.get(key)) {
        System.out.print(s.section + " ");
      }
      System.out.println();
    }
  }

  public static void main(String args[]) {
    Main cm = new Main(2);
    Kid s1 = new Kid(123, "Amir", 15);
    Kid s2 = new Kid(456, "Parkash", 16);
    Kid s3 = new Kid(789, "JOHN CENA", 15);
    Kid s4 = new Kid(901, "Monty", 17);

    Trainer t1 = new Trainer(1234, "Zidane", 28);
    Trainer t2 = new Trainer(1000, "IMMI Boy", 40);

    Section sec1 = new Section(11, "Football", t1);
    cm.addSection("Football", sec1);
    Section sec2 = new Section(22, "Cricket", t2);
    cm.addSection("Cricket", sec2);

    sec1.addKid(123, s1);
    sec1.addKid(456, s2);
    sec1.addKid(789, s3);
    sec1.removekids(123);
    sec2.addKid(901, s4);

    cm.DisplaySection();
  }
}

 

Expert Solution
steps

Step by step

Solved in 3 steps with 1 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