import javax.swing.*; import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.plaf.ColorUIResource; public class ivan3 { public static void main(String[] args) { UIManager uim=new UIManager(); uim.put("OptionPane.background",new ColorUIResource(0,0,190)); uim.put("Panel.background",new ColorUIResource(0,0,190)); uim.put("OptionPane.messageForeground",new ColorUIResource(255,255,255)); uim.put("Panel.messageForeground",new ColorUIResource(255,255,255)); final String HEllo = "SORTING AND SEARCHING NAMES!"; int ctr = 0, ctr1 = 0, ctr2, ctr3 = 0; int search; int num = 0, cc = 0; String temp = ""; String searchee = ""; String JILL = ""; String range = "[A-Z a-z]*"; JOptionPane.showMessageDialog(null, HEllo,null,JOptionPane.PLAIN_MESSAGE); while (cc != 1){ try{ JILL = JOptionPane.showInputDialog(null, "Please put a number of names you want to sorted: "); num = Integer.parseInt(JILL); } catch(NumberFormatException k){ JOptionPane.showMessageDialog(null, "Numbers only, not Letters or Symbols"); cc--; } cc++; } String name[] = new String[num]; for (int i = 0; i < name.length; i++){ JILL= JOptionPane.showInputDialog("Enter the name: "); name[i] = JILL; char letter = name[i].charAt(0); // charAt() is method to find character at index number and return a single character from whole string. if (!name[i].matches(range)){ JOptionPane.showMessageDialog(null, "Input a Letters only."); i--; } else if (Character.isLowerCase(letter)){ // this code method determines whether the specified char value is lowercase. JOptionPane.showMessageDialog(null, " Capitalization of the first letter is required."); i--; } } System.out.println("Your unsorted names: "); for (int f = 0; f < name.length; f++){ System.out.println (name[f]); } while (ctr1 < name.length-1){ ctr2 = ctr1 + 1; while (ctr2 < name.length){ if (name[ctr1].compareTo(name[ctr2])>0){ temp = name[ctr1]; name[ctr1] = name[ctr2]; name[ctr2] = temp; } ctr2++; } ctr1++; } System.out.println("Your Sorted names: "); for (int e = 0; e < name.length; e++){ System.out.println (name[e]); } for (int v = 0; v != 1; v++){ JILL = JOptionPane.showInputDialog(null, "Enter the name you want to search or find."); searchee = JILL; char t = searchee.charAt(0); if (!searchee.matches(range)){ JOptionPane.showMessageDialog(null, "Letters only."); v--; } else if (Character.isLowerCase(t)){ JOptionPane.showMessageDialog(null, "Capitalization of the first letter is required.."); v--; } } while (ctr3 != name.length){ search = ctr3; if (searchee.equals(name[search])){ JOptionPane.showMessageDialog(null, "Name found SUCCESFULLY!."); break; } search++; ctr3++; while (true){JOptionPane.showMessageDialog(null, "Name not found."); for (int v = 0; v != 1; v++){ JILL = JOptionPane.showInputDialog(null, "Enter the name 'AGAIN' you want to search or find."); searchee = JILL; char t = searchee.charAt(0); if (!searchee.matches(range)){ JOptionPane.showMessageDialog(null, "Letters only."); v--; } else if (Character.isLowerCase(t)){ JOptionPane.showMessageDialog(null, "Capitalization of the first letter is required.."); v--; } if (searchee.equals(name[search])){ JOptionPane.showMessageDialog(null, "Name found SUCCESFULLY!."); break; } } } } } }
//this program is about sorting and searching a name anyone can help me fix this things?