4 Replies - 5334 Views - Last Post: 27 November 2011 - 08:14 PM Rate Topic: -----

#1 CindyHope14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-November 11

Bank account program with many errors?

Posted 27 November 2011 - 04:07 PM

This is the code I have so far in my bank account program. I gave it to my teacher and she commented on what I needed to add. Although, when I tried implementing the code and compiling, I only receive errors. I tried using a switch statement to use days in a given month, but I think I had too many syntax errors.

import java.util.Scanner;
import java.io.*;
public class AccountDriver
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        String name, accountNumber, options = "DWAdwa";
        double balance, amount = 0;
        char transactionType;
        int month, day;
        boolean overdrawn;
        System.out.print("What is the name for the account?");
        name = s.nextLine();
        System.out.print("What is the account number?");
        accountNumber = s.next();
        System.out.print("What is the initial balance in the account?");
        balance = s.nextDouble();
        System.out.print("What is the month (1-12) for the account report?");
        month = s.nextInt();
        
        //modify the next statement to instantiate an account object with the input information
        Account account = new Account("John Doe", 00001, 100, 1);
        options = "DWAdwa";
        do
        {
            System.out.print("What day of the month is the next transaction (0 to stop)?");
            day = s.nextInt();
        }
        while (day < 0 || day > 31);
        
        //modify the previous statement to use the days in the given month
        while (day != 0)
        {
            do
            {
                System.out.print("What type of transaction (D=deposit, W=withdrawal, A=add interest, Q=quit)?");
                transactionType = s.next().charAt(0);
            }
            while (options.indexOf(transactionType) == -1);
            overdrawn = false;
            switch (transactionType)
            {
                case 'D': case 'd':
                    System.out.print("What is the amount of the deposit? ");
                    amount = s.nextDouble();
                    //process a deposit
                    
                    break;
                case 'W': case 'w':
                    System.out.print("What is the amount of the withdrawal? ");
                    amount = s.nextDouble();
                    //process a withdrawal
                    
                    break;
               case 'A': case 'a' : 
                    System.out.print("What is the amount of the interest? ")
                    amount = s.nextDouble();
                    //process adding interest
                    
                    break;
            }
            //add a transaction to the array of transactions
            do
            {
                System.out.print("What day of the month is the next transaction (0 to stop)?");
                day = s.nextInt();
            }
            while (day < 0 || day > 31);
            //modify the previous statement to use the days in the given month
        }
        
        //modify the println to print the final attributes for the account to the output file
        System.out.println(account);
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Bank account program with many errors?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10778
  • View blog
  • Posts: 40,134
  • Joined: 27-December 08

Re: Bank account program with many errors?

Posted 27 November 2011 - 04:10 PM

Post your specific errors exactly as they appear from your compiler.
Was This Post Helpful? 0
  • +
  • -

#3 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1414
  • View blog
  • Posts: 3,136
  • Joined: 05-April 11

Re: Bank account program with many errors?

Posted 27 November 2011 - 04:13 PM

You need a semi colon in the end of this line
System.out.print("What is the amount of the interest? ")



Also I suggest you convert your char to lower every time, so you don't need to switch on upper and lower.
transactionType = Character.toLowerCase(transactionType);


This post has been edited by CasiOo: 27 November 2011 - 04:14 PM

Was This Post Helpful? 1
  • +
  • -

#4 Serk102  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 19-June 11

Re: Bank account program with many errors?

Posted 27 November 2011 - 07:49 PM

Ok, so for
//modify the next statement to instantiate an account object with the input information
        Account account = new Account("John Doe", 00001, 100, 1);
All you have to do is take the information you've been given by the user at the beginning of the program and put them in the corresponding spots in the parameters. Not too hard so far.
System.out.print("What is the amount of the deposit? ");
amount = s.nextDouble();
//process a deposit


For the above I'm guessing there's some method in account that you have to carry out like account.deposit(amount) or something along those lines. That shouldn't be too bad although you might have to make the method yourself. The next two comments will follow a similar procedure.
//add a transaction to the array of transactions

I don't see an array of transactions anywhere but you can make one by using your account class and just copying the values to the transaction account. Or make an entirely new class called transactions and go from there...As for this
while (day < 0 || day > 31);
            //modify the previous statement to use the days in the given month

I'm not exactly sure what she's asking, but it sounds like she doesn't want you accidentally putting 31 days in February or something. In which case you can just sort out which months have how many days and have something like
while( day > maxDayofMonth || day < minDayOfMonth)
...

although I'm not really sure what you're trying to accomplish by running that loop with days outside of the month because in your original you had days<0 which doesn't make sense if you're trying to get a day from within the month from the user. I also don't have a clue as to what the do-while loop is doing because you're not actually doing anything if the user gives more than 1 input. Yeah, so there's some logic errors it seems on top of what you have been given by you teacher. Either that or I'm just stupid and can't figure what's going on.

ps: You don't need
options = "DWAdwa";
on line 24 because you already had it set to that in line 8.
Was This Post Helpful? 1
  • +
  • -

#5 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: Bank account program with many errors?

Posted 27 November 2011 - 08:14 PM

So, after applying Serk102 well justified corrections, post your revised code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1