This is for a project for student enrolments. When running the program, I want there to be a menu for the user to input a number from 1-3 which each correspond to a different option. This is the following code I wrote for that menu:
import java.util.*;
import java.io.*;
public class InputMenu
{
public void display_menu()
{
System.out.println("1) Enroll a student\n2) View enrollments\n3) To exit program");
System.out.print("Selection: ");
}
public void question()
{
Scanner q = new Scanner(System.in);
switch (q.nextInt())
{
case 0:
System.out.println ("Thank you and goodbye.");
break;
case 9:
System.out.println ("Please proceed.");
new InputMenu();
break;
default:
System.err.println ( "Unrecognized option" );
break;
}
}
public InputMenu()
{
Scanner in = new Scanner(System.in);
display_menu();
switch (in.nextInt())
{
case 1:
System.out.println ( "You picked enroll a new student" );
question();
break;
case 2:
System.out.println ( "You picked view past enrollments" );
question();
Scanner = new Scanner(new File("students.txt"));
break;
case 3:
System.out.println ( "You picked exit program" );
question();
break;
default:
System.err.println ( "Unrecognized option" );
break;
}
}
public static void main (String[]args)
{
new InputMenu();
}
}
and then there is a file 2 called "University.java". It is a large file sorry about that so I cannot post the whole code. This file 2 was given as part of the project instructions. File 2 is the rest of the program runs (collects user inputed student name, address, unit enrolment etc.).
Anyway I want to run this code ^ provided, and when the user inputs the number '1', I want to then run file 2 called "University.java". Is there a way I can do this, or should I try to work out a way to add this code ^ directly within file 2 (not sure how to do that or were to start due to file 2 having different methods and classes). Thanks, and sorry I am a beginner.