Hallo, ich möchte in diesem Programm die Duplikationen in der main-Methode entfernen oder zusammenfassen (in einer Methode). Der zugehörige Programmcode lautet:
Mein bisheriger Weg war es, die Eingaben im Terminal in der main-Methode zu lassen und die Berechnungen in der int-Methode zu machen:
Jedoch erhalte ich die Fehlermeldung:
input = Terminal.askInt("Enter next value: ");
^
symbol: variable Terminal
location: class Duplicate
/tmp/dfSpLSTmmU/Duplicate.java:13: error: cannot find symbol
int tmp = ((1.01 * x + 1.77 * (y - 10) + 1.22 * input)/3);
^
symbol: variable input
location: class Duplicate
/tmp/dfSpLSTmmU/Duplicate.java:14: error: variable tmp is already defined in method getInput(String[])
int tmp = (int)((1.01 * tmp + 1.77 * (tmp - 10) + 1.22 * input)/3);
^
/tmp/dfSpLSTmmU/Duplicate.java:14: error: cannot find symbol
int tmp = (int)((1.01 * tmp + 1.77 * (tmp - 10) + 1.22 * input)/3);
^
symbol: variable input
location: class Duplicate
4 errors
Ich weiß nicht, wie ich diese Fehler korrigieren kann. Für jede Hilfe dabei wäre ich gerne dankbar.
Java:
public class Duplicate{
public static void main(String[] args) {
int x = 50, y = 30, tmp = 0, input = 0;
input = Terminal.askInt("Enter next value: ");
System.out.println ("Your choice was: " + input + ". Well done!");
tmp = (int)((1.01 * x + 1.77 * (y - 10) + 1.22 * input)/3);
input = Terminal.askInt("Enter next value: ");
System.out.println ("Your choice was: " + input + ". Well done!");
tmp = (int)((1.01 * x + 1.77 * (tmp - 10) + 1.22 * input)/3);
input = Terminal.askInt("Enter next value: ");
System.out.println ("Your choice was: " + input + ". Well done!");
tmp = (int)((1.01 * tmp + 1.77 * (tmp - 10) + 1.22 * input)/3);
System.out.println( "Result: " + tmp);
}
public static int getInput() {
}
public static int calc(int a, int b, int c) {
}
}
Mein bisheriger Weg war es, die Eingaben im Terminal in der main-Methode zu lassen und die Berechnungen in der int-Methode zu machen:
Code:
public class Duplicate{
public static void main(String[] args) {
int x = 50, y = 30, tmp = 0, input = 0;
input = Terminal.askInt("Enter next value: ");
System.out.println ("Your choice was: " + input + ". Well done!");
System.out.println( "Result: " + tmp);
}
public static int getInput(String[] args) {
int x = 50 ;
int y = 30 ;
int tmp = ((1.01 * x + 1.77 * (y - 10) + 1.22 * input)/3);
int tmp = (int)((1.01 * tmp + 1.77 * (tmp - 10) + 1.22 * input)/3);
return tmp;
}
public static int calc(int a, int b, int c) {
}
}
Jedoch erhalte ich die Fehlermeldung:
input = Terminal.askInt("Enter next value: ");
^
symbol: variable Terminal
location: class Duplicate
/tmp/dfSpLSTmmU/Duplicate.java:13: error: cannot find symbol
int tmp = ((1.01 * x + 1.77 * (y - 10) + 1.22 * input)/3);
^
symbol: variable input
location: class Duplicate
/tmp/dfSpLSTmmU/Duplicate.java:14: error: variable tmp is already defined in method getInput(String[])
int tmp = (int)((1.01 * tmp + 1.77 * (tmp - 10) + 1.22 * input)/3);
^
/tmp/dfSpLSTmmU/Duplicate.java:14: error: cannot find symbol
int tmp = (int)((1.01 * tmp + 1.77 * (tmp - 10) + 1.22 * input)/3);
^
symbol: variable input
location: class Duplicate
4 errors
Ich weiß nicht, wie ich diese Fehler korrigieren kann. Für jede Hilfe dabei wäre ich gerne dankbar.