A
Asinus
Gast
Hi alle miteinander.
Ich habe ein wirklich großes Problem:cry:; für eine Aufgabe habe ich folgende Aufgabenstellung:
"Implementieren Sie einen Line Editor der das Interface EditorOperations und die Mitgelieferten Operationen verwendet. Die zu implementierende Klasse LineEditor soll von AbstractLineEditor abgeleitet sein."
Ich habe die zwei Klassen mitgeliefert bekommen, und weiss jetzt wriklich nicht, was ich machen soll. Ich poste hier mal die Codes und hoffe, dass mir jemand helfen kann
import java.util.List;
Ich habe ein wirklich großes Problem:cry:; für eine Aufgabe habe ich folgende Aufgabenstellung:
"Implementieren Sie einen Line Editor der das Interface EditorOperations und die Mitgelieferten Operationen verwendet. Die zu implementierende Klasse LineEditor soll von AbstractLineEditor abgeleitet sein."
Ich habe die zwei Klassen mitgeliefert bekommen, und weiss jetzt wriklich nicht, was ich machen soll. Ich poste hier mal die Codes und hoffe, dass mir jemand helfen kann
import java.util.List;
Code:
import java.util.List;
public interface EditorOperation
{
String getCommand();
int getParamCount();
String execute (String input,List params) throws EprogEditorException;
}
Code:
import java.util.*;
public abstract class AbstractEditor
{
private Map ops=new HashMap();
public AbstractEditor()
{
registerOperations();
}
public void addOperation (EditorOperation op)
{
ops.put(op.getCommand(),op);
}
public EditorOperation getOperation(String command) throws Exception
{
if(!ops.containsKey(command))
throw new Exception("command '"+command+"' not found");
return (EditorOperation)ops.get(command);
}
protected abstract void registerOperations();
protected abstract String readWord();
public abstract String run (String input) throws Exception;
}
Code:
import eprog.*;
public class EprogLineEditor extends LineEditor
{
protected void registerOperations()
{
addOperation(new InsertOperation());
addOperation(new LowerOperation());
addOperation(new RemoveOperation());
addOperation(new ReverseOperation());
addOperation(new SubOperation());
addOperation(new SubstOperation());
addOperation(new UpperOperation());
}
protected String readWord()
{
try
{
return EprogIO.readWord();
}
catch(EprogEOFException ex)
{
return null;
}
}
public static void main (String [] args)
{
AbstractEditor e=new EprogLineEditor();
try
{
EprogIO.println(e.run(EprogIO.readWord()));
}
catch(Exception ex)
{
ex.printStackTrace();
EprogIO.println("?");
}
}
}