Das gesamte Programm soll ein Kombinationsschloss eingeben und das Combo akzeptieren. Dies ist der Code, mit dem ich Probleme habe.Mehrere Fehler für Bezeichner erwartet und illegaler Start des Typs. Confused
import java.util.*; // needed for Scanner
public class CombinationLock extends Lock
{
// Instance Variables
private String combination;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Combination --> ");
String combo = keyboard.nextLine();
if(combination = combo)
{
super.open();
}
public String toString()
{
String str = super.toString() + "\n" +
"Combination = " + combination + "\n";
return str;
}
public void setCombination()
{
}
public boolean getCombination()
{
}
public CombinationLock()
{
super(); // call the default constructor of the Lock class
combination = "";
}
public CombinationLock(String combo)
{
super();
combination = combo;
}
}
Dies sind die Fehler, die ich bin
--------------------Configuration: <Default>--------------------
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:10: error: <identifier> expected
System.out.println("Enter Combination ");
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:10: error: illegal start of type
System.out.println("Enter Combination ");
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:13: error: illegal start of type
if(combination = combo)
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:13: error: <identifier> expected
if(combination = combo)
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:13: error: ';' expected
if(combination = combo)
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:13: error: illegal start of type
if(combination = combo)
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:13: error: <identifier> expected
if(combination = combo)
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:14: error: ';' expected
{
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:15: error: illegal start of type
super.open();
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:18: error: class, interface, or enum expected
public String toString()
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:22: error: class, interface, or enum expected
return str;
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:23: error: class, interface, or enum expected
}
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:25: error: class, interface, or enum expected
public void setCombination()
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:30: error: class, interface, or enum expected
public boolean getCombination()
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:35: error: class, interface, or enum expected
public CombinationLock()
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:38: error: class, interface, or enum expected
combination = "";
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:39: error: class, interface, or enum expected
}
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:41: error: class, interface, or enum expected
public CombinationLock(String combo)
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:44: error: class, interface, or enum expected
combination = combo;
^
C:\Users\waki_\OneDrive\Documents\CombinationLock.java:45: error: class, interface, or enum expected
}
^
20 errors
Process completed.
immer ich bin mir nicht sicher, was das Problem verursacht. Ich habe versucht, andere Antworten zu finden, aber keine von ihnen war relevant für mein Problem.
Ihr Code ** ist nicht ** in einer Methode oder einem Initialisierungsblock. –