Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello...i was struugling trying to get my program to read my file correctly. I got the code to compile correctly, however it reads the file

Hello...i was struugling trying to get my program to read my file correctly. I got the code to compile correctly, however it reads the file incorrectly...I need the file to say Hello COSC 455! as it says in the input file. For some reason it leaves out the 'H' in Hello. The rest runs more or less as it should and the .txt file is correct as well. please help me find the error in my code. The final image is what my program should read
image text in transcribed
image text in transcribed
image text in transcribed
this is the following output:
image text in transcribed
it should look like this....
image text in transcribed
Please Help
import java. util. Scanner; import jova. Lo. FileReader; import java, io. BufferedReader: import Java, io. IOException; public class Project \{ private Scanner scanner; private int currentline; private int currentColum; private char currentChar; private BufferedReader reader; public static void main(String args) throws IOException f Scanner input = new Scanner(System. in); String filename ="; Project reader = new Project(); do \{ System, out.print("Enter filenane (or \"quitl" or \"exitl" to quit): "); BufferedReader br = new BufferedReader(new java, io. InputStreamReader(System. in)); filenome = br. readline O; if (Ifilename,equals("quit") \&s Ifilenase.equals("exit")) \{ reader. openFile(filenane); while (Ireader. currentCharO. equals("end-of-text")) f reoder. nextChar O; System.out, println(reader,pesitionO +++ reader. currentChar()): \} \} else \{ System, out.println("Error: file not found"); currentColumn =1; nextChar(); // Initialize the currentChar field \} public void nextChar() throws IOException \{ I/ Read the next character from the file int c= reader. read(O; if (c=1){ // End of file reached currentChar =10 '; \} else \{ currentchar = (char) c; currentColumnt+; if (currentChar = ' n ') \{ // Newline character encountered currentlinet+; currentColumn =0; 3 \} \} public String currentChar() \{ if (currentChar = ' 10 ) \{ return "end-of-text"; \} else \{ return Character. tostring(currentChar); \} \} public String positionO \{ return currentline +":"+ currentColumn; 3 Enter filename (or "quit" or "exit" to quit): 1:1 e 1:21 1:31 1:40 2:0 2:1C 2:20 2:3S 2:4C 2:5 2:64 2:75 2:85 2:9 ! 2:9 end-of-text Enter filename (or "quit" or "exit" to quit): The reader should produce the following output: 1:1H1:2e1:311:411:502:02:1C2:202:3S2:4C2:52:642:752:852:9

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

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago