Forums Register Login

UpperCaseFile Class

+Pie Number of slices to send: Send
Hello everyone! I am new to this forum but have been searching around on here for awhile now.

I already have this program completed, I think, but I my professor wants me to create a tester and a class. I only have the one program.

The assignment reads:
The class's constructor should accept twp file names as arguments. The first file should be opened for reading and the second file should be opened for writing. The class should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except all the characters will be in uppercase.

And here is my code:


If someone is able to help me with splitting this program up into a tester (demo), and a class that would be awesome! Also I receive an error as well: "The method readLine(boolean) in the type BufferedReader is not applicable for the arguments (String)"

Thanks again!
+Pie Number of slices to send: Send
If you are getting that error, then your program is NOT done, as it is not compiling (and is certainly not running). Further, your code doesn't seem to do what the assignment asks for.

The advice you will get here is most likely advice you will not like to hear:

Throw all this code away, and start over.

You have written all your code in a single method - and the main method, at that. That is not how you write OO code. That's really not even a good way to write procedural code. Your main should do almost nothing but create an object and call its run() method. You should then have lots of other methods that all do little things - get input from the user. print some output. etc.

+Pie Number of slices to send: Send
And as for the specific error message, it's telling you exactly what's wrong. You're trying to pass a String argument to a method that does not accept a String. You can't just pass whatever you want to methods. You can only call a method with the arguments it's documented to accept.

(I don't know what the "boolean" part is about though. That's not part of the standard BufferedReader that I know of, but maybe you're using a different class by that name.)
+Pie Number of slices to send: Send
In your program, you have written all of the code in the main routine.
You may want to make some functions instead, just keep them short. Something like

getKeyboardInput which gets the two file names
openFiles which opens the two files
processFiles which reads from one file, converts to upper case, and writes to the 2nd file
closeFiles which closes files

Now, if you take your code, and split into functions, such as those listed above, you will see that some of the variables are common to the different members such as the file names and the file reader / writer variables. Put the common variables as members of the class, outside of the functions, so they are available to all the class functions.

Then, change your main function to look something like this
main() {
PatrickUpperCaseFile pucf = new PatrickUpperCaseFile();
pucf.getKeyboardInput ();
pucf.openFiles();
pucf.processFiles();
pucf.closeFiles();
}

I'm not clear what level of testing your instructor wants you to perform. Maybe you could think of the values of the class variables before the function is executed, compared to the values after the function executes, and write a test to see that the values changed as expected.

You can add get functions for each of the member variables. Then your tests could look something like

testPatrickUpperCaseFile {
PatrickUpperCaseFile pucf = new PatrickUpperCaseFile();
assertEquals(pucf.getFirstFileName(),null);
...
}

testPatrickUpperCaseFile {
PatrickUpperCaseFile pucf = new PatrickUpperCaseFile();
pucf.getKeyboardInput ();
assertEquals(pucf.getFirstFileName(),"SomeNameForFirstFile");
...
}

In this way, your tests evaluate the progress of your programs algorithm step by step.

Good Luck
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3158 times.
Similar Threads
Need help with username and password validation
Problems reading from a .txt file
java.lang.NullPointerException
Searching an Array
Did I do this right? (Interest calculator)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:01:32.