Question: Help me edit this code **Add the punctuation and the capitalization when reversing the poem. Ex: Lamb little a had Mary. **Instead of using the
Help me edit this code
**Add the punctuation and the capitalization when reversing the poem. Ex: Lamb little a had Mary.
**Instead of using the Stack class in the Java API, create your own LinkedListStack class, with the push and pop methods in it.
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Stack;
public class Mary {
static Stack
public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String filename; Scanner infile = null; while (true) { System.out.println("Enter input filename: "); filename = keyboard.nextLine(); try { infile = new Scanner(new File(filename)); break; } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } }
while (infile.hasNextLine()) { readFileLoadStack(infile); popStackPrintMsg(); } infile.close();
}
private static void popStackPrintMsg() { if (!stack.isEmpty()) { System.out.print(stack.pop()); while (!stack.isEmpty()) { System.out.print(" " + stack.pop()); } } System.out.println(); }
private static void readFileLoadStack(Scanner infile) { String line = infile.nextLine(); String[] words = line.split(" "); for (int i = 0; i < words.length; i++) { stack.push(words[i]); } }
}
**********************************
text file
Mary had a little lamb Whose fleece was white as snow Everywhere that Mary went The lamb was sure to go
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
