Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Checking Account class, need help

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checking Account class, need help

    Sup folks, I have a rather unorganized homework assignment which consists of creating a program which stores the users initial balances and maintains their checking account.

    The assignment template:

    Write a class with methods to help you balance your checking account(an object class-main method is not in this class). The CheckingAccount Class should have at least two instance variables: the balance and the total service charges, along with methods to get and set each instance variables. You may add other variables and methods if you like. The program should read the initial balance for the month, followed by a series of transactions. For each transaction entered, the program should display the transaction data, the current balance for the account, and the total service charges. Service charges are $0.10 for a deposit and $0.15 for a check. If the balance drops below $500.00 at any point during the month, a service charge of $5.00 is assessed once for the month. Anytime the balance drops below $50.00, the program should print a warning message. If the balance becomes negative, an additional service charge of $10.00 should be assessed for each check until the balance becomes positive again. A transaction takes the form of an int number, followed by a double number. If the int number is a 1, then the double number is the amount of a check. If the int number is 2, then the double number is the amount of a deposit. The last transaction is 0 with no number to follow it.
    A sample Input/Output dialogue might look like this: (Use the JOptionPane for the dialog)

    I Enter your initial balance: 879.46
    O Initial balance : $879.46

    I Enter trans code:1
    I Enter trans amt: 400.00

    O Transaction : Check in amount of $400.00
    Current Balance : $479.46
    Service charge : Check --- charge $0.15
    Service charge : Below $500 --- charge $5.00
    Total service charge : $5.15

    I Enter trans code: 2
    I Enter trans amt: 100

    O Transaction : Deposit in amount of $100.00
    Current Balance : $579.46
    Service charge : Deposit --- charge $0.10
    Total service charge : $5.25

    I Enter trans code: 0

    O Transaction : End
    Current Balance : $579.46
    Total service charge : $5.25
    Final Balance : $574.21

    Code template:

    public class Main
    {
       //global variables:
       //define a CheckingAccount object to keep trach of the
       // account information.
       public static void main (String[] args)
       {
           // defines local variables
           //  get initial balance from the user
           //  perform in a loop until the trans code = 0
           //    get the trans code from the user
                 and process it with appropriate helper method
          //   When loop ends show final balance to user.
       }
     
       public static __________ getTransCode()
       {
       }
       public static _________ getTransAmt()
       {
       }
       public static __________ processCheck(___________)
       {
       }
       public static __________ processDeposit(___________)
       {
       }
     
    }
     
    --------------------CheckingAccount.java -------------------------
     
    public class CheckingAccount
    {
     
          private double balance;
          private double totalServiceCharge;
     
          public CheckingAccount(double initialBalance)
          {
                balance = ______________________;
                totalServiceCharge = ______________;
          }
     
          public ____________ getBalance()
          {
                return _______________;
          }
     
          public void setBalance(double transAmt, int tCode)
          {
                if(tCode == 1)
                balance = ___________________;
                else //if(tCode == 2)
                    balance = ______________________;
          }
     
          public ____________ getServiceCharge()
          {
                return totalServiceCharge;
          }
     
            public void setServiceCharge(double currentServiceCharge)
          {
                totalServiceCharge = ___________________________;
          }
    }

    To define the checkingaccount object, I did:

              public class Assignment1 
    {
            CheckingAccount info;
            double balance = 0;
     
            info = new CheckingAccount(balance);
     
     
         public static void main(String[] args)
        {

    however an error comes up stating: identifier expected


    My code currently consists of this:

    import javax.swing.JOptionPane;
    public class Assignment1 
    {
            CheckingAccount info;
            double balance = 0;
     
            info = new CheckingAccount(balance);
     
     
         public static void main(String[] args)
        {
           String balance, transcode, transamount, input;
     
     
           double ibalance;
           int tcode;
           double tamount;
     
     
           do
           {
     
            balance = JOptionPane.showInputDialog ("Enter your initial balance: ");
            ibalance = Double.parseDouble(balance);
     
            transcode = JOptionPane.showInputDialog ("Enter your transaction" + 
                       " code:");
            tcode = Integer.parseInt(transcode);
     
            if(tcode >= 1)
            {
     
            transamount = JOptionPane.showInputDialog ("Enter your trans amount:");
            tamount = Double.parseDouble(transamount);
     
     
     
     
            public static int getTransCode()
            {
                int transcode;
                return transcode;
            }
            }
            public static _________ getTransAmt()
            {
            }
            public static __________ processCheck(___________)
            {
            }
            public static __________ processDeposit(___________)
            {
            }
     
     
     
     
        }
    }

    With the last 4 methods given by my instructor, although I am not sure what they are used for. Would the getTrans method be only used to return the transaction value?

    Also how would I proceed from here? After asking the user for the transaction amount, I have to post the users checking account as so:

    This is the sample run code my professor has supplied, after asking the user for the transaction amount.

    Transaction: Check in amount of $50.00
    Current Balance: &450.00
    Service Charge: Check --- charge $0.15
    Service Charge: Below $4000 --- charge $5.00
    Total Service Charge: $5.15


    I understand how to post the transaction amount and the current balance, as the current balance would just be a simple calculation of initial balance - transaction amount.

    I don't understand how to calculate the service charge, with all the parameters in place of, if the balance is below 500 you have to charge 5.00. I'm guessing this is done by using a nested if - else statement, however the sample code my professor provided includes nothing of that sort, just the checkingaccount.class


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checking Account class, need help

    an error comes up stating: identifier expected
    Please post the full text of the error message that shows where the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Checking Account class, need help

    The only error that came up was identifer expected, nothing else. I am running Netbeans IDE.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checking Account class, need help

    Where is the error? At What line in the source?
    Please copy and paste here the full text of the compiler's error message.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Checking Account class, need help

    It just says identifer expected, there's nothing more.


    The error can be seen as I've pasted right under public class assignment1

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Checking Account class, need help

    Quote Originally Posted by alex067 View Post
    It just says identifer expected, there's nothing more.
    The error can be seen as I've pasted right under public class assignment1
    The error message should tell more, including which line is causing the error. Please show us more information.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checking Account class, need help

    Can't say what the problem is without the location of the error. One clue would be what class it is in. Another would be the line of code that is in the error message.

    What happens if you use the javac command to compile the file with the error?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Checking Account class, need help

    When I compile the error states:

    main at exception breakpoint java.lang.RuntimeException
    Assignment1.main:30

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checking Account class, need help

    That is not a compiler error. Runtime means it happened when the code was executing.
    What type of exception was it? Can you copy the full text of the error message and paste it here?
    Here is what a runtime exception error message should look like:
     
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    	at java.lang.String.substring(Unknown Source)
    	at TestCode10.main(TestCode10.java:310)
    The first line says the type of exception: StringIndexOutOfBoundsException
    the last line shows where: line 310 in TestCode10
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Checking Account class, need help

    That's all the compiler error gave me I'm afraid.


    My main question is regarding the main procedural step and how I should proceed from where I left off, as I'm a bit lost on what to do at the moment. I know that I have to use a loop to keep count of the transactions and balances, but that's about it.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Checking Account class, need help

    If you can't post the full text of the errors you are getting, it will be hard to make recommendations on how to fix the code.

    I recommend that you fix the compiler errors BEFORE adding more code and making the problem worse by introducing more errors.

    I'm done for today. Back tomorrow.
    Last edited by Norm; September 23rd, 2012 at 10:24 PM.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Designing an Account Class
    By m2msucks in forum What's Wrong With My Code?
    Replies: 16
    Last Post: July 27th, 2014, 06:05 PM
  2. Bank Account HELP!!!! PLEASE.
    By metaleddie13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 16th, 2011, 08:06 PM
  3. Create a java small class for a bank account!!?
    By jon123 in forum Object Oriented Programming
    Replies: 2
    Last Post: March 24th, 2010, 11:00 AM
  4. Bank account GUI using swing
    By AlanM595 in forum AWT / Java Swing
    Replies: 5
    Last Post: April 2nd, 2009, 04:39 AM
  5. How to delete records from a Random-Access File?
    By keith in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: March 31st, 2009, 11:40 AM