Re: About to give up



KyoGaSuki wrote:

So finally it decided to actually PRINT something...and then I
realized that it wasn't working how I needed it to. I am just ready
to give up completely considering it is due in an hour and a half and
I have managed to mess it all up. That, and the formatting won't
work, AND nothing is showing up in the output file. *is seriously
close to tears*:

Here's the guts of a small test file I wrote up just now:

**********
Scanner scanner = new Scanner(new File("test1.txt"));
float balance = 1000.00f;
while (scanner.hasNext()) {
int num = scanner.nextInt();
float amt = scanner.nextFloat();
balance -= amt;

System.out.printf("%3d\t%6.2f\n", num, balance);
}
scanner.close();
**********

The input file has an integer and a float on each line. A typical output
line (console) is:

4 848.93

Some thoughts on your code:

1. as others pointed out, why create the PrintWriter and not use it? No
surprise that nothing is going to a file;
2. the format descriptor for ints is 'd';
3. You're talking money here...why are 'balance' and 'deposit' not floats or
doubles?;
4. catch the FileNotFoundException and do something useful with it *in* your
app, even if at this stage you are just printing a message.

I'll assume that the format of your input file supports your Scanner
parsing.

AHS
--
* change 'two' to '2' to email me
.



Relevant Pages

  • Re: frustrated by fscanf and sscanf
    ... there is no threads talking about reading a series of numbers. ... <snip description of input file structure> ... Your description of the file format makes no sense at all. ... along with a sample of your input file or a clearer ...
    (comp.lang.c)
  • Re: BWF.P to BWF.M Batch conversion program
    ... it contains two new "per file" options: A "File name override" option allows you to give the output file a different name than the input file. ... A "Sample rate override" option allows you to override the sample rate derived from the files (this does not change the audio data – it is sometimes useful for doing a manual correction e.g. if the input file format did not contain any sample rate information). ... - The new "Metadata" page not only allows you to view all metadata collected from the source file, it also allows you to edit and override it. ...
    (rec.arts.movies.production.sound)
  • Re: Printing C Program from KWrite on SuSE 10.1
    ... Enscript may be used but still no comprehensive list of the %y %U and ... %Format: name format ... Define a new string constant name according to the format string format. ... $L number of lines in the current input file. ...
    (alt.os.linux.suse)
  • Re: Hexadecimal Input Files
    ... have already finished a program in Assembler. ... I have had two semesters of COBOL class ... The format of the input file I am to use is in ... using this input file. ...
    (comp.lang.cobol)
  • Re: Parse an input file using a Key value
    ... I have an input file in the following format getting repeated. ... I tried to achieve this task using the following script below but it is ... To tranpose certain rows into columns and sort by one of the ...
    (comp.unix.shell)