Question
I created a phone directory java program where I can read raw data directly from original text file, add contact to textfile, and print out
I created a "phone directory" java program where I can read "raw data directly from original text file, add contact to textfile, and print out a file with the list sorted in order.. heres my code:
import java.util.*; import java.io.*;
public class contactBook { public static void main(String[] args)throws IOException { Scanner keyboard = new Scanner(system.in); System.out.println("1. Read contact list"); System.out.println("2. Add contact"); System.out.println("3. Print all contacts"); System.out.println("4. Close program");
String choice; do { choice = in.nextLine(); switch (choice) { case "1": readList(); break; case "2": addContact(); break; case "3": printList(); break; case "4": System.exit(0); break; default: System.out.println("Enter numer from 1 to 4"); } while(!choice.equals("4")); } public static void readList() { String outputFile = "contact.txt"; } public static void addContact() { BufferedWriter add = new BufferedWriter(new FileWriter("contact.txt")); add.write("Enter new contact information:"); add.newLine(); } public static printList() { BufferedReader reader = new BufferedReader(new FileReader("clist.txt")); String input; ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started