do the changes in this program according to the given instruction like coaches instead of teachers,sports name instead of courses etc, import java.util.*; class CourseManager{ //toatl students each section can hold static int max_Students; //mapping of each sections w.r.t to course HashMap > courses ; //constructor for CourseManager public CourseManager(int max){ max_Students = max; courses = new HashMap<>(); } //class Person which will be used by teacher and students to inherit its properties static class Person{ String name; int age; public Person(String name , int age ) { this.name = name; this.age = age; } } //teacher class static class Teacher extends Person{ int id; public Teacher(int id , String name , int age ) { super(name , age ); this.id = id; } } //student class static class Student extends Person{ int id; public Student(int id , String name , int age ) { super(name , age ); this.id = id; } } //section class static class Section { int section; String course ; Teacher instructor; int size ; HashMap students; //constructor public Section(int section , String course , Teacher instructor) { this.section = section; this.course = course; instructor = this.instructor; students = new HashMap<>(); this.size = 0; } //function to add students public void addStudent(int id ,Student s1) { if(students.containsKey(id) || size == max_Students) { System.out.println("Adding student to Section is not succesful"); } else { students.put(id ,s1); size++; System.out.println("Adding student to Section is succesful"); } } //function to remove student public void removeStudent(int id ) { if(!students.containsKey(id) || size == 0) { System.out.println("Removing student from Section is not succesful"); } else { students.remove(id); size--; System.out.println("Removing student from Section is succesful"); } } } // function of course manager to map section with their courses public void addSection(String course , Section s) { if(!courses.containsKey(course)) courses.put(course,new ArrayList()); courses.get(course).add(s); } //function to display the section w.r.t its courses public void DisplaySection() { for(String key : courses.keySet()) { System.out.print("Courses with sections : "); for(Section s : courses.get(key)) { System.out.print(s.section +" "); } System.out.println(); } } public static void main(String args[]) { //course manager object CourseManager cm = new CourseManager(2); //some students object Student s1 = new Student(123,"John",15); Student s2 = new Student(456 , "Paul" ,16); Student s3 = new Student(789 , "Chris" ,15); Student s4 = new Student(901 , "Morris" ,17); //some teacher object Teacher t1 = new Teacher(1234 , "Sophie" , 28); Teacher t2 = new Teacher(1000 , "Alena" , 40); //creating section and mapping them with the courses Section sec1 = new Section(11,"M54",t1); cm.addSection("M54", sec1); Section sec2 = new Section(22,"C11",t2); cm.addSection("M55", sec2); //adding and removing students sec1.addStudent(123, s1); sec1.addStudent(456, s2); sec1.addStudent(789, s3); sec1.removeStudent(123); sec2.addStudent(901, s4); //display the section w.r.t its courses cm.DisplaySection(); } }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter2: Problem Solving Using C++using
Section2.1: Introduction To C++
Problem 13E: (Practice) You’re responsible for planning and arranging the family camping trip this summer. List a...
icon
Related questions
Question

do the changes in this program according to the given instruction

like coaches instead of teachers,sports name instead of courses etc,

import java.util.*;
class CourseManager{
//toatl students each section can hold
static int max_Students;
//mapping of each sections w.r.t to course
HashMap<String,ArrayList<Section> > courses ;

//constructor for CourseManager
public CourseManager(int max){
max_Students = max;
courses = new HashMap<>();
}
//class Person which will be used by teacher and students to inherit its properties
static class Person{
String name;
int age;

public Person(String name , int age )
{
this.name = name;
this.age = age;
}
}
//teacher class
static class Teacher extends Person{
int id;

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

}

}
//student class
static class Student extends Person{
int id;

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

}

}
//section class
static class Section
{
int section;
String course ;
Teacher instructor;
int size ;
HashMap<Integer ,Student > students;
//constructor
public Section(int section , String course , Teacher instructor)
{
this.section = section;
this.course = course;
instructor = this.instructor;
students = new HashMap<>();
this.size = 0;

}
//function to add students
public void addStudent(int id ,Student s1)
{
if(students.containsKey(id) || size == max_Students)
{
System.out.println("Adding student to Section is not succesful");

}
else
{
students.put(id ,s1);
size++;
System.out.println("Adding student to Section is succesful");
}
}
//function to remove student
public void removeStudent(int id )
{
if(!students.containsKey(id) || size == 0)
{
System.out.println("Removing student from Section is not succesful");

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

}
// function of course manager to map section with their courses
public void addSection(String course , Section s)
{
if(!courses.containsKey(course))
courses.put(course,new ArrayList<Section>());
courses.get(course).add(s);

}
//function to display the section w.r.t its courses
public void DisplaySection()
{
for(String key : courses.keySet())
{
System.out.print("Courses with sections : ");
for(Section s : courses.get(key))
{
System.out.print(s.section +" ");
}
System.out.println();
}
}
public static void main(String args[])
{
//course manager object
CourseManager cm = new CourseManager(2);

//some students object
Student s1 = new Student(123,"John",15);
Student s2 = new Student(456 , "Paul" ,16);
Student s3 = new Student(789 , "Chris" ,15);
Student s4 = new Student(901 , "Morris" ,17);

//some teacher object
Teacher t1 = new Teacher(1234 , "Sophie" , 28);
Teacher t2 = new Teacher(1000 , "Alena" , 40);

//creating section and mapping them with the courses
Section sec1 = new Section(11,"M54",t1);
cm.addSection("M54", sec1);
Section sec2 = new Section(22,"C11",t2);
cm.addSection("M55", sec2);

//adding and removing students
sec1.addStudent(123, s1);
sec1.addStudent(456, s2);
sec1.addStudent(789, s3);
sec1.removeStudent(123);
sec2.addStudent(901, s4);

//display the section w.r.t its courses
cm.DisplaySection();
}
}

Overview:
A Sports Club is an organization formed in order to help its members develop interest in certain
sports.
Usually, members interested in the same sport are divided into groups and an expert trainer is
responsible for training each group.
it is required to help the head of a Sports Club for kids implement application to
keep track of the kids (members of the club) and the sports they are interested in.
Requirements:
After a quick meeting with the head of the sports club, you got the following information:
• It is required to store the whole data (all groups of all sports) in one collection.
• Each group has a number, a trainer and they are interested in a certain sport (e.g. footballI).
In addition, it contains many kids with flexibility of adding and removing kids within a given
limit for the maximum number of kids who could be in the same group (where this limit is
fixed and unified for all groups). Furthermore, there are other attributes (add at least 2
attributes from your choice). Group number is unique for each sport.
• Each trainer has a unique ID, a name and other attributes (add at least 3 attributes from
your choice). He/she could train more than one sport.
• Each kid has a unique ID, a name and other attributes (add at least 2 attributes from your
choice).
Moreover, you have been informed that the following operations happen frequently:
• Forming a new group
• Adding a kid to a specified group
• Removing a kid from a specified group
• Retrieving the average number of kids per group of a certain sport
• Displaying all groups in a format similar to the following:
sport1: groupNo1 groupNo2 groupNo3 ..
sport2: groupNo1 groupNo2 groupNo3 ..
where sports and groups are sorted in ascending order
• Saving all the groups into a text file
Analysis:
Q1: There are common attributes and methods between kids and trainers. What is the best
choice for designing and writing the codes of these two classes? Explain your answer.
Q2: Draw a simple class diagram showing only relationships between the classes.
Transcribed Image Text:Overview: A Sports Club is an organization formed in order to help its members develop interest in certain sports. Usually, members interested in the same sport are divided into groups and an expert trainer is responsible for training each group. it is required to help the head of a Sports Club for kids implement application to keep track of the kids (members of the club) and the sports they are interested in. Requirements: After a quick meeting with the head of the sports club, you got the following information: • It is required to store the whole data (all groups of all sports) in one collection. • Each group has a number, a trainer and they are interested in a certain sport (e.g. footballI). In addition, it contains many kids with flexibility of adding and removing kids within a given limit for the maximum number of kids who could be in the same group (where this limit is fixed and unified for all groups). Furthermore, there are other attributes (add at least 2 attributes from your choice). Group number is unique for each sport. • Each trainer has a unique ID, a name and other attributes (add at least 3 attributes from your choice). He/she could train more than one sport. • Each kid has a unique ID, a name and other attributes (add at least 2 attributes from your choice). Moreover, you have been informed that the following operations happen frequently: • Forming a new group • Adding a kid to a specified group • Removing a kid from a specified group • Retrieving the average number of kids per group of a certain sport • Displaying all groups in a format similar to the following: sport1: groupNo1 groupNo2 groupNo3 .. sport2: groupNo1 groupNo2 groupNo3 .. where sports and groups are sorted in ascending order • Saving all the groups into a text file Analysis: Q1: There are common attributes and methods between kids and trainers. What is the best choice for designing and writing the codes of these two classes? Explain your answer. Q2: Draw a simple class diagram showing only relationships between the classes.
Implementation:
After analysing the given requirements, implement the required application:
• with Object Oriented Programming style
• following the rules of good programming style (e.g. adding comments, etc.)
• using only the material covered in M251 (and its prerequisites)
Hints:
• For each class, it is required to implement constructors, setters, getters, toString() method,
and any other necessary method
• If the user tries to do an operation that could violate the state of objects, the operation
should be ignored and the application should display an error message (e.g. adding a kid to
the same group twice, etc.)
• Checking equality of any 2 objects should be done via the equals() method
• There is a class that will do the main job of keep tracking of the kids as follows:
o It has one collection to store the whole data (all groups of all sports)
o It has static methods, one for each operation happens frequently
o For each adding or removing operation, a message should be displayed to the user to
explain the status of the operation (i.e. if it was successful or not)
Testing:
After implementing the required classes, design and implement a testing class to test them as
follows:
• Create at least 7 groups of at least 3 sports and add them to the collection that stores the
whole data then add and remove some kids from them.
• Try to violate the state of the objects and show that your code prevents all violations.
• Show that the other operations that happen frequently are working fine.
At the end, the whole data should be saved into a text file and this file should be saved
automatically inside the folder contains your Java project.
Transcribed Image Text:Implementation: After analysing the given requirements, implement the required application: • with Object Oriented Programming style • following the rules of good programming style (e.g. adding comments, etc.) • using only the material covered in M251 (and its prerequisites) Hints: • For each class, it is required to implement constructors, setters, getters, toString() method, and any other necessary method • If the user tries to do an operation that could violate the state of objects, the operation should be ignored and the application should display an error message (e.g. adding a kid to the same group twice, etc.) • Checking equality of any 2 objects should be done via the equals() method • There is a class that will do the main job of keep tracking of the kids as follows: o It has one collection to store the whole data (all groups of all sports) o It has static methods, one for each operation happens frequently o For each adding or removing operation, a message should be displayed to the user to explain the status of the operation (i.e. if it was successful or not) Testing: After implementing the required classes, design and implement a testing class to test them as follows: • Create at least 7 groups of at least 3 sports and add them to the collection that stores the whole data then add and remove some kids from them. • Try to violate the state of the objects and show that your code prevents all violations. • Show that the other operations that happen frequently are working fine. At the end, the whole data should be saved into a text file and this file should be saved automatically inside the folder contains your Java project.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr