package Chapter6and7; import java.util.*; import java.io.*; public class LittleL
ID: 3655089 • Letter: P
Question
package Chapter6and7; import java.util.*; import java.io.*; public class LittleLamb { public static void main(String[] args) throws FileNotFoundException{ try { PrintWriter outFile = new PrintWriter("C:\Users\Andy Baran\Documents\Computer Science\littelamb.txt"); outFile.println("Mary had a little lamb "); outFile.println("Whose fleece were white as snow "); outFile.println("And everywhere that Mary went "); outFile.println("The lamb was sure to go!"); outFile.close(); } catch (Exception e) { System.out.println("Error with file: "); e.printStackTrace(); } System.out.println("Input file: "); Scanner getNames = new Scanner(System.in); String inputFileName = getNames.next(); System.out.println("Output file: "); String outputFileName = getNames.next(); File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = new PrintWriter(outputFileName); int total = 1; while (in.hasNextLine()) { String line = in.nextLine(); System.out.println("/*" +total+ "*/" +line); (definitely messing up somewhere here in this while loop... i think) total = total + 1; } in.close(); getNames.close(); out.close(); } } and here is the psuedcode... import java.util.*; import java.io.*; public class LittleLamb { public static void main(String[] args) throws FileNotFoundException { //create a Scanner object //prompt for input file name //declare a String variable and set it to the fully qualified //filename from the user be careful with slashes \ in the path //prompt for output file name //declare a String variable and set it to the fully qualified //filename from the user be careful with slashes \ in the path //construct the Scanner and PrintWriter objects for reading and writing //create a File object set is constructor by passing in the infile String object //create another Scanner object by passing in the File object you just created //create a PrintWriter object by passing in the outfile String object //create an int primitive and start it at 1 for line 1 //read the input and write the output //use a while loop while infile has next line //declare a String set it equal to the next line of the infile //printWriter object dot println "/* + your line number + " */" the line from infile //increase counter for line number } //close all three Scanner objects in three separate lines } }Explanation / Answer
only thing i could see missing was while (getNames.hasNextLine()&&totalRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.