Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

///////////////Test Case//////////////// import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; public class LineNumbersTest

image text in transcribed

///////////////Test Case////////////////

import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; public class LineNumbersTest { @Rule public TemporaryFolder folder = new TemporaryFolder(); @Test public void test00() throws IOException { final String INPUT_FILENAME = "foo.txt"; final String OUTPUT_FILENAME = "output.txt"; // Create input and output files and populate input file File inputFile = folder.newFile(INPUT_FILENAME); File outputFile = folder.newFile(OUTPUT_FILENAME); PrintWriter write = new PrintWriter(inputFile); write.println("`Twas brillig, and the slithy toves"); write.println("Did gyre and gimble in the wabe:"); write.println("All mimsy were the borogoves,"); write.println("And the mome raths outgrabe."); write.close(); // Invoke method LineNumbers.parseData(inputFile, outputFile); // Check results assertTrue("File does not exist", outputFile.exists()); String actual, expected; Scanner scan = new Scanner(outputFile); actual = scan.nextLine(); expected = "File contains 124 characters"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "35 `Twas brillig, and the slithy toves"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 Did gyre and gimble in the wabe:"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 All mimsy were the borogoves,"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "28 And the mome raths outgrabe."; assertEquals("Incorrect result", expected, actual); scan.close(); } @Test public void test01() throws IOException { final String INPUT_FILENAME = "foo.txt"; final String OUTPUT_FILENAME = "output.txt"; // Create input and output files and populate input file File inputFile = folder.newFile(INPUT_FILENAME); File outputFile = folder.newFile(OUTPUT_FILENAME); PrintWriter write = new PrintWriter(inputFile); write.println("Rode here on the bus"); write.println("Now you're one of us"); write.println("It was magic hour"); write.println("Counting motorbikes"); write.println("on the turnpike"); write.println("One of Eisenhower's"); write.println(""); write.println("Live your life on a merry-go-round"); write.println("Who starts a fire just to let it go out?"); write.println(""); write.println("If I saw you on the street, would I have you in my dreams tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println(""); write.println("On the lead guitar"); write.println("Said you'd go to work"); write.println("In the waking hour"); write.println("In fluorescent light"); write.println("Antisocialites watch a wilting flower"); write.println(""); write.println("Live your life on a merry-go-round"); write.println("Who builds a wall just to let it fall down?"); write.println(""); write.println("If I saw you on the street, would I have you in my dreams tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println(""); write.println("Don't sit by the phone for me"); write.println("Wait at home for me, all alone for me"); write.println("Your face was supposed to be hanging over me like a rosary"); write.println("So morose for me; seeing ghosts of me; writing oaths to me"); write.println("Is it so naive to wonder..."); write.println(""); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.println("If I saw you on the street, would I have you in my dreams tonight, tonight?"); write.close(); // Invoke method LineNumbers.parseData(inputFile, outputFile); // Check results assertTrue("File does not exist", outputFile.exists()); String actual, expected; Scanner scan = new Scanner(outputFile); actual = scan.nextLine(); expected = "File contains 1316 characters"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "20 Rode here on the bus"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "20 Now you're one of us"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "17 It was magic hour"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "19 Counting motorbikes"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "15 on the turnpike"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "19 One of Eisenhower's"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "34 Live your life on a merry-go-round"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 Who starts a fire just to let it go out?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "66 If I saw you on the street, would I have you in my dreams tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 On the lead guitar"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "21 Said you'd go to work"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 In the waking hour"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "20 In fluorescent light"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "37 Antisocialites watch a wilting flower"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "34 Live your life on a merry-go-round"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "43 Who builds a wall just to let it fall down?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "66 If I saw you on the street, would I have you in my dreams tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 Don't sit by the phone for me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "37 Wait at home for me, all alone for me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "58 Your face was supposed to be hanging over me like a rosary"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "58 So morose for me; seeing ghosts of me; writing oaths to me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "27 Is it so naive to wonder..."; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "75 If I saw you on the street, would I have you in my dreams tonight, tonight?"; assertEquals("Incorrect result", expected, actual); scan.close(); } @Test public void test02() throws IOException { final String INPUT_FILENAME = "foo.txt"; final String OUTPUT_FILENAME = "output.txt"; // Create input and output files and populate input file File inputFile = folder.newFile(INPUT_FILENAME); File outputFile = folder.newFile(OUTPUT_FILENAME); PrintWriter write = new PrintWriter(inputFile); write.println("So now you found the time to get away"); write.println("But you don't know what to do about yourself"); write.println("I see it but I look the other way"); write.println("And I'm feeling like I'm falling out again"); write.println(""); write.println("On the outside, on the outside"); write.println("On the outside, change your mind"); write.println("I'm feeling nothing, I'm feeling nothing"); write.println("On the outside, change your mind"); write.println(""); write.println("I'm lost in"); write.println("I'm lost in"); write.println("I'm lost in"); write.println(""); write.println("So now you turn to me to get away"); write.println("But you haven't figured out just what you want"); write.println("You see those angels in the alleyway"); write.println("Were they coming here to save me from myself?"); write.println(""); write.println("On the outside, on the outside"); write.println("On the outside, change your mind"); write.println("I'm feeling nothing, I'm feeling nothing"); write.println("On the outside, change your mind"); write.println(""); write.println("I'm lost in the sugar"); write.println("Found out you're the only one"); write.println("I'm lost in the sugar"); write.println("Found out you're the only one"); write.println("Go on now forever"); write.println("Found out you're the only one"); write.close(); // Invoke method LineNumbers.parseData(inputFile, outputFile); // Check results assertTrue("File does not exist", outputFile.exists()); String actual, expected; Scanner scan = new Scanner(outputFile); actual = scan.nextLine(); expected = "File contains 763 characters"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "37 So now you found the time to get away"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "44 But you don't know what to do about yourself"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "33 I see it but I look the other way"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "42 And I'm feeling like I'm falling out again"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "30 On the outside, on the outside"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 On the outside, change your mind"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 I'm feeling nothing, I'm feeling nothing"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 On the outside, change your mind"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "11 I'm lost in"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "11 I'm lost in"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "11 I'm lost in"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "33 So now you turn to me to get away"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "46 But you haven't figured out just what you want"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "36 You see those angels in the alleyway"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "45 Were they coming here to save me from myself?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "30 On the outside, on the outside"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 On the outside, change your mind"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 I'm feeling nothing, I'm feeling nothing"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 On the outside, change your mind"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "21 I'm lost in the sugar"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 Found out you're the only one"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "21 I'm lost in the sugar"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 Found out you're the only one"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "17 Go on now forever"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 Found out you're the only one"; assertEquals("Incorrect result", expected, actual); scan.close(); } @Test public void test03() throws IOException { final String INPUT_FILENAME = "foo.txt"; final String OUTPUT_FILENAME = "output.txt"; // Create input and output files and populate input file File inputFile = folder.newFile(INPUT_FILENAME); File outputFile = folder.newFile(OUTPUT_FILENAME); PrintWriter write = new PrintWriter(inputFile); write.println("One, two"); write.println(""); write.println("Baby really hurt me"); write.println("Crying in the taxi"); write.println("He don't wanna know me"); write.println("Says he made the big mistake of dancing in my storm"); write.println("Says it was poison"); write.println("So I guess I'll go home"); write.println("Into the arms of the girl that I love"); write.println("The only love I haven't screwed up"); write.println("She's so hard to please"); write.println("But she's a forest fire"); write.println("I do my best to meet her demands"); write.println("Play at romance, we slow dance"); write.println("In the living room, but all that a stranger would see"); write.println("Is one girl swaying alone"); write.println("Stroking her cheek"); write.println(""); write.println("They say, \"You're a little much for me"); write.println("You're a liability"); write.println("You're a little much for me\""); write.println("So they pull back, make other plans"); write.println("I understand, I'm a liability"); write.println("Get you wild, make you leave"); write.println("I'm a little much for"); write.println("E-a-na-na-na, everyone"); write.println(""); write.println("The truth is I am a toy"); write.println("That people enjoy"); write.println("'Til all of the tricks don't work anymore"); write.println("And then they are bored of me"); write.println("I know that it's exciting"); write.println("Running through the night, but"); write.println("Every perfect summer's"); write.println("Eating me alive until you're gone"); write.println("Better on my own"); write.println(""); write.println("They say, \"You're a little much for me"); write.println("You're a liability"); write.println("You're a little much for me\""); write.println("So they pull back, make other plans"); write.println("I understand, I'm a liability"); write.println("Get you wild, make you leave"); write.println("I'm a little much for"); write.println("E-a-na-na-na, everyone"); write.println(""); write.println("They're gonna watch me"); write.println("Disappear into the sun"); write.println("You're all gonna watch me"); write.println("Disappear into the sun "); write.close(); // Invoke method LineNumbers.parseData(inputFile, outputFile); // Check results assertTrue("File does not exist", outputFile.exists()); String actual, expected; Scanner scan = new Scanner(outputFile); actual = scan.nextLine(); expected = "File contains 1200 characters"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "8 One, two"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "19 Baby really hurt me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 Crying in the taxi"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "22 He don't wanna know me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "51 Says he made the big mistake of dancing in my storm"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 Says it was poison"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 So I guess I'll go home"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "37 Into the arms of the girl that I love"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "34 The only love I haven't screwed up"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 She's so hard to please"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 But she's a forest fire"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 I do my best to meet her demands"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "30 Play at romance, we slow dance"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "53 In the living room, but all that a stranger would see"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "25 Is one girl swaying alone"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 Stroking her cheek"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "38 They say, \"You're a little much for me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 You're a liability"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "28 You're a little much for me\""; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "35 So they pull back, make other plans"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 I understand, I'm a liability"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "28 Get you wild, make you leave"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "21 I'm a little much for"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "22 E-a-na-na-na, everyone"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 The truth is I am a toy"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "17 That people enjoy"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "41 'Til all of the tricks don't work anymore"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 And then they are bored of me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "25 I know that it's exciting"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "30 Running through the night, but"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "22 Every perfect summer's"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "33 Eating me alive until you're gone"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "16 Better on my own"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "38 They say, \"You're a little much for me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "18 You're a liability"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "28 You're a little much for me\""; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "35 So they pull back, make other plans"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "29 I understand, I'm a liability"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "28 Get you wild, make you leave"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "21 I'm a little much for"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "22 E-a-na-na-na, everyone"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "22 They're gonna watch me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "22 Disappear into the sun"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "25 You're all gonna watch me"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 Disappear into the sun "; assertEquals("Incorrect result", expected, actual); scan.close(); } @Test public void test04() throws IOException { final String INPUT_FILENAME = "foo.txt"; final String OUTPUT_FILENAME = "output.txt"; // Create input and output files and populate input file File inputFile = folder.newFile(INPUT_FILENAME); File outputFile = folder.newFile(OUTPUT_FILENAME); PrintWriter write = new PrintWriter(inputFile); write.println("What have you gathered to report to your progenitors?"); write.println("Are your excuses any better than your senator's?"); write.println("He held a conference and his wife was standing by his side"); write.println("He did her dirty but no-one died"); write.println(""); write.println("I saw Sonny Liston on the street last night"); write.println("Black-fisted and strong singing Redemption Song"); write.println("He motioned me to the sky"); write.println("I heard heaven and thunder cry"); write.println(""); write.println("Run for cover"); write.println("Run while you can, baby, don't look back"); write.println("You gotta run for cover"); write.println("Don't be afraid of the fear, that's a played out trap, man"); write.println("You know you're not the only one"); write.println("And don't look back, just run for cover"); write.println(""); write.println("What are you waiting for, a kiss or an apology?"); write.println("You think by now you'd have an A in toxicology"); write.println("It's hard to pack the car when all you do is shame us"); write.println("It's even harder when the dirtbag's famous"); write.println(""); write.println("I saw my mother on the street last night"); write.println("All pretty and strong, singing 'the road is long'"); write.println("I said 'momma I know you've tried'"); write.println("But she fell on her knees and cried"); write.println(""); write.println("Run for cover"); write.println("Run while you can, baby, don't look back"); write.println("You gotta run for cover"); write.println("Don't be afraid of the fear, that's a played out trap, man"); write.println("I know you're not the only one"); write.println("And don't look back, just run for cover"); write.println(""); write.println("And there was nothing she wouldn't give"); write.println("Just to trust him with her nightmares, with her dreams"); write.println("She's running, she's running"); write.println("Just to trust him"); write.println("He got a big smile, he's fake news"); write.println("Just run for cover, you've got nothing left to lose"); write.println(""); write.println("Run for cover"); write.println("Run while you can, baby, don't look back"); write.println("You gotta run for cover"); write.println("Don't be afraid of the fear, that's a played out trap, man"); write.println("You know you're not the only one"); write.println("And don't look back, just run for cover"); write.close(); // Invoke method LineNumbers.parseData(inputFile, outputFile); // Check results assertTrue("File does not exist", outputFile.exists()); String actual, expected; Scanner scan = new Scanner(outputFile); actual = scan.nextLine(); expected = "File contains 1518 characters"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "53 What have you gathered to report to your progenitors?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "48 Are your excuses any better than your senator's?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "58 He held a conference and his wife was standing by his side"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 He did her dirty but no-one died"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "43 I saw Sonny Liston on the street last night"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "47 Black-fisted and strong singing Redemption Song"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "25 He motioned me to the sky"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "30 I heard heaven and thunder cry"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "13 Run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 Run while you can, baby, don't look back"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 You gotta run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "58 Don't be afraid of the fear, that's a played out trap, man"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 You know you're not the only one"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "39 And don't look back, just run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "47 What are you waiting for, a kiss or an apology?"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "46 You think by now you'd have an A in toxicology"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "53 It's hard to pack the car when all you do is shame us"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "42 It's even harder when the dirtbag's famous"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 I saw my mother on the street last night"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "49 All pretty and strong, singing 'the road is long'"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "34 I said 'momma I know you've tried'"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "35 But she fell on her knees and cried"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "13 Run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 Run while you can, baby, don't look back"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 You gotta run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "58 Don't be afraid of the fear, that's a played out trap, man"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "30 I know you're not the only one"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "39 And don't look back, just run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "39 And there was nothing she wouldn't give"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "54 Just to trust him with her nightmares, with her dreams"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "28 She's running, she's running"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "17 Just to trust him"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "34 He got a big smile, he's fake news"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "51 Just run for cover, you've got nothing left to lose"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "0 "; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "13 Run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "40 Run while you can, baby, don't look back"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "23 You gotta run for cover"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "58 Don't be afraid of the fear, that's a played out trap, man"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "32 You know you're not the only one"; assertEquals("Incorrect result", expected, actual); actual = scan.nextLine(); expected = "39 And don't look back, just run for cover"; assertEquals("Incorrect result", expected, actual); scan.close(); } }
CSC 201 Computer Science I Text I/O Lab Write a class "LineNumbers" that has the method "parse Data" (below) which reads a file containing text. The program counts the number of characters in that file and the number of characters per each line. It then writes that information, along with the contents of the read file, to an output file. public static void parseData (File inputFile, File outputFile) f //Your code here Use Scanner to read the contents of the input file and use PrintWriter to write out to the output file. Use string formatting to get the correct output. Each line after the first should be a print formatted string where: the number of characters in the line is a left justified String, width 10, and the content of the line itself is a right justified string of length 1. Be sure to include appropriate comments throughout your code and choose meaningful variable names. So if the input file is Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe. Your program should write EXACTLY this to "output.txt" File contains 124 characters 35 Twas brillig, and the slithy toves 32 Did gyre and gimble in the wabe: 29 All mimsy were the borogoves, 28 And the mome raths outgrabe

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

Database And Expert Systems Applications 23rd International Conference Dexa 2012 Vienna Austria September 2012 Proceedings Part 1 Lncs 7446

Authors: Stephen W. Liddle ,Klaus-Dieter Schewe ,A Min Tjoa ,Xiaofang Zhou

2012th Edition

3642325998, 978-3642325991

More Books

Students also viewed these Databases questions

Question

1. Explain why strategic planning is important to all managers.

Answered: 1 week ago

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago