Sorry, ich bin ein Anfänger mit Java-Programmierung. Kann jemand sehen, warum mein Programm mir diese Fehlermeldungen gibt?

Die Fehlermeldung lautet:

MonthlyPhoneCostVer2.java:13: error: '.class' expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                           ^
MonthlyPhoneCostVer2.java:13: error: ';' expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                            ^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                                       ^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                                                 ^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                                                           ^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                                                                     ^
MonthlyPhoneCostVer2.java:13: error: <identifier> expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                                                                               ^
MonthlyPhoneCostVer2.java:13: error: ';' expected
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
                                                                                        ^
8 errors

Hier ist mein Code:

import javax.swing.*;
public class MonthlyPhoneCostVer2{
public static void main (String [] args){
double a = 2.50; // cost/min for day call
double b = 0.55; // cost/min for evening and weekend calls
double c = 50; // static monthly subscription cost
double d = 0.60; // cost for opening a phone call . cant have ',' in value
double x = Integer.parseInt(JOptionPane.showInputDialog(null, "Number of Phone Calls?"));
double y = Integer.parseInt(JOptionPane.showInputDialog(null, "Minutes of day calls"));
double z = Integer.parseInt(JOptionPane.showInputDialog(null, "Minutes of evening weekend calls"));
double res = isCost(double a, double b, double c, double d, double x, double y, double z);
JOptionPane.showMessageDialog(null, "Your Total Cost of Phone Fees is: " + res);
}
public static double isCost(double a, double b, double c, double d, double x, double y, double z){
return ((x*d) + (y*a) + (z*b) + c);
}
}
0
Zerenity 23 Feb. 2020 im 23:33

3 Antworten

Beste Antwort

Ihr Methodenaufruf an isCost hat die Syntax . Dies

double res = isCost(double a, double b, double c, double d, double x, double y, double z);

Sollte sein

double res = isCost(a, b, c, d, x, y, z);

Mir ist nicht klar, warum Sie die Typinformationen (erneut) vom Anrufer hinzufügen mussten, aber das ist einfach nicht korrekt.

1
Elliott Frisch 23 Feb. 2020 im 20:36
import javax.swing.*;

public class MonthlyPhoneCostVer2 
{
    public static void main (String [] args) 
    {
        double a = 2.50; // cost/min for day call
        double b = 0.55; // cost/min for evening and weekend calls
        double c = 50; // static monthly subscription cost
        double d = 0.60; // cost for opening a phone call . cant have ',' in value
        double x = Integer.parseInt(JOptionPane.showInputDialog(null, "Number of Phone Calls?"));
        double y = Integer.parseInt(JOptionPane.showInputDialog(null, "Minutes of day calls"));
        double z = Integer.parseInt(JOptionPane.showInputDialog(null, "Minutes of evening weekend calls"));
        double res = isCost(a,b,c,d,x,y,z);
        JOptionPane.showMessageDialog(null, "Your Total Cost of Phone Fees is: " + res);
    }

    public static double isCost(double a, double b, double c, double d, double x, double y, double z) 
    {
        return ((x*d) + (y*a) + (z*b) + c);
    }
}

Die Doppelvariablen wurden bereits definiert. Es ist also nicht erforderlich, die Variablen innerhalb der Funktion zu definieren.

0
Costantino Grana 24 Feb. 2020 im 02:39

Verwenden

double res = isCost(a, b,  c, d, x, y, z);
0
Sunil Lama 23 Feb. 2020 im 20:37