I want the program to compare what the user puts in and then compare that string to something in an array and see if it is a match.

Here is code for things already put into array

private static void createExistingUserData(Scientist[] scientist){
		scientist[0] = new Scientist("user1", "password1");
		scientist[0].setDob("02/02/1995");
		scientist[0].setSsn("612-45-7070");
		scientist[0].setApplicantName("Peter Lee");
		scientist[0].setInstituteName("George Washington University");
		scientist[0].setDepartmentName("Information System Department");
		scientist[0].setPositionRank(1);
		scientist[0].setResearchTopic("Software Engineering");
		scientist[0].setPastFunding(250000);
		scientist[0].setNumOfPaper(30);
	}

Here is code that i have right now for checking.

do{
			ssn = JOptionPane.showInputDialog(null,"Please enter your social security number (xxx-xx-xxxx): ", "Lab 4",
					JOptionPane.QUESTION_MESSAGE);
		}while(!scientist[index].setSsn(ssn));
		
		
		
		for (int i = 0; i < scientist.length; i++)
			if (ssn.equals(scientist[i])){
				System.out.print("This is in use");
			}

Recommended Answers

All 9 Replies

You don't ask a question or say what your problem is.
Does your code work? If not explain what the problem is and give some examples where the code does not work. Add some println statements to print out the values of the variables that are being used.

Yes my code works expect for the comparison part it skips it and it works if i put in the exact number that im looking for it to duplicate it works but I am trying to get it to search the array to find the duplicate

I am trying to get it to search the array to find the duplicateed.

Where is the code that is doing the search thru the array?

Did you try this:
Add some println statements to print out the values of the variables that are being used.

this is the code searching through the array for the specific string

for (int i = 0; i < scientist.length; i++)
			if (ssn.equals(scientist[i])){
				System.out.print("This is in use");
			}

and yes i have tried using println statements they show the string i am looking for and i tried passing that into a variable but the code still doesn't recognize them as equals.

Post the print outs of the Strings that are being compared.
Be sure to put delimiters before and after the Strings to show all characters. For example:
println("ssn=" + ssn +"<");

String usedSsn = scientist[0].getSsn();
		System.out.print(usedSsn);
			
			if (ssn.compareTo(usedSsn)){
				System.out.print("This is in use");
			}

Prints out : 615-45-7070
Which is the ssn i want to compare the users to but I do not know how to search an array for that specific value and then compare it.

Please put delimiters on the Strings.
You only show one String, where is the one that it is being compared to?

Where is the loop? The code you posted only looks at the first element in the array.

Your previous post showed a loop going thru the elements in the scientist array.

Here is the Scientist class

import java.text.NumberFormat;
import javax.swing.JOptionPane;
public class Scientist {
	private String ssn;
	private String dob;
	private String username;
	private String password;
	private String applicantName;
	private String instituteName;
	private String departmentName;
	private int positionRank;
	private String researchTopic;
	private double pastFunding;
	private int numOfPaper;
	private final int scientistId;
	private static int numOfScientistsCreated;
	public static final double MAX_SCORE = 100;
	public static final double MAX_FUNDING = 500000;
	
	public Scientist(){
		ssn = "";
		dob = "";
		applicantName = "";
		instituteName = "";
		departmentName = "";
		positionRank = 0;
		researchTopic = "";
		pastFunding = 0;
		numOfPaper = 0;
		numOfScientistsCreated++;
		scientistId = numOfScientistsCreated;	
	}
	
	public Scientist(String iUsername, String iPassword){
		this();
		username = iUsername;
		password = iPassword;
	}
	
	public boolean setUsername(String iUsername){
		if (iUsername == null || iUsername.equals(""))
			return false;
		else{
			username = iUsername;
			return true;
		}
	}
	
	public String getUsername(){
		return username;
	}
	
	public boolean setPassword(String iPassword){
		if (iPassword == null || iPassword.equals(""))
			return false;
		else{
			password = iPassword;
			return true;
		}
	}
	
	public String getPassword(){
		return password;
	}
	
