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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:19:49+00:00 2026-05-26T11:19:49+00:00

public class Balance { public static void main(String[] args) { System.out.printf(%.2f\n, balance(0.0, 0.0, 0.0));

  • 0
public class Balance {
public static void main(String[] args) {
    System.out.printf("%.2f\n", balance(0.0, 0.0, 0.0));
}
/**
 * @param principal
 * @param rate
 * @param years
 * @return
 */
public static double balance(double principal, double rate, double years) {
    double amount = 0;
    Scanner sc = new Scanner(System.in);

    System.out.print("Enter the initial investment amount: ");
    principal = sc.nextDouble();

    System.out.print("Enter the interest rate: ");
    rate = sc.nextDouble();

    System.out.print("Enter the number of years: ");
    years = sc.nextDouble();

    for (int i = 1; i < years; i++) {
        amount = principal * Math.pow(1.0 + rate, years);
        amount += principal;
    }
    return amount - principal;

}
}

My problem is with the printf line that I am using within the main method. Eclipse wants me to change the method balance from void to Object[]. When I do this I must return a value from balance. So I guess my question is, how would I return the proper value? Am I on the right track? Thank you for your time and constructive criticism. 🙂

EDIT – Thanks for the help everyone, much appreciated 🙂 My math is off. I end up with 1000 more than I should have. hmmm.

So should I just take a 1000 from amount like so:

return amount - 1000;

Or this:

return amount - principal;

EDIT this is what I am going with since it is due tonight. Thanks to all for the assistance. 🙂

  • 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-26T11:19:49+00:00Added an answer on May 26, 2026 at 11:19 am

    A few points:

    • balance() cannot be void, because you use its return value in S.out.printf(). Do you want balance to print to the screen, or do you want it to yield a number?

    • Your loop for (years = 0; years > 10; years++) won’t run. Think about why. It might help to convert the for into a while, to visualize why.

    • You read in years as a double, but then use it as a counter in your loop. What type should it actually be?

    • Your balance() function takes three parameters, then immediately gets input and obliterates them. Do you want balance() to be provided these numbers, or do you want it to fetch them?

    Otherwise, you seem to be on the right track.

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

Sidebar

Related Questions

public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
public class Main3 { public static void main(String[] args) { Integer min = Integer.MIN_VALUE;
public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);
public class MyClass { public int Age; public int ID; } public void MyMethod()
public class Address { public string ZipCode {get; set;} } public class Customer {
public class CovariantTest { public A getObj() { return new A(); } public static
package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;
Here's my Class that I'm grouping: public class RefundTran : DataObjectBase<RefundTran> { public string

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.