package student;
import java.util.ArrayList;
import java.util.Scanner;
/**
* This class prints a list of menu, and according to users selection from char 1-6, each method will be called and executed.
* @author Boo
*
*/
public class StudentList {
private static final int numb = 0;
//creates an Arraylist that contains the elements of Student (in Student.class)
//actually a collection that can hold any amount, changes itself, while with array you have to specify an amount that it can hold.
ArrayList<Student> list = new ArrayList<Student>();
Scanner keybd = new Scanner(System.in);
public void menu()
{
//creates a scanner keyboard that captures keyboard inputs
char selection;
//display menu
do{
System.out.println("\n------------");
System.out.println(" Main Menu\n");
System.out.println("1. Add a Student");
System.out.println("2. Find a Student");
System.out.println("3. Delete a Student");
System.out.println("4. Display all Students");
System.out.println("5. Total number of Students");
System.out.println("6. Exit");
//get menu selection
selection = keybd.next().charAt(0);
//process menu selection, and when a char is entered, method will be called, executed, and exit to the menu selection when completed
//(also so that it doesn't execute the other methods, without be selected by the user)
switch (selection)
{
case '1':
AddS();
break;
case '2':
FindS();
break;
case '3':
DeleteS();
break;
case '4':
DisplayS();
break;
case '5':
TotalS();
break;
case '6':
//recognize as valid selection but do nothing
break;
default:
System.out.printf("%c\n",7);
System.out.println("Invalid Selection");
}//end switch
}while( selection != '6');
}//end main()
/**
* uses println() to ask questions, then use scanner to read the answers
* once there is all the answers to build a Student object, use the Student's class constructor to build an object and save that object in the arraylist
* @param firstName, lastName, SNumber, major, gpa
*
*/
// Java does not allow us to pass methods into methods, but allow us to pass an object into a method and then invoke the object's methods
public void AddS()//Object Student, String firstName, String lastName, int SNumber, String major, double gpa
{
Scanner keybd = new Scanner (System.in);
//new operator invokes the object constructor
//then call setFirstName method which takes input as the variable
System.out.println("enter firstname");
String firstName = keybd.nextLine();
//pass firstname into this method, this object now have action and behavior
System.out.println("enter lastname");
String lastName = keybd.nextLine();
// System.out.println(lastname);
System.out.println("enter studentnumber");
int SNumber = keybd.nextInt();
//call setSNumber method and pass value of sNumber into it
System.out.println("enter major");
String major = keybd.next();
// System.out.println(major);
System.out.println("enter gpa");
double gpa= keybd.nextDouble();//read input as a double
//create a new student object
Student student = new Student(firstName, lastName, SNumber, major, gpa );
list.add(student);
System.out.print(student);//why is it oly printing first name
}
//static means there is only 1 copy of it, such as whenever you use that class and its static members, you are using the same 1 copy of its properties.
/**
* find a Student from the ArrayList by typing out their firstname, so if it matches anyone from the ArrayList, print that student.
*/
public void FindS()
{
//keyboard can be accessed anywhere since it has been declared public.
System.out.print("please enter Student Number");
int ssn = keybd.nextInt();
// Find Student using SSN not firstname
for (Student people: list){
if (ssn==people.getSNumber()){
System.out.print(people);
}
}
}
/**
* Delete a student from the ArrayList by name, so if the user input equals the ArrayList student first name, then remove the student.
*/
public void DeleteS()
{
// LOOK AT THE JAVA API TO LOOK AT BUNCH OF REMOVE METHODS for ArrayList
System.out.print("please enter Student Number");
int ssn = keybd.nextInt();
for(Student people : list)
{
if(ssn == people.getSNumber())
{
}
}
}
/**
* Display all the students in the ArrayList
*/
public void DisplayS()
{
//using enhanced for loop to go through the list of an ArrayList, then print each student .
for (Student people: list){
System.out.println(people);
}
}
/**
* display total number of students
* print the number of student in the ArrayList, basically ArrayList.length (something like that)
* probably requres some iteration to complete this method, a loop that go through the list and increment by 1 untill it reaches the ArrayList.length
* @param student1
*/
public void TotalS()
{
System.out.print(Student.count);
}
// public StudentList (String fn, String ln, int sn, String mj, double gpa)
// {
// Student student1 = new Student ("fn", "ln", 5555, "mj", 3.5);
// System.out.print(student1);
// }
}