runtime error reading data from text file

R

Robocop

Hi folks please help me figure out whats wrong with this code i have
shown which part is giving run time error (below code is the
datafile!).....

please read its pretty simple just few bugs !

import type.lang.*;
import type.lib.*;
import java.util.*;

public class Check0

{
public static void main(String []args)
{
IO.println("Enter name, limit, and trx filename
(comma-delimited):");
String finstr = "PCL";
StringTokenizer tok = new StringTokenizer(IO.readLine() ,",");

String name = tok.nextToken();
String limit = tok.nextToken();
String file = tok.nextToken();
double num = Double.parseDouble(limit);
CreditCard card = new CreditCard(2343,name,num);
UniReader ur = new UniReader(file);

int count = 0; //00001 counter

for (String str = ur.readLine(); !ur.eof(); str = ur.readLine())
{
count++; //counts no. of records.
StringTokenizer tok2 = new StringTokenizer(str);
IO.print(count, "5Z");
if(str == "")
{
IO.println(" invalid record.");
}
for (;tok2.hasMoreTokens();)
{
String tranin = tok2.nextToken().toUpperCase();
String trancode = "" + tranin.charAt(0);
//FOLLOWING PART IS GIVING RUNTIME ERROR!!!
String stra = tok2.nextToken(); //gets p550.. from data file given
below

IO.print(stra.charAt(0));
if(finstr.charAt(finstr.indexOf(stra.charAt(0))) == stra.charAt(0));

String stram = stra.substring(1, stra.length());
//??????????????????OVER???????????????????????????????????/
double amount = Double.parseDouble(stram);
trancode.toUpperCase();

IO.print(" "+trancode);
IO.print(amount, "10.2");
if (trancode.equals("C") && card.charge(amount))
{
IO.print(" done.","10.2L");
}
else if (trancode.equals("P"))
{
card.pay(amount);
IO.print(" done.","10.2L");
}
else if (trancode.equals("L") && card.setLimit(amount))
{
IO.print(" " +"done.","10.2L");
} else{
IO.print(" " +"rejected.","10.2L");
}
IO.println();

} //end of hasMoreTokens();

} // end of tokenizer


IO.print("Card Balance = ");
IO.print(card.getBalance(), "10.2");
IO.println();
IO.print("Credit Limit = ");
IO.print(card.getLimit(), "10.2");

}
}

_____________________________

c 500
c 2100
p550 // <==problem line
c 5950
c 3000

l4000 // <== problem line
p 4050
l 2500
c 2750
p 500
c 200
p 1000
_____________________________

thanks a lot for your help!!! :)
 
S

Sudsy

Robocop said:
Hi folks please help me figure out whats wrong with this code i have
shown which part is giving run time error (below code is the
datafile!).....

please read its pretty simple just few bugs !

Only few bugs? Why think you that we have nothing better to do
than fix your errors? Think you not that you figure out
potential problems first?
Do you think that this is some 24x7 support line, dedicated to
assisting people such as yourself who don't want to expend
the time and/or effort to understand basic algorithms?
Please retry on c.l.j.h...
Sheesh!
 
M

Marco Schmidt

Robocop:
Hi folks please help me figure out whats wrong with this code i have
shown which part is giving run time error (below code is the
datafile!).....

Just take an IDE with a debugger like Eclipse and step through the
code, watching the content of variables, that should bring up the
problem.

For that purpose, you should deobfuscate (is that a word?) lines like

if(finstr.charAt(finstr.indexOf(stra.charAt(0))) == stra.charAt(0));

Most importantly - what runtime error are you getting? Is there a
stack trace? What were you expecting at the line where the error
occurs?

Regards,
Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top