diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml new file mode 100644 index 0000000..1f2ea11 --- /dev/null +++ b/.idea/copilot.data.migration.ask2agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index fdc35ea..17e9c2e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java deleted file mode 100644 index 435139b..0000000 --- a/src/main/java/org/codedifferently/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.codedifferently; - -//TIP To Run code, press or -// click the icon in the gutter. -public class Main { - public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); - - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/cbtyson/Main.java b/src/main/java/org/codedifferently/cbtyson/Main.java new file mode 100644 index 0000000..2a2a513 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/Main.java @@ -0,0 +1,15 @@ +package org.codedifferently.cbtyson; + +import org.codedifferently.cbtyson.menus.MainMenu; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + + MainMenu mainMenu = new MainMenu(); + mainMenu.promptMainMenu(); + + + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/cbtyson/README.md b/src/main/java/org/codedifferently/cbtyson/README.md new file mode 100644 index 0000000..ddbfdce --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/README.md @@ -0,0 +1,240 @@ +# Group Differently +## The Mission + +Group Differently is a **Java command-line application** designed to help organize students into groups efficiently. + +The goal of this program is to simulate a real-world classroom scenario where instructors or organizers need to: + +- Create and manage students +- Create groups +- Assign students to groups +- Shuffle students across groups +- Move students between groups when adjustments are needed + +Instead of manually organizing groups, this application allows users to manage and restructure teams quickly using simple command-line controls. + +This project demonstrates our ability to: + +* Design software systems +* Structure Java programs effectively +* Apply object-oriented programming concepts +* Collaborate with a partner using Agile principles +* Explain our technical decisions through documentation and comments + +--- + +# Theme: Everyday Application + +Group Differently represents a **real-world system used in classrooms, training programs, and team-based environments**. + +Teachers, instructors, or team leaders often need to divide people into balanced groups. This application simplifies that process by allowing users to organize and shuffle group assignments automatically while still allowing manual adjustments when necessary. + +--- + +# Team Structure + +This project was developed **in pairs**. + +Using our **Certified Scrum Master knowledge**, we organized development into **three sprint phases**. + +Each sprint allowed us to progressively design, implement, and evaluate our system. + +--- + +# Sprint Documentation + +--- + +## Sprint 1 — The Plan + +Before writing code, we planned the structure of the system. + +### Problem the Program Solves + +Instructors often need to divide students into groups for: + +- Projects +- Discussions +- Lab assignments +- Team activities + +Manually organizing groups can be time-consuming, especially when groups must be balanced or frequently adjusted. + +Group Differently provides a simple system for managing students and distributing them into groups automatically or manually. + +### Planned Features + +We planned the following core features: + +1. Add Student +2. Add Group +3. View Groups and Students +4. Move students from one group to another +5. Remove a student from a group +6. Shuffle students into groups based on a preferred team size +7. Exit the program + +### Expected Classes + +We expected to create several classes to organize the program: + +**Student** + +Stores student information including: + +- ID +- First name +- Last name +- Email +- Age +- GPA + +**Group** + +Represents a group with: + +- Group ID +- Group name +- A list of students assigned to the group + +**Main / Application Class** + +Handles: + +- User input +- Menu navigation +- Program execution + +**Manager / Controller Class (optional)** + +Responsible for managing collections of students and groups. + +### Work Division + +Our team divided the work so both partners contributed to different parts of the system, including: + +- Designing the data structures +- Implementing student and group classes +- Implementing menu functionality +- Implementing shuffle and group management logic +- Testing program behavior + +--- + +## Sprint 2 — The Build + +During this phase we implemented the core functionality of the program. + +### Implemented Features + +The final program allows users to: + +1. **Add Student** + +Users can create students with: + +- ID +- First Name +- Last Name +- Email +- Age +- GPA + +2. **Add Group** + +Users can create groups with: + +- Group ID +- Group name + +3. **View Groups and Students** + +Users can display all groups and the students assigned to them. + +4. **Move Student Between Groups** + +Students can be transferred from one group to another using their **Student ID**. + +5. **Remove Student From Group** + +Students can be removed from a group if they need to be reassigned. + +6. **Shuffle Groups** + +The shuffle feature allows users to enter a **preferred team size**. +The program distributes students across available groups while trying to keep the groups balanced. + +7. **Exit Program** + +Allows the user to safely terminate the application. + +### Program Menu + +When the program starts, the user sees a command-line menu: + + +### Challenges Encountered + +Some challenges included: + +- Designing a system to efficiently search students and groups +- Ensuring groups remained balanced during shuffling +- Managing relationships between students and groups +- Handling user input safely in the command line + +### Solutions + +To solve these challenges we: + +- Used **IDs for students and groups** to simplify searching +- Used **collections such as ArrayList** to store dynamic lists of students and groups +- Built methods that handle student movement and group assignment cleanly + +--- + +## Sprint 3 — The Reflection + +### What Works Well + +The program successfully allows users to: + +- Manage students and groups +- Automatically distribute students across groups +- Adjust group assignments manually +- View organized group information easily + +The menu system provides a simple interface for interacting with the program. + +### Improvements With More Time + +If we had more time, we would improve the program by adding: + +- Data persistence (saving students and groups to files) +- A graphical user interface (GUI) +- More advanced shuffle algorithms +- GPA-based or skill-based group balancing +- Editing or updating student information + +### Java Concepts Used + +This project heavily utilized several core Java concepts: + +- **Classes and Objects** +- **Constructors** +- **Encapsulation with getters and setters** +- **Collections (ArrayList)** +- **Loops** +- **Conditional statements** +- **User input with Scanner** +- **Method organization and modular design** + +### What We Learned + +This project helped us better understand: + +- How to design object-oriented programs +- How to manage relationships between objects +- How to structure larger Java programs +- How to document and explain software design decisions + +--- \ No newline at end of file diff --git a/src/main/java/org/codedifferently/cbtyson/data/Group.java b/src/main/java/org/codedifferently/cbtyson/data/Group.java new file mode 100644 index 0000000..a89b923 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/data/Group.java @@ -0,0 +1,28 @@ +package org.codedifferently.cbtyson.data; + +import java.util.ArrayList; + +public class Group { + String name; + String groupID; + ArrayList studentList; + + + public Group(String name, String groupID, ArrayList studentList) { + this.name = name; + this.groupID = groupID; + this.studentList = studentList; + } + + public String getName() { + return name; + } + + public ArrayList getStudentList() { + return studentList; + } + + public String getGroupID() { + return groupID; + } +} diff --git a/src/main/java/org/codedifferently/cbtyson/data/GroupList.java b/src/main/java/org/codedifferently/cbtyson/data/GroupList.java new file mode 100644 index 0000000..9562362 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/data/GroupList.java @@ -0,0 +1,103 @@ +package org.codedifferently.cbtyson.data; + +import java.util.ArrayList; +import java.util.List; + +public class GroupList { + + static ArrayList groups = new ArrayList<>(); + + public static List GetGroups() { + return groups; + } + + public static void AddGroup(Group group) { + groups.add(group); + } + + public static boolean AddStudentToGroup(String groupID,Student student) { + + boolean groupFound = false; + + for (Group group : groups) { + if(group.getGroupID().equals(groupID)) { + groupFound = true; + group.getStudentList().add(student); + } + } + + if(!groupFound) { + System.out.println("Group not found!"); + } + + return groupFound; + + } + + public static boolean RemoveStudentFromGroup(String groupID, String studentID) { + + boolean groupFound = false; + boolean studentFound = false; + + for (Group group : groups) { + if(group.getGroupID().equals(groupID)) { + groupFound = true; + for(Student student : group.getStudentList()) { + if(student.getStudentID().equals(studentID)) { + studentFound = true; + group.getStudentList().remove(student); + return true; + } + } + + } + } + + if(!studentFound && groupFound) { + System.out.println("Student ID not found!"); + } + + if(!groupFound) { + System.out.println("Group ID not found!"); + } + return false; + } + + public static Student GetStudentFromGroup(String groupID, String studentID) { + boolean groupFound = false; + boolean studentFound = false; + + for (Group group : groups) { + if(group.getGroupID().equals(groupID)) { + groupFound = true; + for(Student student : group.getStudentList()) { + if(student.getStudentID().equals(studentID)) { + studentFound = true; + return student; + } + } + + } + } + + if(!studentFound && groupFound) { + System.out.println("Student ID not found!"); + } + + if(!groupFound) { + System.out.println("Group ID not found!"); + } + return null; + } + + public static String GetGroupIDFromStudentID(String studentID) { + for(Group group : groups) { + for(Student student : group.getStudentList()) { + if(student.getStudentID().equals(studentID)) { + return group.getGroupID(); + } + } + } + return null; + } +} diff --git a/src/main/java/org/codedifferently/cbtyson/data/Student.java b/src/main/java/org/codedifferently/cbtyson/data/Student.java new file mode 100644 index 0000000..c2bb0e5 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/data/Student.java @@ -0,0 +1,45 @@ +package org.codedifferently.cbtyson.data; + +public class Student { + + public String firstName; + public String lastName; + public String email; + public String studentID; + public int age; + public double gpa; + + + public Student(String firstName, String lastName, String email, String studentID, int age, double gpa) { + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.studentID = studentID; + this.age = age; + this.gpa = gpa; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public int getAge() { + return age; + } + + public String getEmail() { + return email; + } + + public double getGpa() { + return gpa; + } + + public String getStudentID() { + return studentID; + } +} diff --git a/src/main/java/org/codedifferently/cbtyson/helpers/GroupRandomizer.java b/src/main/java/org/codedifferently/cbtyson/helpers/GroupRandomizer.java new file mode 100644 index 0000000..e5b72fc --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/helpers/GroupRandomizer.java @@ -0,0 +1,85 @@ +package org.codedifferently.cbtyson.helpers; + +import org.codedifferently.cbtyson.data.Group; +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + + +public class GroupRandomizer { + public static void randomizeStudentsIntoGroups(ArrayList allStudents, int groupSize) { + List groups = GroupList.GetGroups(); + + if (groups.isEmpty()) { + System.out.println("No groups exist. Please add groups first."); + return; + } + if (allStudents == null || allStudents.isEmpty()) { + System.out.println("No students to assign."); + return; + } + + // Clear existing students from all groups + for (Group group : groups) { + group.getStudentList().clear(); + } + + // Shuffle a copy of the student list + ArrayList shuffled = new ArrayList<>(allStudents); + Collections.shuffle(shuffled); + + // Determine how many groups we need based on desired group size + int numGroupsNeeded = (int) Math.ceil((double) shuffled.size() / groupSize); + + if (numGroupsNeeded > groups.size()) { + System.out.println("Warning: Not enough groups for group size of " + groupSize + + ". Need " + numGroupsNeeded + " but only have " + groups.size() + + ". Some groups will be larger than requested."); + } + + // Assign students round-robin across available groups + for (int i = 0; i < shuffled.size(); i++) { + int groupIndex = i % groups.size(); + groups.get(groupIndex).getStudentList().add(shuffled.get(i)); + } + + System.out.println("Students assigned! Group breakdown:"); + for (Group g : groups) { + System.out.println(" " + g.getName() + ": " + g.getStudentList().size() + " students"); + } + } + + public static void randomizeStudentsIntoGroupsInteractive(ArrayList allStudents) { + Scanner scanner = new Scanner(System.in); + System.out.print("Enter desired group size: "); + + while (!scanner.hasNextInt()) { + System.out.print("Invalid input. Enter a number: "); + scanner.next(); + } + + int groupSize = scanner.nextInt(); + + if (groupSize <= 0) { + System.out.println("Group size must be at least 1."); + return; + } + + randomizeStudentsIntoGroups(allStudents, groupSize); + } + + public static void randomizeGroups() { + ArrayList studentList = new ArrayList<>(); + + for (Group group : GroupList.GetGroups()) { + for(Student student : group.getStudentList()) { + studentList.add(student); + } + } + randomizeStudentsIntoGroupsInteractive(studentList); + } +} diff --git a/src/main/java/org/codedifferently/cbtyson/helpers/InputHandler.java b/src/main/java/org/codedifferently/cbtyson/helpers/InputHandler.java new file mode 100644 index 0000000..92529ae --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/helpers/InputHandler.java @@ -0,0 +1,97 @@ +package org.codedifferently.cbtyson.helpers; +import java.util.Scanner; + +public class InputHandler { + + public static int handleIntegerInput() { + Scanner scan = new Scanner(System.in); + int scanInput = 0; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextInt(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a number instead of a String!"); + scan.next(); + } + } + return scanInput; + } + + public static String handleStringInput() { + Scanner scan = new Scanner(System.in); + String scanInput = ""; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextLine(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a valid String!"); + scan.next(); + } + } + return scanInput; + } + + public static Double handleDoubleInput() { + Scanner scan = new Scanner(System.in); + double scanInput = 0; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextDouble(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a valid Double!"); + scan.next(); + } + } + return scanInput; + } + + public static String handleYesNoInput() { + Scanner scan = new Scanner(System.in); + String scanInput = ""; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + + scanInput = scan.nextLine(); + + if(scanInput.toLowerCase().equals("y") || scanInput.toLowerCase().equals("n")) { + validScanInput = true; + } + else { + System.out.println("Yes (y) or no (n) only!!"); + } + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a valid String!"); + scan.next(); + } + } + return scanInput; + } + +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/cbtyson/menus/AddGroupMenu.java b/src/main/java/org/codedifferently/cbtyson/menus/AddGroupMenu.java new file mode 100644 index 0000000..c4333e9 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/menus/AddGroupMenu.java @@ -0,0 +1,80 @@ +package org.codedifferently.cbtyson.menus; + +import org.codedifferently.cbtyson.data.Group; +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; +import org.codedifferently.cbtyson.helpers.InputHandler; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class AddGroupMenu { + + public void promptGroupMenu() { + + boolean inGroupMenu = true; + + while(inGroupMenu) { + System.out.println("Enter your Group Name:"); + String name = InputHandler.handleStringInput(); + + // System.out.println("How big is your group? "); + // int groupSize = InputHandler.handleIntegerInput(); + + // Generate a new UUID object + String groupID = UUID.randomUUID().toString(); + groupID = groupID.substring(0,6); + + Group group = new Group(name, groupID, new ArrayList()); + + System.out.println(); + + //Add new Group to List + GroupList.AddGroup(group); + + System.out.println("Continue adding groups? (y/n)"); + String answer = InputHandler.handleYesNoInput(); + if(answer.equals("n")) { + inGroupMenu = false; + } + } + } + + public void promptGroupMenu(Student student) { + boolean inGroupMenu = true; + boolean addedStudent = false; + + while(inGroupMenu) { + System.out.println("Enter your new Group Name:"); + String name = InputHandler.handleStringInput(); + + //System.out.println("How big is your group? "); + //int groupSize = InputHandler.handleIntegerInput(); + + // Generate a new UUID object + String groupID = UUID.randomUUID().toString(); + groupID = groupID.substring(0,6); + + //add student to studentList here, only diff in overloaded method + ArrayList studentList = new ArrayList<>(); + if(!addedStudent) studentList.add(student); + addedStudent = true; + + Group group = new Group(name, groupID, studentList); + + System.out.println(); + + //Add new Group to List + GroupList.AddGroup(group); + System.out.println("The " + group.getName() + " has been made! ID: " + group.getGroupID()); + + System.out.println("Continue adding groups? (y/n)"); + System.out.println("==================================="); + String answer = InputHandler.handleYesNoInput(); + if(answer.equals("n")) { + inGroupMenu = false; + } + } + } +} diff --git a/src/main/java/org/codedifferently/cbtyson/menus/AddStudentMenu.java b/src/main/java/org/codedifferently/cbtyson/menus/AddStudentMenu.java new file mode 100644 index 0000000..d0d4db4 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/menus/AddStudentMenu.java @@ -0,0 +1,67 @@ +package org.codedifferently.cbtyson.menus; + +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; +import org.codedifferently.cbtyson.helpers.InputHandler; + +import java.util.UUID; + +public class AddStudentMenu { + + public void promptAddStudentMenu() { + + System.out.println("============================================================="); + System.out.println(); + System.out.println("Add Student Menu:"); + System.out.println("Lets add some students!"); + System.out.println(); + System.out.println("============================================================="); + + boolean inStudentMenu = true; + + while (inStudentMenu) { + + System.out.println("Enter their First Name: "); + String firstName = InputHandler.handleStringInput(); + + System.out.println("Enter their Last Name: "); + String lastName = InputHandler.handleStringInput(); + + System.out.println("Enter their Email: "); + String email = InputHandler.handleStringInput(); + + System.out.println("Enter their Age: "); + int age = InputHandler.handleIntegerInput(); + + System.out.println("Enter their GPA: "); + double gpa = InputHandler.handleDoubleInput(); + + // Generate a new UUID object + String studentID = UUID.randomUUID().toString(); + studentID = studentID.substring(0,6); + + Student student = new Student(firstName, lastName, email, studentID, age, gpa); + + System.out.println(); + System.out.println("Which group is this new student going to?"); + System.out.println("Enter the Group ID here:"); + + //Actually add student to group + String groupID = InputHandler.handleStringInput(); + GroupList.AddStudentToGroup(groupID, student); + + System.out.println(); + System.out.println("Make another one? (y/n)"); + System.out.println("========================================="); + + String answerStr = InputHandler.handleYesNoInput(); + if(answerStr.equals("n")) { + inStudentMenu = false; + } + + } + + } + + +} diff --git a/src/main/java/org/codedifferently/cbtyson/menus/MainMenu.java b/src/main/java/org/codedifferently/cbtyson/menus/MainMenu.java new file mode 100644 index 0000000..12d7d5e --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/menus/MainMenu.java @@ -0,0 +1,94 @@ +package org.codedifferently.cbtyson.menus; + +import org.codedifferently.cbtyson.data.Group; +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; +import org.codedifferently.cbtyson.helpers.GroupRandomizer; +import org.codedifferently.cbtyson.helpers.InputHandler; + +import java.util.ArrayList; + +public class MainMenu { + + public void promptMainMenu() { + //Group-Differently + //Structured Group Maker + + //generate default students + generateDefaultStudents(); + + //Menus + AddGroupMenu addGroupMenu = new AddGroupMenu(); + AddStudentMenu addStudentMenu = new AddStudentMenu(); + + //main loop for program + boolean inMainMenu = true; + while(inMainMenu) { + System.out.println("============================================================="); + System.out.println(); + System.out.println("Welcome to Group Differently!"); + System.out.println("Please take a moment to assign a new group, or add new students!"); + System.out.println(); + System.out.println("============================================================="); + + System.out.println("1. Add new Student"); + System.out.println("2. Generate Group"); + System.out.println("3. View Students/Groups"); + System.out.println("4. Move Students across Groups."); + System.out.println("5. Remove Students from Group"); + System.out.println("6. Randomize Groups"); + System.out.println("7. Exit"); + + int inputCode = InputHandler.handleIntegerInput(); + + switch(inputCode) { + case 1: + addStudentMenu.promptAddStudentMenu(); + break; + case 2: + addGroupMenu.promptGroupMenu(); + break; + case 3: + ViewMenu viewMenu = new ViewMenu(); + viewMenu.viewGroups(); + break; + case 4: + MoveStudentMenu moveMenu = new MoveStudentMenu(); + moveMenu.moveGroups(); + break; + case 5: + RemoveMenu removeMenu = new RemoveMenu(); + removeMenu.removeStudentFromGroup(); + break; + case 6: + GroupRandomizer.randomizeGroups(); + break; + case 7: + System.out.println("Have a Nice Day!"); + inMainMenu = false; + break; + } + } + } + + //generates students, and adds them to a group. then adds them into the static groupList field. + void generateDefaultStudents() { + //Make new students + Student glenn = new Student("Glenn", "Tyson", "mrtyson@gmail.com", "31d13de", 29, 3.6); + Student chris = new Student("Chris", "Bennett", "cbswag@gmail.com", "1920vfa", 30, 2.0); + Student alex = new Student("Alex", "Trunzo", "vanyllagodzylla@gmail.com", "120-1fd", 22, 4.0); + Student bobby = new Student("Bobby", "Money", "bigmoney@gmail.com", "19911-f", 25, 3.56); + + //List of students added to arrayList + ArrayList students1 = new ArrayList<>(); + students1.add(glenn); + students1.add(chris); + students1.add(alex); + students1.add(bobby); + + Group group = new Group("Vanylla Godzylla Band", "90121j", students1); + + //Add group + GroupList.AddGroup(group); + } +} diff --git a/src/main/java/org/codedifferently/cbtyson/menus/MoveStudentMenu.java b/src/main/java/org/codedifferently/cbtyson/menus/MoveStudentMenu.java new file mode 100644 index 0000000..2f556ae --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/menus/MoveStudentMenu.java @@ -0,0 +1,42 @@ +package org.codedifferently.cbtyson.menus; + +import org.codedifferently.cbtyson.data.Group; +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; +import org.codedifferently.cbtyson.helpers.InputHandler; + +public class MoveStudentMenu { + + public void moveGroups() { + + System.out.println("Enter Student ID to move:"); + System.out.println("============================="); + + String studentID = InputHandler.handleStringInput(); + + System.out.println("Enter Group ID to move into:"); + String groupID = InputHandler.handleStringInput(); + + + //Get old GroupID that student used to be in + String oldGroupID = GroupList.GetGroupIDFromStudentID(studentID); + + //Get reference to student to be moved. + Student movedStudent = GroupList.GetStudentFromGroup(oldGroupID, studentID); + + //Remove them from old group + boolean removeResult = GroupList.RemoveStudentFromGroup(oldGroupID, studentID); + + if(removeResult) { + //Then add them to new group if remove was successful + boolean result = GroupList.AddStudentToGroup(groupID, movedStudent); + + if(result) System.out.println("Moved Students successfully!"); + } + else { + System.out.println("Removing student from previous group has failed!!"); + } + + } + +} diff --git a/src/main/java/org/codedifferently/cbtyson/menus/RemoveMenu.java b/src/main/java/org/codedifferently/cbtyson/menus/RemoveMenu.java new file mode 100644 index 0000000..24d91a5 --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/menus/RemoveMenu.java @@ -0,0 +1,44 @@ +package org.codedifferently.cbtyson.menus; + +import org.codedifferently.cbtyson.data.Group; +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; +import org.codedifferently.cbtyson.helpers.InputHandler; + +public class RemoveMenu { + + public void removeStudentFromGroup() { + + System.out.println("Enter Group ID:"); + String groupID = InputHandler.handleStringInput(); + + System.out.println("Enter Student ID:"); + String studentID = InputHandler.handleStringInput(); + + for (Group group : GroupList.GetGroups()) { + + if (group.getGroupID().equals(groupID)) { + + Student studentToRemove = null; + + for (Student student : group.getStudentList()) { + if (student.getStudentID().equals(studentID)) { + studentToRemove = student; + break; + } + } + + if (studentToRemove != null) { + group.getStudentList().remove(studentToRemove); + System.out.println("Student removed successfully!"); + } else { + System.out.println("Student not found in this group."); + } + + return; + } + } + + System.out.println("Group not found."); + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/cbtyson/menus/ViewMenu.java b/src/main/java/org/codedifferently/cbtyson/menus/ViewMenu.java new file mode 100644 index 0000000..e5f604f --- /dev/null +++ b/src/main/java/org/codedifferently/cbtyson/menus/ViewMenu.java @@ -0,0 +1,35 @@ +package org.codedifferently.cbtyson.menus; + +import org.codedifferently.cbtyson.data.Group; +import org.codedifferently.cbtyson.data.GroupList; +import org.codedifferently.cbtyson.data.Student; +import org.codedifferently.cbtyson.helpers.InputHandler; + +public class ViewMenu { + + public void viewGroups() { + + if (GroupList.GetGroups().isEmpty()) { + System.out.println("No groups available."); + return; + } + + for (Group group : GroupList.GetGroups()) { + + System.out.println("=================================="); + System.out.println("Group Name: " + group.getName()); + System.out.println("Group ID: " + group.getGroupID()); + System.out.println("Students:"); + + for (Student student : group.getStudentList()) { + System.out.println(student.getFirstName() + " " + student.getLastName() + " | ID: " + student.getStudentID() + " | GPA: " + student.getGpa()); + } + + System.out.println("=================================="); + System.out.println(); + } + System.out.println("Press anything to continue"); + System.out.println("=============================="); + InputHandler.handleStringInput(); + } +} \ No newline at end of file