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!!!
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!!!