1 Replies - 63 Views - Last Post: 07 February 2012 - 08:08 PM Rate Topic: -----

Topic Sponsor:

#1 Candise Wise  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 07-February 12

Error Problem

Posted 07 February 2012 - 04:33 PM

Chapter 3: Interactive Checkbook Balancing Calculator

Filename: Balance.java
Purpose: This program calculates what the ending balance should be. After accepting
the beginning balance, the total of the checks written, the total of any
deposits, and the fees charged by the bank as inputs.

import java.io.*;

public class Balance
{
	public static void main(String[] args) throws IOException
	{
		//Declare and Construct Variables
		String balance, checks, startingBalance, deposits, fees, count;
		float endingBalance;
		BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in));
		
		//Print prompts and get input
		System.out.println("\tTBalancing Your Checkbook");
		System.out.println();
		System.out.println("\t\tWhat is the balance from your last statement?");
		balance = dataIn.readLine();
		startingBalance = String .parseInt(balance);
		
		System.out.println("\t\tWhat is the total amount of all deposits?");
		deposits = dataIn.readLine();
		checks = String.parseInt(deposits);
		
		System.out.println("\t\tWhat is the total amount of all checks?");
		checks = dataIn.readLine();
		count = string.parseInt(checks);
		
		System.out.println("\t\tWhat is the total amount of all transacation fees?");
		fees = dataIn.readLine();
		deposits = string.parseInt(fees);
		
		//Calculations
		endingBalance = startingBalance+deposits-(checks+fees);
		
		
		
		
		
		// Output 
		System.out.println("\t\tYour new balance is " + endingBalance);
	
}
}

It's coming up with error messages on the parse lines. I don't exactly know what I did wrong?

This post has been edited by smohd: 07 February 2012 - 08:05 PM
Reason for edit:: Code tags added. Please use [code] tags when posting codes


Is This A Good Question/Topic? 0
  • +

Replies To: Error Problem

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: Error Problem

Posted 07 February 2012 - 08:08 PM

The class String has no parseInt() method, the method is available in a wrapper class Integer:
startingBalance = String .parseInt(balance);

Should be Integer.parseInt()

Also you should look again at your declarations, you need numbers to do calculation and not strings:
String balance, checks, startingBalance, deposits, fees, count;

But some strings needed also to take input
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1