CISS-238/dropbox12/dropbox12/StudentTest.java
2025-10-01 04:33:24 -07:00

87 lines
2.7 KiB
Java

/**
* Assignment 12
* Course: CISS238
* Student: Scott Steely
* Date: Sep 22, 2025
*/
package dropbox12;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// variables
String name;
String course;
// two courses in an ArrayList
ArrayList<String> myCourses = new ArrayList<>();
myCourses.add("CS 101");
myCourses.add("CS 102");
// prompt user for input
System.out.println("Enter student name: ");
name = input.nextLine();
// create a student with the two courses
Student student = new Student(name, myCourses);
int menuSelected;
// display a user menu
System.out.println("Enter a number for the task:");
System.out.println("1. Add a course.");
System.out.println("2. Drop a course.");
System.out.println("3. Find the position of a course.");
System.out.println("4. Display all courses.");
System.out.println("5. Sort courses.");
System.out.println("6. Exit.");
menuSelected = input.nextInt();
input.nextLine();
while(menuSelected > 0 && menuSelected <6) {
switch(menuSelected) {
case 1:
System.out.println("Enter a course: ");
course = input.nextLine();
student.addCourse(course);
System.out.println("Course added.");
break;
case 2:
System.out.println("Enter a course to delete:");
course = input.nextLine();
student.removeCourse(course);
System.out.println("Course dropped.");
break;
case 3:
System.out.println("Enter a course to see its position: ");
course = input.nextLine();
// check if the course is in the completed list
if(student.isCourseCompleted(course)) {
System.out.printf("%s is in position %d%n",
course, student.findCoursePosition(course));
} else {
System.out.printf("%s is not completed yet.", course);
}
break;
case 4:
System.out.println(student);
break;
case 5:
student.sortCourses();
System.out.println(student);
}
// display a user menu
System.out.println("Enter a number for the task:");
System.out.println("1. Add a course.");
System.out.println("2. Drop a course.");
System.out.println("3. Find the position of a course.");
System.out.println("4. Display all courses.");
System.out.println("5. Sort courses.");
System.out.println("6. Exit.");
menuSelected = input.nextInt();
input.nextLine();
}
input.close();
}
}