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...





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

  }

}


Jun 01, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here