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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:00:50+00:00 2026-06-17T18:00:50+00:00

I am getting an error trying to code a program which calculates interest on

  • 0

I am getting an error trying to code a program which calculates interest on a loan, and displays information back with certain decimal positions. I need the loanInterest to display at 3.546%, or something like that with 3 decimal places. I was able to get the totalInterest to display properly, but I dont know if this is because it was a new value I just established. When I try to run my program as seen below, I get a “float cannot be dereferenced” error.

public class SarahShelmidineModule2Project {

public static void main(String[] args) {
    //Being programing for Module 2 project

    // Welcome the user to the program
    System.out.println("Welcome to the Interest Calculator");
    System.out.println();  // print a blank line

    // create a Scanner object named sc
    Scanner sc = new Scanner(System.in);

    // perform interest calculations until choice isn't equal to "y" or "Y"
    String choice = "y";
    while (choice.equalsIgnoreCase("y"))
    {
        // get info from user on loan amount and interest rates and store data
        System.out.print("Enter loan amount:   ");
        double loanAmount = sc.nextDouble();
        System.out.print("Enter interest rate:   ");
        float loanInterest = sc.nextFloat();


        // calculate the interest and convert to BigDecimal and rounding for totalInterest

       BigDecimal decimalloanAmount = new BigDecimal (Double.toString(loanAmount));
       BigDecimal decimalloanInterest = new BigDecimal (Double.toString(loanInterest));
       BigDecimal totalInterest = decimalloanAmount.multiply(decimalloanInterest);
       totalInterest = totalInterest.setScale(2, RoundingMode.HALF_UP);

       loanInterest = loanInterest.setScale(3, RoundingMode.HALF_UP);

        System.out.println();  // print a blank line

        // display the loan amount, loan interest rate, and interest
        // also format results to percent and currency
        NumberFormat currency = NumberFormat.getCurrencyInstance();
        NumberFormat percent = NumberFormat.getPercentInstance();

        String message =    "Loan amount: " + currency.format(loanAmount) + "\n"
                +           "Interest rate:  " + percent.format(loanInterest) + "\n"
                +           "Intrest:    " + currency.format(totalInterest) + "\n";
        System.out.println(message);

        // inquire if user would like to continue with application
        System.out.print("Continue? (y/n): ");
        choice = sc.next();
        System.out.println();

Below is the error I get when I run this:

Welcome to the Interest Calculator

Enter loan amount: 10932

Enter interest rate: .0934

Exception in thread "main" java.lang.RuntimeException: Uncompilable
source code - Erroneous sym type: <any>     at
 sarahshelmidinemodule2project.SarahShelmidineModule2Project.main(SarahShelmidineModule2Project.java:45)
  • 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-17T18:00:51+00:00Added an answer on June 17, 2026 at 6:00 pm

    Just change

    float loanInterest = sc.nextFloat();

    with

    BigDecimal loanInterest = new BigDecimal(sc.nextFloat());

    and you will resolve “float cannot be derefenced” since float is a primitive type and has not method setScale.

    About printing right number of decimals, use something like this:

        String currencySymbol = Currency.getInstance(Locale.getDefault()).getSymbol();
        System.out.printf("%s%8.5f\n", currencySymbol, totalInterest);
    

    This code will use 5 decimals, but be sure that your BigDecimal scale is at least 5, otherwise you will get not significant zeros.

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

Sidebar

Related Questions

I am getting error trying to run my asp code for executing stored proc.
I'm trying to code some stuff for a game but I keep getting error
hi im new to c# and was trying to code but getting error can
I am getting an error while trying to run CFmx code on a remote
I keep getting this error while trying to modify some tables. Here's my code:
I am getting the following error when trying to check in my code: $>
I'm getting an error in my python code when trying to import one of
I am trying to update code via Linq, but I am getting this error:
I am trying to compile the following code and i am getting the error:
I'm trying to compile the next code, but I'm getting this error on 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.