Aufgabe gelöst
parent
4a0ba990b1
commit
5e587fc926
18
README.md
18
README.md
|
@ -1,18 +0,0 @@
|
|||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,29 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class Console {
|
||||
|
||||
|
||||
public static String readString() throws IOException{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
return reader.readLine();
|
||||
}
|
||||
|
||||
public static char[] readCharArray() throws IOException{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
return reader.readLine().toCharArray();
|
||||
}
|
||||
|
||||
public static boolean readBoolean() throws IOException{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
String input = reader.readLine();
|
||||
if(input.equals("true"))
|
||||
return true;
|
||||
else if(input.equals("false"))
|
||||
return false;
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
public class DemoConsole {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Text eingeben: ");
|
||||
String text = Console.readString();
|
||||
System.out.println("Gelesener Text: " + text);
|
||||
|
||||
System.out.println("Text eingeben: ");
|
||||
char [] ca = Console.readCharArray();
|
||||
System.out.println("Gelesenes char-Feld: ");
|
||||
for(char celement: ca)
|
||||
System.out.print(celement);
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Boolean eingeben: ");
|
||||
boolean b = Console.readBoolean();
|
||||
System.out.println("Gelesener Wert: " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
public class Unterzaehler extends Zaehler {
|
||||
|
||||
private int unterzaehlerstand;
|
||||
|
||||
public Unterzaehler(String zaehlerort, Verbraucher verbraucher, int unterzaehlerstand) {
|
||||
super(zaehlerort, verbraucher, unterzaehlerstand);
|
||||
this.unterzaehlerstand = unterzaehlerstand;
|
||||
}
|
||||
|
||||
public int getUnterzaehlerstand() {
|
||||
return unterzaehlerstand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unterzaehler clone() throws CloneNotSupportedException{
|
||||
return (Unterzaehler)super.clone();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
public class Verbraucher {
|
||||
|
||||
private String name;
|
||||
|
||||
public Verbraucher(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
public class Zaehler extends Object implements Cloneable {
|
||||
|
||||
private int zaehlerstand;
|
||||
private String zaehlerort;
|
||||
private Verbraucher verbraucher;
|
||||
|
||||
public Zaehler(String zaehlerort, Verbraucher verbraucher, int zaehlerstand) {
|
||||
this.zaehlerort = zaehlerort;
|
||||
this.zaehlerstand = zaehlerstand;
|
||||
this.verbraucher = verbraucher;
|
||||
}
|
||||
|
||||
public int getZaehlerstand() {
|
||||
return zaehlerstand;
|
||||
}
|
||||
|
||||
public Verbraucher getMeinVerbraucher() {
|
||||
return verbraucher;
|
||||
}
|
||||
|
||||
public String getZaehlerort() {
|
||||
return zaehlerort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zaehler clone() throws CloneNotSupportedException {
|
||||
return (Zaehler) super.clone();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
public class ZaehlerUI {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Zaehler einZaehler, klonZaehler = null;
|
||||
|
||||
Verbraucher einVerbraucher = new Verbraucher("Schulz");
|
||||
einZaehler = new Zaehler("Elektro", einVerbraucher, 123);
|
||||
|
||||
try {
|
||||
klonZaehler = einZaehler.clone();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fehler");
|
||||
}
|
||||
|
||||
System.out.println("Zählerstand =" + einZaehler.getZaehlerstand()
|
||||
+ " gehört zu Verbraucher " + einZaehler.getMeinVerbraucher().getName());
|
||||
|
||||
System.out.println("Geklonter Zähler Zählerstand = " + klonZaehler.getZaehlerstand()
|
||||
+ " gehört zu Verbraucher " + klonZaehler.getMeinVerbraucher().getName());
|
||||
|
||||
if (einZaehler.getMeinVerbraucher() == klonZaehler.getMeinVerbraucher())
|
||||
System.out.println("Verbraucher identisch");
|
||||
else
|
||||
System.out.println("Verbraucher nicht identisch");
|
||||
|
||||
Unterzaehler nochEinZaehler = new Unterzaehler("Gas", einVerbraucher, 500);
|
||||
|
||||
System.out.println("Zählerstand = " + nochEinZaehler.getZaehlerstand()
|
||||
+ " Unterzählerstand: " + nochEinZaehler.getUnterzaehlerstand()
|
||||
+ " gehört zu Verbraucher " + nochEinZaehler.getMeinVerbraucher().getName());
|
||||
|
||||
Unterzaehler klonUnterzaehler = null;
|
||||
|
||||
try {
|
||||
klonUnterzaehler = nochEinZaehler.clone();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fehler");
|
||||
}
|
||||
|
||||
System.out.println("Geklonter Unterzähler: Zählerstand = " + klonUnterzaehler.getZaehlerstand()
|
||||
+ " Unterzählerstand: " + klonUnterzaehler.getUnterzaehlerstand()
|
||||
+ " gehört zu Verbraucher " + klonUnterzaehler.getMeinVerbraucher().getName());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue