Hey, im having some issues with my if statements. Im using linked lists to keep details on students and ive made a interface class to make the program more user friendly. When the user types 1, it will bring up the add student interface, 2 is delete student interface and 3 should be print the list, but for some reason, when you press 3, nothing happens. I dont believe that i have errors in my code because if you type a println statement in the box and then press 3, Nothing happens. Here is my code -
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lab8;
/**
*
* @author Aled
*/
import java.util.Scanner;
public class RegistryInterface
{
Scanner sc = new Scanner(System.in);
Registry reg = new Registry();
public RegistryInterface(Registry theRegistry)
{
}
public void doMenu()
{
Boolean quit = false;
while (!quit)
{
System.out.println("Registry Main Menu");
System.out.println("******************\n");
System.out.println("1. Add a Student");
System.out.println("2. Delete a Student");
System.out.println("3. Print Registry");
System.out.println("4. Quit");
System.out.print("Select option [1, 2, 3, 4] :> ");
int userInput = sc.nextInt();
if (userInput == 1)
{
doAddStudent();
}
if (userInput == 2)
{
deleteStudent();
}
if (userInput == 3)
{
printRegistry();
}
if (userInput == 4)
{
quit = true;
}
}
}
public void doAddStudent()
{
boolean addAnother = true;
while (addAnother == true)
{
System.out.println("Add student Interface");
System.out.print("Enter forename\t :>");
String forename = sc.next();
System.out.print("Enter surname\t :>");
String surname = sc.next();
System.out.print("Enter student Id\t :>");
int studentId = sc.nextInt();
Student student = new Student(forename, surname,studentId);
System.out.println(student);
reg.addStudent(student);
System.out.print("Add another (Y/N)\t :>");
String add = sc.next();
if ("n".equals(add))
{
addAnother = false;
}
}
}
public void printRegistry()
{
System.out.println("Printing...");
reg.printList();
}
public void deleteStudent()
{
System.out.println("Enter a Student Id\t :>");
int studentId = sc.nextInt();
reg.deleteStudent(studentId);
}
}
Thanks. Any help out there?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lab8;
/**
*
* @author Aled
*/
import java.util.Scanner;
public class RegistryInterface
{
Scanner sc = new Scanner(System.in);
Registry reg = new Registry();
public RegistryInterface(Registry theRegistry)
{
}
public void doMenu()
{
Boolean quit = false;
while (!quit)
{
System.out.println("Registry Main Menu");
System.out.println("******************\n");
System.out.println("1. Add a Student");
System.out.println("2. Delete a Student");
System.out.println("3. Print Registry");
System.out.println("4. Quit");
System.out.print("Select option [1, 2, 3, 4] :> ");
int userInput = sc.nextInt();
if (userInput == 1)
{
doAddStudent();
}
if (userInput == 2)
{
deleteStudent();
}
if (userInput == 3)
{
printRegistry();
}
if (userInput == 4)
{
quit = true;
}
}
}
public void doAddStudent()
{
boolean addAnother = true;
while (addAnother == true)
{
System.out.println("Add student Interface");
System.out.print("Enter forename\t :>");
String forename = sc.next();
System.out.print("Enter surname\t :>");
String surname = sc.next();
System.out.print("Enter student Id\t :>");
int studentId = sc.nextInt();
Student student = new Student(forename, surname,studentId);
System.out.println(student);
reg.addStudent(student);
System.out.print("Add another (Y/N)\t :>");
String add = sc.next();
if ("n".equals(add))
{
addAnother = false;
}
}
}
public void printRegistry()
{
System.out.println("Printing...");
reg.printList();
}
public void deleteStudent()
{
System.out.println("Enter a Student Id\t :>");
int studentId = sc.nextInt();
reg.deleteStudent(studentId);
}
}
Thanks. Any help out there?