7 Replies - 2446 Views - Last Post: 27 March 2011 - 10:52 AM Rate Topic: -----

#1 mwharyjr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-March 11

Basic Bank Account Program

Posted 27 March 2011 - 09:35 AM

I need to make the code fire errors if the Contribution balance is less than $100, it has to say that the bank don't except anything lower than $100 and ask to enter a amount hirer than $100, The way I have it now, works, but no matter what I put, I get the error I have it to ask for, I tryed switching the > < both ways, I am not sure if I am missing something or what, any advice is appreciated. Thanks!!
import java.util.Scanner;
import java.text.*;
public class CertificateofDeposit5
{
public static void main(String[] args)
{
		Scanner console = new Scanner(System.in);
		
	double contribution=0;			
do
{
System.out.print("Please enter what your able to contribute. ");
contribution = console.nextFloat();
if (contribution >= 100);
{
System.out.print("Current banking rules don't allow this amount");
}
}while(contribution <= 100);

                System.out.print("Current Market Annual Interest Rate: ");
	 			float Apr = console.nextFloat();
				if(Apr <= 10);
		System.out.print("Please enter Amount lower than 10%");
		
		System.out.print("Number of Years Planned Investment: ");
				int years = console.nextInt();
		System.out.println();
		printTables(years, contribution, Apr);
		System.out.println();
}
public static double calcInt
				(double balance, double rate)
{
				double xRate = (rate / 100);
				double interestTotals = balance * xRate;
		balance = balance + interestTotals;
				return interestTotals;
}
public static void printTables(int numberRows, double balance, double rate)
{
				double compondInterest=0;
		System.out.println("Year#\tCash\t\tInterest\tTotalCash");
		System.out.println("-----\t-------\t\t--------\t--------");
				for (char i = 1; i <= numberRows; i++)
{
		compondInterest = calcInt(balance, rate);
		printRow(i, balance, compondInterest);
		balance = balance + compondInterest;
}
}
public static void printRow(char rowNum, double bal, double interest)

{
				double newBalance = bal + interest;
		String StringBal = roundTo2Dec(bal);
		String StringInt = roundTo2Dec(interest);
		String StringNewBal = roundTo2Dec(newBalance);
		System.out.println(rowNum + "\t" + StringBal + "\t" + StringInt + "\t\t" + StringNewBal);
}
public static String roundTo2Dec(double value)
{
		DecimalFormat Currency = new DecimalFormat("$#,###.0#");
		String exactFormat = Currency.format(value);
				return exactFormat;}

	}


Edited by japanir: Added code tags.

Edited by macosxnerd101: Renamed title to be more descriptive.

Is This A Good Question/Topic? 0
  • +

Replies To: Basic Bank Account Program

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Basic Bank Account Program

Posted 27 March 2011 - 09:43 AM

You have an extra semicolon at the end of the if statement on line 14. Delete that, and change both comparisons (on lines 14 and 18) to <


You also have the same error (extraneous ; ) at the end of line 22.

There should never be a semicolon at the end of an if statement.

This post has been edited by r.stiltskin: 27 March 2011 - 09:46 AM

Was This Post Helpful? 1
  • +
  • -

#3 mwharyjr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-March 11

Re: Basic Bank Account Program

Posted 27 March 2011 - 09:49 AM

View Postr.stiltskin, on 27 March 2011 - 09:43 AM, said:

You have an extra semicolon at the end of the if statement on line 14. Delete that, and change both comparisons (on lines 14 and 18) to <


You also have the same error (extraneous ; ) at the end of line 22.

There should never be a semicolon at the end of an if statement.


haha, that simple, thanks so much, this was driving batty.
Was This Post Helpful? 0
  • +
  • -

#4 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Basic Bank Account Program

Posted 27 March 2011 - 09:52 AM

You might also want to change some of your print statements to println so it will advance to the next line, for example:
System.out.println("Please enter what you're able to contribute. ");
Was This Post Helpful? 1
  • +
  • -

#5 mwharyjr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-March 11

Re: Basic Bank Account Program

Posted 27 March 2011 - 10:09 AM

View Postr.stiltskin, on 27 March 2011 - 09:52 AM, said:

You might also want to change some of your print statements to println so it will advance to the next line, for example:
System.out.println("Please enter what you're able to contribute. ");


So what do I have to add to also fire an error if user enter 0 or an negative number, I thought it was if(Apr >=10 && 0)
but thats not it. Thanks

do
{
System.out.print("Current Market Annual Interest Rate. ");
Apr = console.nextFloat();
if(Apr >= 10)
{
System.out.print("Please enter Amount lower than 10%. ");
}
}while(Apr >=10);
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Basic Bank Account Program

Posted 27 March 2011 - 10:23 AM

if(Apr < 0.0 || Apr >= 10)
Was This Post Helpful? 1
  • +
  • -

#7 mwharyjr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 23-March 11

Re: Basic Bank Account Program

Posted 27 March 2011 - 10:31 AM

View Postpbl, on 27 March 2011 - 10:23 AM, said:

if(Apr < 0.0 || Apr >= 10)


and that would also be the same for the while statement?
Was This Post Helpful? 0
  • +
  • -

#8 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Basic Bank Account Program

Posted 27 March 2011 - 10:52 AM

Yes, of course the while should agree with the if.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1