• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UpperCaseFile Class

 
Greenhorn
Posts: 1
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic