A little problem
Okay, I modified another program I wrote, I probabaly should have started from scratch, but whatever.
(most of what you see commented out are parts of the code I didn't want to get rid of, incase it was useful)
The problem is somewhat explained in the code, but basically, I run the program, put in my latest paycheck, it takes half of my overall total, then takes any withdrawls and sticks it in another variable, then any tips I happen to get. When I run it, I know it saves what I put in, because I have it printing that out in the beginning.
I'm not sure if the parseInt is doing what it needs to do, I have outputs randomly in the code to try and find where the problem is, so they don't really matter. Now, When it outputs the final numbers, it is just taking what I put in that run and using them, the math I am running with the old numbers isn't effecting the results any.
publicclass Balance{
/**
* @param args
*/
publicstaticvoid main(String[] args){
// TODO Auto-generated method stub
{
String path ="C:/paycheck.txt";
JTextArea outputarea =new JTextArea();
String[] spaces=new String[5];
spaces[0]="Total: ";
spaces[1]="Half: ";
spaces[2]="Left to spend: ";
spaces[3]="Tips: ";
String[] data=new String[5];
int counter=0;
String test="";
String[] subtotals=new String[5];
double totals[]=newdouble[5];
double[] outPut=newdouble[5];
double soFar;
double half;
double left;
subtotals[0]="";
subtotals[1]="";
subtotals[2]="";
subtotals[3]="";
try
{
FileReader tester=new FileReader(path);
BufferedReader thingy=new BufferedReader(tester);
for(int count=0;count<4;count++)
{
try
{
test=thingy.readLine();
data[count]=test;
System.out.println(data[count]);
}
catch (IOException e){}
}
try{
tester.close();
}
catch(IOException e){}
}
catch(FileNotFoundException e)
{
System.out.println("File Not Found");
}
for(int scoreloop=0;scoreloop<=4;scoreloop++)
{
try{
subtotals[scoreloop]=subtotals[scoreloop]+(data[scoreloop].substring(0, data[scoreloop].length()));
try
{
totals[scoreloop]=Integer.parseInt(data[scoreloop]);
System.out.println(totals[scoreloop]);
}
catch(NumberFormatException e){}
}
catch(NullPointerException e){}
}
double newCheck=Console.readDouble("Enter Paycheck");
double takenOut=Console.readDouble("Any withdrawl?");
double tips=Console.readDouble("Tips?");
// I think this is where the problem is, it seems to just use the numbers
// that I enter, and do none of the math.
soFar=totals[0]+newCheck;
half=soFar/2;
left=totals[2]+(newCheck/2)-takenOut;
//System.out.println("totals[0]:"+totals[0]);
//System.out.println("takenOut:"+takenOut);
//System.out.println("tips:"+tips);
outPut[0]=soFar;
outPut[1]=half;
outPut[2]=left;
outPut[3]=totals[3]+tips;
try{
FileOutputStream newtester=new FileOutputStream(path);
PrintStream thingy2=new PrintStream(newtester);
for(int count=0;count<4;count++)
{
thingy2.println(outPut[count]);
}
newtester.close();
}
catch(IOException e)
{
System.out.println("File Not Found");
}
//String out="";
for(int count=0;count<4;count++)
{
//System.out.println((count+1)+"."+order2[count]+"\t"+order[count]);
System.out.println(spaces[count]+outPut[count]);
}
//outputarea.setText( out );
//JOptionPane.showMessageDialog( null, outputarea, "High Scores", JOptionPane.INFORMATION_MESSAGE );
}
}
}
This was supposed to be a quick little program, so i don't really have seperate classes or anything for it.

