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 9219373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:06:08+00:00 2026-06-18T03:06:08+00:00

II am having so much trouble getting this method: A method in SmallBank named

  • 0

II am having so much trouble getting this method: A method in SmallBank named printBankDetailsthat prints out the details of the stored BankAccounts. This method should work in the case that there is only one BankAccount as well as in the case that there are two BankAccounts. You can check whether there is a value in the account2 instance variable as follows. I have no idea how to get the value of the primitive types I created, account1 and account2 then print that value. Any suggestions?

public class SmallBank
{
    private BankAccount account1;
    private BankAccount account2;

    public SmallBank(String name, int balance)
    {
        account1 = new BankAccount(name, balance);
        account2 = null;
    }

    public void addSecondAccount(BankAccount newAccount)
    {
        account2 = newAccount;
    }

    public void printBlankDetails()
    {
        account1.getDeclaredFields();
        String name = field.getName();
        Int balance = field.getBalance();
        System.out.println(b);

    }
}
  • 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-18T03:06:09+00:00Added an answer on June 18, 2026 at 3:06 am

    An alternate design is to have say printDetails() in the BankAccount class itself. Something like:

    public class BankAccount {
      String name;
      int balance;
      ...
      ...
    
      public String printDetails() {
          return (name + "/" + balance);
      }
    }
    

    and then use it in your SmallBank::printBlankDetails() method as follows:

    printBlankDetails() {
       if(account1 != null) system.out.println(account1.printDetails());
       if(account2 != null) system.out.println(account2.printDetails());
    }
    

    IMO, this approach provides better encapsulation, hides the details of BankAccount from SmallBank class.

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

Sidebar

Related Questions

I am having trouble with getting this to work I need pointed in the
I'm having trouble getting this to work. I'm writing a Vim snippet that will
I am having trouble getting a SOAP request out. I'm using generated client code
i'm having trouble getting this to work for some reason. Heres the icon sheet
I am having trouble getting this accomplished. I have one formset with 5 extra
I am having trouble getting this code to compile. I am new to MVC/Stackoverflow/programming
Having some trouble getting this to work... I basically want the report to look
I'm having some trouble getting this to work in a WPF app I'm working
ok so im having trouble getting this to work. nothing is happening. view the
I am having trouble getting this to work. I would like to trigger the

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.