permaculture playing cards*
The moose likes Java in General and the fly likes UpperCaseFile Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "UpperCaseFile Class" Watch "UpperCaseFile Class" New topic
Author

UpperCaseFile Class

Christopher Patrick
Greenhorn

Joined: Apr 09, 2013
Posts: 1

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!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.)
John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UpperCaseFile Class