Mathias E.

asked • 07/10/21

Why the output is Error : class interest is public, should be declared in a file named Interest.java?

public class Interest {

public static void main(String[] args) {

/* Declare the variables. */

double principal; // The value of the investment.

double rate; // The annual interest rate.

double interest; // Interest earned in one year.

/* Do the computations. */

principal = 17000;

rate = 0.07;

interest = principal * rate; // Compute the interest.

principal = principal + interest;

// Compute value of investment after one year, with interest.

// (Note: The new value replaces the old value of principal.)

/* Output the results. */

System.out.print("The interest earned is $");

System.out.println(interest);

System.out.print("The value of the investment after one year is $");

System.out.println(principal);

} // end of main()

} // end of class Interest



Why it was producing error when I run the code in my interpreter?


Error : class interest is public, should be declared in a file named Interest.java




1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.