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

View File

@@ -0,0 +1,4 @@
package oving1;
public class Account {
}

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;
}
}

View File

@@ -0,0 +1,4 @@
package oving1;
public class Location {
}

View File

@@ -0,0 +1,6 @@
// class Main {
// public static void main(String[] args) {
// System.out.println("Hello, World!");
// LineEditor line_editor = new LineEditor("test", 0);
// }
// }

View File

@@ -0,0 +1,87 @@
package oving1;
public class Rectangle {
int x1;
int y1;
int x2;
int y2;
public Rectangle(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
int getMinX() {
return Math.min(x1, x2);
}
int getMinY() {
return Math.min(y1, y2);
}
int getMaxX() {
return Math.max(x1, x2);
}
int getMaxY() {
return Math.max(y1, y2);
}
int getWidth() {
return getMaxX() - getMinX();
}
int getHeight() {
return getMaxY() - getMinY();
}
boolean isEmpty() {
return getWidth() == 0 || getHeight() == 0;
}
boolean contains(int x, int y) {
return x >= getMinX() && x <= getMaxX() && y >= getMinY() && y <= getMaxY();
}
boolean contains(Rectangle rect) {
return contains(rect.x1, rect.y1) && contains(rect.x2, rect.y1) && contains(rect.x1, rect.y2)
&& contains(rect.x2, rect.y2);
}
boolean add(int x, int y) {
int px1 = x1;
int px2 = x2;
int py1 = y1;
int py2 = y2;
x1 = Math.min(x, x1);
x2 = Math.max(x, x2);
y1 = Math.min(y, y1);
y2 = Math.max(y, y2);
return px1 == x1 && px2 == x2 && py1 == y1 && py2 == y2;
}
boolean add(Rectangle rect) {
return add(rect.x1, rect.y1) || add(rect.x2, rect.y1) || add(rect.x1, rect.y2) || add(rect.x2, rect.y2);
}
Rectangle union(Rectangle rect) {
int px1 = x1;
int px2 = x2;
int py1 = y1;
int py2 = y2;
add(rect);
Rectangle r = new Rectangle(x1, y1, x2, y2);
x1 = px1;
x2 = px2;
y1 = py1;
y2 = py2;
return r;
}
@Override
public String toString() {
return "";
}
}

View File

@@ -0,0 +1,63 @@
package oving1;
public class StopWatch {
boolean active = false;
int time = 0;
int ticks = 0;
int lapTime = 0;
int lap = 0;
int lastLapTime = -1;
public StopWatch() {
}
boolean isStarted() {
return active;
}
boolean isStopped() {
return !active;
}
int getTicks() {
return ticks;
}
int getTime() {
return time;
}
int getLapTime() {
return lapTime;
}
int getLastLapTime() {
return lastLapTime;
}
void tick(int ticks) {
this.ticks += ticks;
if (isStopped()) {
return;
}
}
void start() {
active = true;
}
void lap() {
lap += 1;
lastLapTime = lapTime;
lapTime = 0;
}
void stop() {
active = false;
}
@Override
public String toString() {
return "";
}
}

View File

@@ -0,0 +1,4 @@
package oving1;
public class UpOrDownCounter {
}