This is the check off list
Here is the code that I already have, I need the rest implemented into the code I already have. Refer to the instructions at the top of the page
A word processor can represent and process a user's document as a list of Strings. Develop a menu based word processor with the following choices: D · New document. Clear the list of Strings. • Open file. Ask the user for a filename and read the contents of that file to the list of Strings. • Save file. Ask the user for a filename and write the list of Strings to that file. • Add lines to end. Allow the user to enter lines that are added to the end of the list of Strings. The user enters STOP (or a word of your choice) to finish inputting lines. • Replace a single line. Ask the user for the index number of a line, then get a replacement from the user for that line. • Insert lines. Ask the user for the index number of a line, then allow the user to enter lines that are inserted at the desired position into the list of Strings. The user enters STOP (or a word of your choice) to finish inputting lines! Delete a line. Ask the user for the index number of a line, remove that line from the list of Strings. Quit. The program ends. If the user provides an invalid index for ( R )eplace, Unsert, or (D)elete, print an error message and make no changes to the document. The indices and lines of the list of Strings are shown each time the menu is displayed. The menu input should recognize upper and lower-case versions of commands. Print an error message when the user enters an unknown command. . .
Menu loop New document Open file (read from file) Save file (write to file) Add lines to end Replace a single line Delete a line insert lines
9 1 import java.util.*; 2 import java.io.*; 3 4 public class Processor 5 6 static Scanner keyb = new Scanner(System.in); 7 8 static void displayDocument(ArrayList<String> doc) { System.out.println("Index Line") 10 System.out.println("===== ======"); 11 for(int ndx = 0; ndx < doc.size(); ndx++) { 12 System.out.printf("%d %s\n", 13 ndx, doc.get(ndx)); 14 } 15 16 17 public static void main(String[] args) { 18 ArrayList<String> document = new ArrayList<>(); 19 20 String menu = "(N) ew document, (0)pen file, (S)ave file, (A) "(R)eplace a single line, (I)nsert lines, (D "(Quit program"; 23 24 String choice = ""; 25 while (!choice.equals("Q")) { 26 //display document here 27 displayDocument(document); 28 System.out.println(menu '\nEnter your choice"); % (9:48) 5 21. 22. NN
29 30 31 32 33 34 35 36 37 38 39 choice = keyb.nextLine().toUpperCase(); switch(choice) { case "N": break; // insert function calls here case "O": break; case "S": I break; case "A": addlinesToEnd (document); break; case "R": break; case "I": break; case "D": break; case "Q": break; default: System.out.println("No such command, please try ag 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 } } 55 56 15% (9:40) System.out.println("Bye
56 57 System.out.println("Bye"); I 58 ] 59 60 static void addlinesToEnd (ArrayList<String> doc) { System.out.println("adding lines"); 62 ] 63 61
A word processor can represent and process a user's document as a list of Strings. Develop a menu based word processor w
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
A word processor can represent and process a user's document as a list of Strings. Develop a menu based word processor w
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!