Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- menu();
- }
- public static void menu(){
- Scanner input = new Scanner(System.in);
- while(true){
- System.out.println("Select an option: ");
- System.out.println("1. Add");
- System.out.println("2. View");
- System.out.println("3. Update");
- System.out.println("4. Remove");
- System.out.println("5. Exit\n");
- System.out.print("Choice: ");
- Student student;
- switch(input.nextInt()){
- case 1:
- System.out.println("\nAdding a student: ");
- System.out.print("Name: ");
- String addName = input.next();
- System.out.print("Level: ");
- int addLevel = input.nextInt();
- System.out.print("Grade: ");
- int addGrade = input.nextInt();
- System.out.print("Course Name: ");
- String addCourseName = input.next();
- System.out.print("Course Hours: ");
- int addCourseHours = input.nextInt();
- System.out.print("Course Grade: ");
- String addCourseGrade = input.next();
- student = new Student(addName, addLevel, addGrade, addCourseName, addCourseHours, addCourseGrade);
- student.addStudent(student);
- System.out.println("Student added successfully!");
- break;
- case 2:
- student = new Student();
- if(student.studentsNumber() > 0){
- System.out.print("\n1. Search for student\n2. Search for students in course\nChoice: ");
- int choice = input.nextInt();
- if(choice == 1){
- System.out.print("Student name: ");
- String searchName = input.next();
- System.out.println("Viewing student: ");
- student.view(searchName);
- }
- else if(choice == 2){
- System.out.print("Course name: ");
- String searchCourse = input.next();
- student.studentsInCourse(searchCourse);
- }
- else{
- System.out.println("Invalid choice.");
- }
- }
- else{
- System.out.println("Error, there are no students.");
- }
- break;
- case 3:
- student = new Student();
- if(student.studentsNumber() > 0){
- System.out.println("\nUpdating a student: ");
- System.out.print("Index: ");
- int updateIndex = input.nextInt();
- if(updateIndex < student.studentsNumber()) {
- System.out.print("Name: ");
- String updateName = input.next();
- System.out.print("Level: ");
- int updateLevel = input.nextInt();
- System.out.print("Grade: ");
- int updateGrade = input.nextInt();
- System.out.print("Course Name: ");
- String updateCourseName = input.next();
- System.out.print("Course Hours: ");
- int updateHours = input.nextInt();
- System.out.print("Course Grade: ");
- String updateCourseGrade = input.next();
- student.update(updateIndex, updateName, updateLevel, updateGrade,
- updateCourseName, updateHours, updateCourseGrade);
- }
- else{
- System.out.println("Error, index is out of bounds.");
- }
- }
- else{
- System.out.println("Error, there are no students.");
- }
- break;
- case 4:
- student = new Student();
- if(student.studentsNumber() > 0){
- System.out.println("\nRemoving a student (starting from 1): ");
- System.out.print("Index: ");
- int removeIndex = input.nextInt();
- if((removeIndex-1) < student.studentsNumber()){
- student.remove(removeIndex-1);
- }
- else{
- System.out.println("Error, index is out of bounds.");
- }
- }
- else{
- System.out.println("Error, there are no students.");
- }
- break;
- case 5:
- System.out.print("The program will exit.");
- System.exit(0);
- break;
- default:
- System.out.println("Error, enter a valid option.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement