Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:53:22+00:00 2026-05-31T23:53:22+00:00

When I update the balance of certain record in the array, using the deposit

  • 0

When I update the balance of certain record in the array, using the deposit and withdraw amounts, the balance for that sepcific record changes along with the balance for the records in arrays.

How to fix it?

private String name;
private int pin;
private int account;
private static double balance;

public void setBalance(double amount)
{
    balance = amount;
}

public static void deposit(double aDeposit) 
{ 
balance = balance + aDeposit; 
} 
public static void withdraw(double aWithdraw) 
{ 
    if  
    ( balance >= aWithdraw) 
        balance = balance - aWithdraw; 
    else if 
    ( balance < aWithdraw) 
        System.out.println("Cannot withdarw amount."); 
}

public double getBalance( )
{
    return balance;
}
public boolean equal(CustomerRecord otherObject)
{
    return (name.equalsIgnoreCase(otherObject.name) &&
           (pin == otherObject.pin) &&
           (account == otherObject.account) &&
           (balance == otherObject.balance));

      }
  }

    do{   


        System.out.println("Enter the name");
        String aName;
        Scanner keyboard = new Scanner(System.in);
        aName = keyboard.nextLine();

        System.out.println("Enter the pin");
        int aPin;
        aPin = keyboard.nextInt();


             for

             (int i = 0; i < index; i++) {
              CustomerRecord record = anotherArray[i];
              if
              ((record.getName().equalsIgnoreCase(aName)) && (record.getPin() == (aPin)))

          {
                 System.out.println(record);

             System.out.println("Enter the amount you wish to Deposit");
             double aDeposit;
             aDeposit = keyboard.nextDouble();
             CustomerRecord.deposit(aDeposit);

             System.out.println("Enter the amount you wish to withdraw");
             double aWithdraw;
             aWithdraw = keyboard.nextDouble();
             CustomerRecord.withdraw(aWithdraw);


            record.getBalance();

  }
             }

        System.out.println("\nAnother Transaction? (y for yes) (n for no)");
        repeat = keyboard.next().charAt(0);

    }
    while
        (

         repeat == 'y' || repeat == 'Y') ;

        //Print the records on screen

    { for (int i = 0; i < index; i++)
        System.out.print(anotherArray[i]);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:53:24+00:00Added an answer on May 31, 2026 at 11:53 pm

    You haven’t shown where you define the balance field but going by the fact that you are able to access it from a static methods deposit and withdraw I would guess it is itself a static variable, say

    private static double balance;
    

    Now, what does the static mean here? If you figure that out, you will know what is the error in your program, and why changing it in one object changes it in all

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're using NHibernate to update an account table with balance for a user. One
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
I need to increment User's balance, so I do: Doctrine_Query::create()->from('User')->update('balance', 'balance + 0.15')->execute(); And
I need to update a datastore entity in a way that will not be
I want to update a table: $result=mysql_query(select balance from tablename where userid='$userid)or die(mysql_error()); $row=mysql_fetch_assoc($result);
How would I write this SQL the Zend Framework way? UPDATE register SET balance
Here's the issue. I'm using ASP.NET Forms Authentication for an account balance type website.
BEGIN; UPDATE saving SET balance = balance - 100.00 WHERE name = 'Alice'; UPDATE
I have a SQLite table with a Balance field that will be used as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.