	public boolean setApplicantName(String iName){
		if (iName == null || iName.equals("")){
			JOptionPane.showMessageDialog(null, "Sorry! " +	"No name is entered. Please enter it again.", "Lab 4",
					JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		
		if(iName.indexOf(" ") == -1){
			JOptionPane.showMessageDialog(null, "Sorry! Your name is not valid. Please enter it again.",  "Lab 4",
					JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		applicantName = iName;
		
		return true;
	}
	
	public String getApplicantName(){
		return applicantName;
	}
	
	public boolean setInstituteName(String iInstituteName){
		if (iInstituteName == null || iInstituteName.equals(""))
			return false;
		else{
			instituteName = iInstituteName;
			return true;
		}
	}
	
	public String getInstituteName(){
		return instituteName;
	}
	
	public boolean setDepartmentName(String iDepartmentName){
		if (iDepartmentName ==  null || iDepartmentName.equals(""))
			return false;
		else{
			departmentName = iDepartmentName;
			return true;
		}
	}
	
	public String getDepartmentName(){
		return departmentName;
	}
	
	public boolean setResearchTopic(String iTopic){
		if (iTopic == null || iTopic.equals(""))
			return false;
		else{
			researchTopic = iTopic;
			return true;
		}
	}
	
	public String getResearchTopic(){
		return researchTopic;
	}
	
	public boolean setPositionRank(int iRank){
		if (iRank < 1 || iRank > 4)
			return false;
		else {
			positionRank = iRank;
			return true;			
		}
	}
	
	public int getPositionRank(){
		return positionRank;
	}
	
	public boolean setNumOfPaper(int iNumOfPaper){
		if (iNumOfPaper < 0)
			return false;
		else {
			numOfPaper = iNumOfPaper;
			return true;
		}
	}
	
	public int getNumOfPaper(){
		return numOfPaper;
	}
	
	public boolean setPastFunding(double iPastFunding){
		if (iPastFunding < 0)
			return false;
		else {
			pastFunding = iPastFunding;
			return true;
		}
	}
	
	public double getPastFunding(){
		return pastFunding;
	}
		
	public static int getNumOfScientistsCreated(){
		return numOfScientistsCreated;
	}
	
	public int getScientistId(){
		return scientistId;
	}
	
	public String toString(){
		String position = "", str = "";
		NumberFormat currency = NumberFormat.getCurrencyInstance();
		currency.setMinimumFractionDigits(2);
		currency.setMaximumFractionDigits(2);
		
		if (getPositionRank() == 1)
			position = "Full Professor";
		else if (getPositionRank() == 2)
			position = "Associate Professor";
		else if (getPositionRank() == 3)
			position = "Assistant Professor";
		else if (getPositionRank() == 4)
			position = "Others";
			
		str =	"Applicant Name: " + getApplicantName() + 
				"\nPersonal ID: " + getScientistId() +
				"\nDate of Birth: " + getDob() +
				"\nSocial Security NUmber: " + getSsn() +
				"\nInstitute Name: " + getInstituteName() + 
				"\nDepartment Name: " + getDepartmentName() +
				"\nPosition Title : " + position +
				"\nResearch Topic: " + getResearchTopic() +
				"\nNumber of Papers Published: " + getNumOfPaper() +
				"\nPast Funding Awarded: " + currency.format(getPastFunding());
		
		return str;
	}
		
	private double calculateAwardFunding(){
		double score = 0;
		
		if (getPositionRank() == 1)
			score = 30;
		else if (getPositionRank() == 2)
			score = 20;
		else if (getPositionRank() == 3)
			score = 10;
		else if(getPositionRank() == 4)
			score = 5;
		
		if (getNumOfPaper() >= 30)
			score += 30;
		else if (getNumOfPaper() >= 20)
			score += 20;
		else if (getNumOfPaper() >= 10)
			score += 10;
		else if (getNumOfPaper() >= 1)
			score += 5;
		
		if (getPastFunding() >= 400000)
			score += 40;
		else if (getPastFunding() >= 300000)
			score += 30;
		else if (getPastFunding() >= 200000)
			score += 20;
		else if (getPastFunding() >= 1)
			score += 10;
		
		return (score / MAX_SCORE) * MAX_FUNDING;
	}
	
	public double getNewAwardFunding(){
		return calculateAwardFunding();
	}

	public boolean setDob(String dob2) {
		if(dob2.length() != 10){
			JOptionPane.showMessageDialog(null, "Sorry! The entered birth date is not valid G(mm/dd/yyyy). " +
					"Please enter again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		
		if(dob2.indexOf("/") != 2 || dob2.lastIndexOf("/") != 5){
		
			JOptionPane.showMessageDialog(null, "Sorry! The entered birth date is not valid (mm/dd/yyyy). " +
					"Please enter again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		for (int i = 0; i < 2; i++){
			if(!Character.isDigit(dob2.charAt(i))){
				JOptionPane.showMessageDialog(null, "Sorry! The month is not two digits. " +
						"Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
		}
		String month = dob2.substring(0,2);
		int m = Integer.parseInt(month);
		if (m > 12 || m <= 0){
			JOptionPane.showMessageDialog(null, "Sorry! The month must be between 01 and 12. " +
					"Please enter again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		for (int i = 3; i < 5; i++){
			if(!Character.isDigit(dob2.charAt(i))){
				JOptionPane.showMessageDialog(null, "Sorry! The day is not two digits. " +
						"Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
		}
		String day = dob2.substring(3,5);
		int d = Integer.parseInt(day);
		if (d > 31 || m <= 0){
			JOptionPane.showMessageDialog(null, "Sorry! The day must be between 01 and 31. " +
					"Please enter again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		
		for (int i = 6; i < 9; i++){
			if(!Character.isDigit(dob2.charAt(i))){
				JOptionPane.showMessageDialog(null, "Sorry! The year is not four digits. " +
						"Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
		}
		dob = dob2;
		return true;
	}
	
	public String getDob(){
		return dob;
	}

	public boolean setSsn(String ssn2) {
		if(ssn2.length() != 11){
			JOptionPane.showMessageDialog(null, "Sorry! The entered SSN is not valid(xxx-xx-xxxx)." +
					" Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		
		if(ssn2.indexOf("-") != 3 || (ssn2.lastIndexOf("-") != 6)){
			
			JOptionPane.showMessageDialog(null, "Sorry! The entered SSN is not valid (xxx-xx-xxxx). " +
					"Please enter again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
			return false;
		}
		
		for (int i = 0; i < 3; i++){
			if(!Character.isDigit(ssn2.charAt(i))){
				JOptionPane.showMessageDialog(null, "Sorry! The xxx is not three digits. " +
						"Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
		}
		
		for (int i = 4; i < 6; i++){
			if(!Character.isDigit(ssn2.charAt(i))){
				JOptionPane.showMessageDialog(null, "Sorry! The xx is not two digits. " +
						"Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
		}
		
		for (int i = 7; i < 11; i++){
			if(!Character.isDigit(ssn2.charAt(i))){
				JOptionPane.showMessageDialog(null, "Sorry! The xxxx is not four digits. " +
						"Please enter it again.",  "Lab 4",JOptionPane.INFORMATION_MESSAGE);
				return false;
			}
		}
		
		
		ssn = ssn2;
		return true;
	}
	public String getSsn(){
		return ssn;
	}

	
	
}

here is the Application class

import javax.swing.JOptionPane;
import java.text.NumberFormat;
public class NSFFunding {
	public static void main(String[] args) {
		Scientist[] scientist = new Scientist[10];
		createExistingUserData(scientist);
		int choice = 0, newAccount = 0;
		int login = loginPage(scientist);
		do{
			if (!(login == -1)){
				do {
					do {
						choice = Integer.parseInt(JOptionPane.showInputDialog(null, showMenu(), 
								"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
						if (choice < 1 || choice > 4)
							JOptionPane.showMessageDialog(null, "Sorry! There is no such option " + 
						choice + ". Please enter the option again.", "Take-Home Assignment 3", 
						JOptionPane.ERROR_MESSAGE);
					}while (choice < 1 || choice > 4);
	
					if (choice == 1)
						modifyProfile(scientist, login);
					else if (choice == 2)
						displayScientistProfile(scientist, login);
					else if (choice == 3)
						displayApplicationResult(scientist, login);
					else {
						JOptionPane.showMessageDialog(null, "Thanks for your application!", "Take-Home Assignment 3", 
								JOptionPane.INFORMATION_MESSAGE);
						login = -1;
					}
				}while(choice != 4);
			}
			else{
				newAccount = JOptionPane.showConfirmDialog(null, "Sorry! We don't have your account. " +
						"Do you want to create a new account?", "Take-Home Assignment 3", JOptionPane.YES_NO_OPTION);
				if (newAccount != JOptionPane.YES_OPTION)
					JOptionPane.showMessageDialog(null, "Goodbye!", "Take-Home Assignment 3", 
							JOptionPane.INFORMATION_MESSAGE);
				else{
					login = createAccount(scientist);
					JOptionPane.showMessageDialog(null, "Please create your own profile now.", 
							"Take-Home Assignment 3", JOptionPane.INFORMATION_MESSAGE);
					createProfile(scientist, login);
				}
			}
		}while(!(login == -1));
	}
	
	private static void createExistingUserData(Scientist[] scientist){
		scientist[0] = new Scientist("user1", "password1");
		scientist[0].setDob("02/02/1995");
		scientist[0].setSsn("612-45-7070");
		scientist[0].setApplicantName("Peter Lee");
		scientist[0].setInstituteName("George Washington University");
		scientist[0].setDepartmentName("Information System Department");
		scientist[0].setPositionRank(1);
		scientist[0].setResearchTopic("Software Engineering");
		scientist[0].setPastFunding(250000);
		scientist[0].setNumOfPaper(30);
	}
	
	private static int loginPage(Scientist[] scientist){
		String username = "", password = "";
		do{
			username = JOptionPane.showInputDialog(null, "Please enter the username:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			if (username == null || username.equals(""))
				JOptionPane.showMessageDialog(null, "Sorry! The username is empty. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(username == null || username.equals(""));
		
		do{
			password = JOptionPane.showInputDialog(null, "Please enter the password:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			if (password == null || password.equals(""))
				JOptionPane.showMessageDialog(null, "Sorry! The password is empty. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(password == null ||password.equals(""));
		
		return validateAccount(scientist, username, password);
	}
	
	private static String showMenu(){
		String menu = "Scientists' NSF Funding Application System";
		menu += "\n1. Update your profile";
		menu += "\n2. Display your profile";
		menu += "\n3. Submit and Application Result";
		menu += "\n4. Exit the system";
		return menu;
	}
	
	private static int createAccount(Scientist[] scientist){
		String username = "", password = "";
		int login = 0;
		do{
			username = JOptionPane.showInputDialog(null, "Please enter the username:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			password = JOptionPane.showInputDialog(null, "Please enter the password:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			if (!(validateAccount(scientist, username, password) == -1))
				JOptionPane.showMessageDialog(null, "Sorry! The account has been chosen. Please choose another one.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!(validateAccount(scientist, username, password) == -1));
		
		if (Scientist.getNumOfScientistsCreated() < scientist.length){
			scientist[Scientist.getNumOfScientistsCreated()] = new Scientist(username, password);
			login = Scientist.getNumOfScientistsCreated() - 1;
		}
		
		return login;
	}
	
	private static int validateAccount(Scientist[] scientist, String username, String password){
		boolean same = false;
		int i = 0, index = 0;
		
		while(!same && i < Scientist.getNumOfScientistsCreated()){
			if (scientist[i].getUsername().equals(username) && scientist[i].getPassword().equals(password))
				same = true;
			else
				i++;
		}
		
		if (same)
			index = i;
		else
			index = -1;
		
		return index;
	}
	
	private static void createProfile(Scientist[] scientist, int index){
		int positionRank = 0, numOfPaper = 0;
		String applicantName = "", instituteName = "", departmentName = "", researchTopic = "", dob = "", ssn = "";
		double pastFunding = 0;
		
		do{
			applicantName = JOptionPane.showInputDialog(null, "Please enter your name:", "Take-Home Assignment 3", 
					JOptionPane.QUESTION_MESSAGE);
		}while(!scientist[index].setApplicantName(applicantName));
		
		do{
			dob = JOptionPane.showInputDialog(null,"Please enter your birth date (mm/dd/yyyy): ", "Lab 4",
					JOptionPane.QUESTION_MESSAGE);
		}while(!scientist[index].setDob(dob));
		
		do{
			ssn = JOptionPane.showInputDialog(null,"Please enter your social security number (xxx-xx-xxxx): ", "Lab 4",
					JOptionPane.QUESTION_MESSAGE);
		}while(!scientist[index].setSsn(ssn));
		
		
		String usedSsn = scientist[0].getSsn();
		System.out.print(usedSsn);
			
			if (ssn.equals("" + usedSsn)){
				System.out.print("This is in use");
			}
		
		System.out.print(scientist[0]);
		
		
				
		do{
			instituteName = JOptionPane.showInputDialog(null, "Please enter the institue name:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			if (!scientist[index].setInstituteName(instituteName))
				JOptionPane.showMessageDialog(null, "Sorry! The name is empty. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!scientist[index].setInstituteName(instituteName));
		
		do{
			departmentName = JOptionPane.showInputDialog(null, "Please enter your department name:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			if (!scientist[index].setDepartmentName(departmentName))
				JOptionPane.showMessageDialog(null, "Sorry! The name is empty. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!scientist[index].setDepartmentName(departmentName));
		
		do{
			positionRank = Integer.parseInt(JOptionPane.showInputDialog(null, "Please choose your position:" +
					"\n1) Full Professor\n2) Associate Professor\n3) Assistant Professor\n4) Others", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
			if (!scientist[index].setPositionRank(positionRank))
				JOptionPane.showMessageDialog(null, "Sorry! The position choice is not one of the options. " +
						"Please enter it again.", "Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!scientist[index].setPositionRank(positionRank));
		
		do{
			researchTopic = JOptionPane.showInputDialog(null, "Please enter the research topic:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
			if (!scientist[index].setResearchTopic(researchTopic))
				JOptionPane.showMessageDialog(null, "Sorry! The topic is empty. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!scientist[index].setResearchTopic(researchTopic));
		
		do{
			pastFunding = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the past funding:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
			if (!scientist[index].setPastFunding(pastFunding))
				JOptionPane.showMessageDialog(null, "Sorry! The funding is negative. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!scientist[index].setPastFunding(pastFunding));
		
		do{
			numOfPaper = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the number of paper published:", 
					"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
			if (!scientist[index].setNumOfPaper(numOfPaper))
				JOptionPane.showMessageDialog(null, "Sorry! The number is negative. Please enter it again.", 
						"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
		}while(!scientist[index].setNumOfPaper(numOfPaper));
	}
	

	private static void modifyProfile(Scientist[] scientist, int index){
		int positionRank = 0, numOfPaper = 0, choice = 0;
		String applicantName = "", instituteName = "", departmentName = "", researchTopic = "";
		double pastFunding = 0;
		
		choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Please choose an iterm that you want to " +
				"update:\n1) Applicant Name\n2) Institute Name\n3) Department Name\n4) Position\n5) Research " +
				"Topic\n6) Past Funding\n7) Num of Papers Published", "Take-Home Assignment 3", 
				JOptionPane.QUESTION_MESSAGE));
		switch(choice){
			case 1:
				do{
					applicantName = JOptionPane.showInputDialog(null, "Please enter your new name:", 
							"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
					if (!scientist[index].setApplicantName(applicantName))
						JOptionPane.showMessageDialog(null, "Sorry! The name is empty. Please enter it again.", 
								"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setApplicantName(applicantName));
				JOptionPane.showMessageDialog(null, "Your name has been updated.", "Take-Home Assignment 3", 
						JOptionPane.INFORMATION_MESSAGE);
			break;
			
			case 2:
				do{
					instituteName = JOptionPane.showInputDialog(null, "Please enter your new institute:", 
							"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
					if (!scientist[index].setInstituteName(instituteName))
						JOptionPane.showMessageDialog(null, "Sorry! The name is empty. Please enter it again.", 
								"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setInstituteName(instituteName));
				JOptionPane.showMessageDialog(null, "Your institute has been updated.", "Take-Home Assignment 3", 
						JOptionPane.INFORMATION_MESSAGE);
			break;
			
			case 3:
				do{
					departmentName = JOptionPane.showInputDialog(null, "Please enter your new department name:", 
							"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
					if (!scientist[index].setDepartmentName(departmentName))
						JOptionPane.showMessageDialog(null, "Sorry! The name is empty. Please enter it again.", 
								"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setDepartmentName(departmentName));
				JOptionPane.showMessageDialog(null, "Your department has been updated.", "Take-Home Assignment 3", 
						JOptionPane.INFORMATION_MESSAGE);
			break;
			
			case 4:
				do{
					positionRank = Integer.parseInt(JOptionPane.showInputDialog(null, "Please choose your position:" +
							"\n1) Full Professor\n2) Associate Professor\n3) Assistant Professor\n4) Others", 
							"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
					if (!scientist[index].setPositionRank(positionRank))
						JOptionPane.showMessageDialog(null, "Sorry! The position choice is not one of the options. " +
								"Please enter it again.", "Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setPositionRank(positionRank));
				JOptionPane.showMessageDialog(null, "Your position has been updated.", "Take-Home Assignment 3", 
						JOptionPane.INFORMATION_MESSAGE);
			break;
			
			case 5:
				do{
					researchTopic = JOptionPane.showInputDialog(null, "Please enter your new research topic:", 
							"Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE);
					if (!scientist[index].setResearchTopic(researchTopic))
						JOptionPane.showMessageDialog(null, "Sorry! The topic is empty. Please enter it again.", 
								"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setResearchTopic(researchTopic));
				JOptionPane.showMessageDialog(null, "Your research topic has been updated.", "Take-Home Assignment 3", 
						JOptionPane.INFORMATION_MESSAGE);
			break;
			
			case 6:
				do{
					pastFunding = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter your funding " +
							"awarded:", "Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
					if (!scientist[index].setPastFunding(pastFunding))
						JOptionPane.showMessageDialog(null, "Sorry! The funding is negative. Please enter it again.", 
								"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setPastFunding(pastFunding));
				JOptionPane.showMessageDialog(null, "Your funding has been updated.", "Take-Home Assignment 3", 
						JOptionPane.INFORMATION_MESSAGE);
			break;
			
			case 7:
				do{
					numOfPaper = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your number of paper " +
							"published:", "Take-Home Assignment 3", JOptionPane.QUESTION_MESSAGE));
					if (!scientist[index].setNumOfPaper(numOfPaper))
						JOptionPane.showMessageDialog(null, "Sorry! The number is negative. Please enter it again.", 
								"Take-Home Assignment 3", JOptionPane.ERROR_MESSAGE);
				}while(!scientist[index].setNumOfPaper(numOfPaper));				
				JOptionPane.showMessageDialog(null, "The number of papers published has been updated.", "Take-Home " +
						"Assignment 3", JOptionPane.INFORMATION_MESSAGE);
			break;
		}	
	}	
		
	private static void displayScientistProfile(Scientist[] scientist, int index){
		JOptionPane.showMessageDialog(null, scientist[index].toString(), "Take-Home Assignment 3", 
				JOptionPane.INFORMATION_MESSAGE);
	}
	
	private static void displayApplicationResult(Scientist[] scientist, int index){
		NumberFormat currency = NumberFormat.getCurrencyInstance();
		currency.setMinimumFractionDigits(2);
		currency.setMaximumFractionDigits(2);
		if (scientist[index].getNewAwardFunding() == 0)
			JOptionPane.showMessageDialog(null, "Sorry! You have not had any new funding.", "Take-Home Assignment 3", 
					JOptionPane.INFORMATION_MESSAGE);
		else
			JOptionPane.showMessageDialog(null, "Congratulation! You received a new funding, " + 
		currency.format(scientist[index].getNewAwardFunding()) + ".", "Take-Home Assignment 3", 
		JOptionPane.INFORMATION_MESSAGE);
	}
}

how to search an array for that specific value and then compare it.

You lost me. All I was interested in was a loop that compares a String against the contents of an array. The rest of the program is in the way.

If you are interested in getting a search for a String to work, write a small simple program that compiles and executes with an array of Strings and a loop to search that array. Leave off the hundreds of lines of code that is not involved in that problem.

commented: countering negative rep, valid point made +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.