I am try to make the user enter name and password then ask them if they want to search. The menu has the options and i am having trouble with the search method. Here's my server:
[CODE=java]import java.util.Scann er;
public class StudentPassword {
static Scanner reader = new Scanner (System.in);
private int option;//the user option
private int count = 0;//the count
private String names[] = new String [50];
private int passwords[] = new int [50];
public StudentPassword (){
while(true){
setOption();
selection();
}//close whlie
}//close main
public int menu()
{
while(true){
String menu = "----------\n1)Enter name and password\n2)Sea rch"
+ "\n3)Print\n4)Q uit\nMake a selection: ";
try{
System.out.prin t(menu);
option = reader.nextInt( );
if(option >= 1 && option <= 4){
reader.nextLine ();//CONSUME EXTRA CHARACTER
break;
}else{
System.out.prin t("\nEnter a number answer");
reader.nextLine ();
}//close if
}catch(Exceptio n e){
System.out.prin t("\nEnter a valid answer");
reader.nextLine ();
}//exception
}//close whlie
return option;
}//close menu
public void setOption()
{
option = menu();
}//close setOption
public int getOption(){
return option;
}//close getOption
public void selection()
{
if(getOption() == 4){
quit();
}else if (getOption() == 3){
print();
}else if (option == 2){
search();
}else{
getNames();
}//close if
}//close selection
public void setName(String [] names2)
{
names = names2;
}//close setRun
public String [] getNames()
{
String nm;//the user local name
for(int i = count; count < names.length; i++){
System.out.prin t("Enter Your name or enter 'bye' to quit: ");
nm = reader.nextLine ();
if (nm.equalsIgnor eCase("bye")){
break;
}else{
names[count] = nm;
getPass();
}//close if
}//close for
return names;
}//close getRun
public void setPass(int [] pass2)
{
passwords = pass2;
}//close setRun
public int [] getPass()
{
int pass;//the user local password
for(int i = count; count < passwords.lengt h; i++){
while(true){
try{
System.out.prin t("Enter Your password: ");
pass = reader.nextInt( );
passwords[count] = pass;
count++;
reader.nextLine ();
break;
}catch(Exceptio n e){
System.out.prin t("\nEnter a number answer: ");
reader.nextLine ();
}//close exception
}//close while
break;
}//close for
return passwords;
}//close run
public void quit()
{
System.exit(99) ;
}//close quit
public void search()
{
int coresspondingPa ssword;
for(int i = count; count < names.length; i++){
String searchName;
System.out.prin t("Enter Name: " );
searchName = reader.nextLine ();
if(searchName.e quals(names[count])){
coresspondingPa ssword = passwords[count];
System.out.prin t("The password is " + coresspondingPa ssword);
break;
}else{
System.out.prin t(searchName + " not found");
}//close if
count++;
}//close for
}//close search
public void print()
{
for(int i = count; count < names.length; i++){
System.out.prin t(names[i]);
}//close for
}//close getPrint
}//StudentPassword[/CODE]
[CODE=java]import java.util.Scann er;
public class StudentPassword {
static Scanner reader = new Scanner (System.in);
private int option;//the user option
private int count = 0;//the count
private String names[] = new String [50];
private int passwords[] = new int [50];
public StudentPassword (){
while(true){
setOption();
selection();
}//close whlie
}//close main
public int menu()
{
while(true){
String menu = "----------\n1)Enter name and password\n2)Sea rch"
+ "\n3)Print\n4)Q uit\nMake a selection: ";
try{
System.out.prin t(menu);
option = reader.nextInt( );
if(option >= 1 && option <= 4){
reader.nextLine ();//CONSUME EXTRA CHARACTER
break;
}else{
System.out.prin t("\nEnter a number answer");
reader.nextLine ();
}//close if
}catch(Exceptio n e){
System.out.prin t("\nEnter a valid answer");
reader.nextLine ();
}//exception
}//close whlie
return option;
}//close menu
public void setOption()
{
option = menu();
}//close setOption
public int getOption(){
return option;
}//close getOption
public void selection()
{
if(getOption() == 4){
quit();
}else if (getOption() == 3){
print();
}else if (option == 2){
search();
}else{
getNames();
}//close if
}//close selection
public void setName(String [] names2)
{
names = names2;
}//close setRun
public String [] getNames()
{
String nm;//the user local name
for(int i = count; count < names.length; i++){
System.out.prin t("Enter Your name or enter 'bye' to quit: ");
nm = reader.nextLine ();
if (nm.equalsIgnor eCase("bye")){
break;
}else{
names[count] = nm;
getPass();
}//close if
}//close for
return names;
}//close getRun
public void setPass(int [] pass2)
{
passwords = pass2;
}//close setRun
public int [] getPass()
{
int pass;//the user local password
for(int i = count; count < passwords.lengt h; i++){
while(true){
try{
System.out.prin t("Enter Your password: ");
pass = reader.nextInt( );
passwords[count] = pass;
count++;
reader.nextLine ();
break;
}catch(Exceptio n e){
System.out.prin t("\nEnter a number answer: ");
reader.nextLine ();
}//close exception
}//close while
break;
}//close for
return passwords;
}//close run
public void quit()
{
System.exit(99) ;
}//close quit
public void search()
{
int coresspondingPa ssword;
for(int i = count; count < names.length; i++){
String searchName;
System.out.prin t("Enter Name: " );
searchName = reader.nextLine ();
if(searchName.e quals(names[count])){
coresspondingPa ssword = passwords[count];
System.out.prin t("The password is " + coresspondingPa ssword);
break;
}else{
System.out.prin t(searchName + " not found");
}//close if
count++;
}//close for
}//close search
public void print()
{
for(int i = count; count < names.length; i++){
System.out.prin t(names[i]);
}//close for
}//close getPrint
}//StudentPassword[/CODE]
Comment