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");
- Student student;
- switch(input.nextInt()){
- case 1:
- System.out.println("Adding 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();
- student = new Student(addName, addLevel, addGrade);
- student.addStudent(student);
- System.out.println("Student added successfully!");
- break;
- case 2:
- student = new Student();
- if(student.students.size() > 0){
- System.out.print("Student name: ");
- String searchName = input.next();
- System.out.println("Viewing student: ");
- student.view(searchName);
- }
- else{
- System.out.println("Error, there are no students.");
- }
- break;
- case 3:
- student = new Student();
- if(student.students.size() > 0){
- System.out.println("Updating a student: ");
- System.out.print("Index: ");
- int updateIndex = input.nextInt();
- if(updateIndex < student.students.size()) {
- System.out.print("Name: ");
- String updateName = input.next();
- System.out.print("Level: ");
- int updateLevel = input.nextInt();
- System.out.print("Grade: ");
- int updateGrade = input.nextInt();
- student.update(updateIndex, updateName, updateLevel, updateGrade);
- }
- 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.students.size() > 0){
- System.out.println("Removing a student: ");
- System.out.print("Index: ");
- int removeIndex = input.nextInt();
- if(removeIndex < student.students.size()){
- student.remove(removeIndex);
- }
- 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