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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:15:21+00:00 2026-06-15T23:15:21+00:00

I’m trying to return an object in this static method: public static Account Consolidate(Account

  • 0

I’m trying to return an object in this static method:

public static Account Consolidate(Account acct1, Account acct2){
        String name1 = acct1.getName();
        String name2 = acct2.getName();
        double acctNum1 = acct1.getAcctNumber();
        double acctNum2 = acct2.getAcctNumber();
        double balance1 = acct1.getBalance();
        double balance2 = acct2.getBalance();
        double balance3;
        Account acct3 = new Account(name1);

        if ((name1.equalsIgnoreCase(name2)) &&  (acctNum1 != acctNum2)){
            balance3 = balance1 + balance2;
            acct1.close();
            acct2.close();              
            System.out.println("Consolidation successful!");        
            return (acct3);                     
        }
        else 
             System.out.println("These accounts cannot be consolidated.");          
             return null;
        }

But it returns nothing and I’m not sure how to fix it. As in,

Here’s the driver program:

    import java.util.Scanner;

public class Consolidates{
    public static void main(String[] args){
    String name1;
    String name2;
    String name3;

    Scanner scan = new Scanner(System.in);

    System.out.println("Enter the name of the first account holder");
    name1 = scan.next();
    System.out.println("Enter the name of the second account holder");
    name2 = scan.next();
    System.out.println("Enter the name of the third account holder");
    name3 = scan.next();
    System.out.println();
    Account acct1 = new Account(100, name1, 333333);
    Account acct2 = new Account(100, name2, 555555);
    Account acct3 = new Account(100, name3, 777777);
    System.out.println(acct1);
    System.out.println(acct2);
    System.out.println(acct3);
    System.out.println();
    System.out.println("Closing account 1...");
    System.out.println();
    acct1.close();  
    System.out.println();
    System.out.println("Attempting to consolidate accounts 2 and 3...");
    Account.Consolidate(acct2, acct3);
    System.out.println();
    System.out.println("Printing original 3 accounts");
    System.out.println(acct1);
    System.out.println(acct2);
    System.out.println(acct3);
    }
}

Finally, here is the output:

Enter the name of the first account holder
rick
Enter the name of the second account holder
james
Enter the name of the third account holder
james

Name: rick
Account Number: 333333
Balance: 100.0
Name: james
Account Number: 555555
Balance: 100.0
Name: james
Account Number: 777777
Balance: 100.0

Closing account 1...


Attempting to consolidate accounts 2 and 3...
Consolidation successful!

Printing original 3 accounts
Name: CLOSED
Account Number: 333333
Balance: 0.0
Name: CLOSED
Account Number: 555555
Balance: 0.0
Name: CLOSED
Account Number: 777777
Balance: 0.0

As you can see, it does print the consolidation successful message indicating it goes through the loop correctly, it just isn’t returning the account summary.

  • 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-15T23:15:22+00:00Added an answer on June 15, 2026 at 11:15 pm

    You never actually do anything with the return value:

    Account.Consolidate(acct2, acct3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.