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