PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

[FIXED] What causes error "error: '.class' expected"?

 June 26, 2022     compiler-errors, java, joptionpane, swing     No comments   

Issue

Please help me solve these errors.
These are the errors I'm getting after I have executed the java codes below.

/Deposit.java:15: error: '.class' expected
    double results=presentValue(double f, double r ,int n);
                                       ^
/Deposit.java:15: error: ';' expected
    double results=presentValue(double f, double r ,int n);
                                        ^
/Deposit.java:15: error: <identifier> expected
    double results=presentValue(double f, double r ,int n);
                                                    ^
/Deposit.java:15: error: ';' expected
    double results=presentValue(double f, double r ,int n);
                                                         ^
4 errors

import javax.swing.JOptionPane;

/*This program computes a customers present
deposit to make to obtain a desired future
value
*/
public class Deposit
{
  //Main method
  public static void main(String[] args)
  {

    //Calling the present value method
    double results=presentValue(double f, double r ,int n);

    //Displaying the present value 
    JOptionPane.showMessageDialog(null, "You have to deposit: $" +results);
  }

  public static double presentValue(double f, double r, int n)
  {
    //Declaring the input variable
    String input;

    //Taking inputs from the customer
    //Future value
    input = JOptionPane.showInputDialog("Enter your desired future value:");
    f = Double.parseDouble(input);

    //Annual Interest Rate
    input = JOptionPane.showInputDialog("Enter the annual interest rate:");
    r = Double.parseDouble(input);

    //Number of years
    input = JOptionPane.showInputDialog("Enter the number of years:");
    n = Integer.parseInt(input);

    //Calculating the present value the customer has to deposit
    double p = f/Math.pow((1+r), n);

    //Returning the value to the present value method
    return p;

    System.exit(0);
  }
}

Solution

Go with function without arguments, since yours doesn't do anything.

public class Deposit
{
  //Main method
  public static void main(String[] args)
  {
    double results=presentValue();
    ... // same code
  }

  public static double presentValue()
  {
    double f,r;
    int n;
    ... // same code
  }
}


Answered By - sittsering
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing