initial solutions

This commit is contained in:
2026-01-30 01:44:23 +01:00
parent 9f58e12d48
commit a732c16c12
16 changed files with 540 additions and 2 deletions
+64
View File
@@ -0,0 +1,64 @@
package oving1;
public class LineEditor {
String text = "";
int insertionIndex = 0;
LineEditor() {
}
void left() {
insertionIndex -= 1;
}
void right() {
insertionIndex += 1;
}
void insertString(String s) {
String a = text.substring(0, insertionIndex - 1);
String b = text.substring(insertionIndex, text.length());
text = a + s + b;
}
void deleteLeft() {
if (insertionIndex < 1) {
return;
}
String a = text.substring(0, insertionIndex - 2);
String b = text.substring(insertionIndex, text.length());
text = a + b;
}
void deleteRight() {
if (insertionIndex >= text.length() - 1) {
return;
}
String a = text.substring(0, insertionIndex - 1);
String b = text.substring(insertionIndex + 1, text.length());
text = a + b;
}
String getText() {
return text;
}
void setText(String s) {
text = s;
}
int getInsertionIndex() {
return insertionIndex;
}
void setInsertionIndex(int i) {
insertionIndex = i;
}
@Override
public String toString() {
String a = text.substring(0, insertionIndex - 1);
String b = text.substring(insertionIndex, text.length());
return a + "|" + b;
}
}