Question: I need to somehow convert the following program into javafx gui (using intellij) and I am not sure how, it needs to have a a

I need to somehow convert the following program into javafx gui (using intellij) and I am not sure how, it needs to have a a space to enter the commands for each command, a button for each command for example a list button that would start command 'l' and list the entries, a space to show the list of entries, and finally spaces to enter first and last name for example when you enter 'e' pop up boxes would appear to enter the fields. Any help in figuring this out or giving an example soultion would be amazing!! Here is my code:

package Sample; import java.io.*; import java.util.*; class Entry { public String first, last, number, note; }

public class Phonebookfor1510 { public static Entry[] contactList; public static int num_entries; public static Scanner stdin = new Scanner(System.in);

public static void main(String args[]) throws Exception { int i; char C; String code, Command; contactList = new Entry[200]; num_entries = 0; readPhoneBook("phonebook.txt"); System.out.println("Codes are entered as 1 to 8 characters. Use" + " \"e\" for enter," + " \"f\" for find," + " \"l\" for listing all the entries," + " \"m\" for Merging all the entries," + " \"q\" to quit."); Command = null; C = ' '; while (C != 'q') { System.out.print("Command: "); Command = stdin.next(); C = Command.charAt(0); switch (C) { case 'e': addContact(); break; case 'f': code = stdin.next(); stdin.nextLine(); i = index(code); if (i >= 0) { displayContact(contactList[i]); } else { System.out.println("**No entry with code " + code); } break; case 'l': listAllContacts(); break; case 'a': sortContactList(); break;

case 'm': { mergeContacts(); break; } case 'q': CopyPhoneBookToFile("PhoneBook1.txt"); System.out.println( "Quitting the application. All the entries are " + "stored in the file PhoneBook1.txt"); break; default: System.out.println("Invalid command Please enter the command again!!!"); }

}

}

private static void mergeContacts() { try { for (int i = 0; i < num_entries ; i++) { for (int j = 0; j < num_entries; j++) { if(i==j){ continue; } if (contactList[i].first.equals(contactList[j].first) && contactList[i].last.equals(contactList[j].last)) { // Concatenating notes & number to notes contactList[i].note = contactList[i].note.concat(" " + contactList[j].note); if (!(contactList[i].number.equals(contactList[j].number))) { contactList[i].note = contactList[i].note.concat(" " + contactList[j].number); }

removeElements(contactList, j); } } } } catch (NullPointerException exc) { }

System.out.println("merge completed..."); }

//method to remove an entity at certain index public static Entry[] removeElements(Entry[] input, int index) { List result = new LinkedList(); for (int i = 0; i < num_entries; i++){ if (!(i == index)) result.add(input[i]); }

num_entries=result.size(); return result.toArray(input); }

public static void sortContactList() {

for (int x = 1; x < num_entries; x++) { for (int y = 0; y < num_entries - x; y++) { if (contactList[y].first.compareTo(contactList[y + 1].first) > 0 && !contactList[y].first.equals("") && !contactList[y+1].first.equals("")) { Entry temp=contactList[y]; contactList[y] = contactList[y+1]; contactList[y+1]=temp;

} else if(contactList[y].first.compareTo(contactList[y + 1].first) == 0 && !contactList[y].first.equals("") && !contactList[y+1].first.equals("")){ if(contactList[y].last.compareTo(contactList[y + 1].last) > 0){//if it is based on phone use index 2 Entry temp=contactList[y]; contactList[y] = contactList[y+1]; contactList[y+1]=temp; } }

} } System.out.println(" Phonebook Sorted..");

}

public static void readPhoneBook(String FileName) throws Exception { File F; F = new File(FileName); Scanner S = new Scanner(F); while (S.hasNextLine()) { contactList[num_entries] = new Entry(); contactList[num_entries].first = S.next(); contactList[num_entries].last = S.next(); contactList[num_entries].number = S.next(); contactList[num_entries].note = S.nextLine(); num_entries++; } S.close(); }

public static void addContact() { String firstname = stdin.next(); String number; String lastname; stdin.nextLine();

if(firstname.length()>8){ System.out.println("First name should be between 1-8 characters."); return; }

contactList[num_entries] = new Entry(); contactList[num_entries].first = firstname; lastname = stdin.next();

if(lastname.length()>8){ System.out.println("Last name should be between 1-8 characters."); return; }

stdin.nextLine(); contactList[num_entries].last = lastname; System.out.print("Enter Number: "); number = stdin.nextLine(); contactList[num_entries].number = number; System.out.print("Enter Notes: "); contactList[num_entries].note = stdin.nextLine(); num_entries++; }

// Function to get the index of a key from an array // if not found, returns // -1 public static int index(String Key) { for (int i = 0; i < num_entries; i++) { if (contactList[i].first.equalsIgnoreCase(Key)) { return i; // Found the Key, return index. } } return -1; }

public static void displayContact(Entry contact) { System.out.println("--" + contact.first + "\t" + contact.last + "\t" + contact.number + "\t" + contact.note); }

public static void listAllContacts() { int i = 0; while (i < num_entries) { displayContact(contactList[i]); i++; } }

public static void CopyPhoneBookToFile(String FileName) throws Exception { FileOutputStream out = new FileOutputStream(FileName); PrintStream P = new PrintStream(out); for (int i = 0; i < num_entries; i++) { P.println(contactList[i].first + "\t" + contactList[i].last + "\t" + contactList[i].number + "\t" + contactList[i].note); } }

}

Any help with figuring out how to make and edit the javafx program will be much appreciated!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!