Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I make my code so it will work in a JavaFX file? Here's my code so far: import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream;

How do I make my code so it will work in a JavaFX file?

Here's my code so far:

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.PrintStream;

import java.util.Scanner;

import java.util.HashSet;

class Entry {

String fname, lname, number, note;

public Entry() {

fname = "";

lname = "";

number = "";

note = "";

}

}

class PBN {

public static Entry[] contactList;

public static HashSet h = new HashSet();

public static int num_entries;

public static Scanner stdin = new Scanner(System.in);

public static void main(String args[]) throws Exception {

char C;

String code, Command;

contactList = new Entry[999];

num_entries = 0;

try {

readPhoneBook("Phonebook.txt");

} catch (FileNotFoundException e) {

}

System.out.println("Codes are entered as 1 to 8 characters. " +

"Use Commands: " +

" \"e\" for enter a new contact, " +

" \"f\" for find contact by fist name, " +

" \"r\" for find contact by last name, " +

" \"y\" for find contact by phone number, " +

" \"l\" for listing all the existing contacts, " +

//" \"m\" for removing the entries by name, " +

" \"d\" for removing contacts by phone number, " +

" \"a\" for sort alphabetically by first name, " +

" \"n\" for sort alphabetically by last name, " +

" \"p\" for sort by number, " +

" \"q\" to quit.");

while (true) { // loop infinitely

System.out.print("Command: ");

Command = stdin.nextLine();

C = Command.charAt(0);

switch (C) {

case 'e':

addContact();

break;

case 'f':

System.out.print("Search for contact by first name: ");

code = stdin.next();

stdin.nextLine();

index(code);

break;

case 'r':

System.out.print("Search for contact by last name: ");

code = stdin.next();

stdin.nextLine();

index1(code);

break;

case 'y':

System.out.print("Search for contact by phone number: ");

code = stdin.next();

stdin.nextLine();

index2(code);

break;

case 'l':

listAllContacts();

break;

case 'q': // when user wants to quit

CopyPhoneBookToFile("Phonebook.txt");

System.out.println("Quitting the application. All the entries are "

+ "stored in the file Phonebook.txt");

System.exit(0); // simply terminate the execution

case 'a':

sortList1();

break;

case 'n':

sortList2();

break;

case 'm:

mergeContacts();

break;

case 'p':

sortListByPhoneNumber();

break;

/*

case 'm': // m for deleting a contact; delete by first name

System.out.print("Enter the first name of a contact you wish to remove : ");

String fname = stdin.nextLine(); // read the contact number

removeEntry(fname); // remove the number from the entries

break;

case 'o': // m for deleting a contact; delete by last name

System.out.print("Enter the last name of a contact you wish to remove : ");

String lname = stdin.nextLine(); // read the contact number

removeEntry2(lname); // remove the number from the entries

break;

*/

case 'd': // m for deleting a contact; delete by phone number

System.out.print("Enter the phone number of a contact you wish to delete : ");

String number = stdin.nextLine();// read the contact number

/*

System.out.println("You want to delete this contact?");

index2(number);

System.out.println("Yes or no");

stdin.nextLine();

if (stdin.equals("Yes")){

}else if (stdin.equals("No")){

return;

}else{

return;

}

*/

removeEntry1(number); // remove the number from the entries

break;

default:

System.out.println("Invalid command Please enter the command again!!!");

}

}

}

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].fname = S.next();

contactList[num_entries].lname = S.next();

contactList[num_entries].number = S.next();

contactList[num_entries].note = S.nextLine();

num_entries++;

}

S.close();

}

public void edit(String fname, String lname, String number, String note, int selection){

contactList[selection].fname = fname;

contactList[selection].lname = lname;

contactList[selection].number = number;

contactList[selection].note = note;

}

public static void addContact() {

System.out.print("Enter first name: ");

String fname = stdin.nextLine();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago