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

  • SEARCH
  • Home
  • 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 7717855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:00:40+00:00 2026-06-01T03:00:40+00:00

In my do while loop, the body works fine initially, but when it loops,

  • 0

In my do while loop, the body works fine initially, but when it loops, it prints the first two statements like it should but it does not allow me to enter the name instead it goes straight to enter pin and whatever I enter it skips the rest and asks me if I want another transaction.

I have an array object partially filed. The variables in the object are name, pin, account number and balance. When I add a new object and set the balance, the new balance I enter causes the balance for the previous objects to change as well. I think it has something to do with the balance variable being declared as static but I don’t make it static, i can the error “Cannot make a static reference to the non-static method withdraw(double) from the type CustomerRecord”. (SOLVED) Thank you.

public class BankCustomers 
{
public static void main(String[] args)

    //------------------------------------------------
    //Part4: Find a customer record from anotherArray 
    //to do transaction(s) and update the record's balance

    char repeat; // User control to repeat or quit
    Scanner keyboard = new Scanner(System.in); //creating the scanner

    String aName;
    int aPin;
    double aWithdraw;
    double aDeposit;

    do{   


        //Read customer information before search
        System.out.println();
        System.out.println("Lets make a transaction");
        System.out.println("Enter customer full name");
        aName = keyboard.nextLine( );

        System.out.println("Enter Pin");
        aPin = keyboard.nextInt();


        //Search an Array for equal aName and aPin
        for (int i = 0; i < index; i++)
        {
            CustomerRecord cRecord = anotherArray[i];
                if((cRecord.getName().equalsIgnoreCase(aName)) && (cRecord.getPin()           ==(aPin)))
                {
                    System.out.println(cRecord);

                    System.out.println("Enter Withdraw Amount");
                    aWithdraw = keyboard.nextDouble();
                    CustomerRecord.withdraw(aWithdraw);

                    System.out.println("Enter Deposite Amount");
                    aDeposit = keyboard.nextDouble();
                    CustomerRecord.deposit(aDeposit);  
                    System.out.println(cRecord);             
                }                               
        }


        System.out.println("\nAnother Transaction? (y for yes)");
        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-06-01T03:00:41+00:00Added an answer on June 1, 2026 at 3:00 am

    Your problem is twofold:

    First, balance istatic, which means it is associated with the class, not any of its instances (objects), or in other terms it is shared between all instances of that class.

    Second, as you pointed it out, your static method withdraw is accessing balance. The consideration about static applies here just as well — the method is associated with the class, and cannot access memebers that are non-static.

    To solve the second problem, remove static from the withdraw declaration (and remove static from balance as well. Thyis will make your code CustomerRecord.withdraw() not compile, becuase withdraw is now not associated with the class itself, but an instance of it. So you need to use an instance and call withdraw on that

    cRecord.withdraw(aWithdraw);
    

    Similarly for deposit

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

Sidebar

Related Questions

I wrote a while loop in a function, but don't know how to stop
I need to do a PHP while loop, but only if a variable is
How should i set a while loop counter? When is it supposed to be
While compiling a while loop without a body, I saw this message: warning: suggest
The while loop I have while reading in from a file doesn't break. I'm
I've got a while loop, that runs for many seconds and that's why I
I am using a while loop to iterate through a cursor and then outputing
I'm running a while loop reading each line in a file, and then fork
Is it a good idea to use while loop instead of a cursor? What
i am searching in a while loop for a particular character to check whether

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.