diff --git a/README.md b/README.md deleted file mode 100644 index 7c03a53..0000000 --- a/README.md +++ /dev/null @@ -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). diff --git a/bin/Console.class b/bin/Console.class new file mode 100644 index 0000000..f79a595 Binary files /dev/null and b/bin/Console.class differ diff --git a/bin/DemoConsole.class b/bin/DemoConsole.class new file mode 100644 index 0000000..68526c7 Binary files /dev/null and b/bin/DemoConsole.class differ diff --git a/bin/Unterzaehler.class b/bin/Unterzaehler.class new file mode 100644 index 0000000..43c7d02 Binary files /dev/null and b/bin/Unterzaehler.class differ diff --git a/bin/Verbraucher.class b/bin/Verbraucher.class new file mode 100644 index 0000000..0aa4c2e Binary files /dev/null and b/bin/Verbraucher.class differ diff --git a/bin/Zaehler.class b/bin/Zaehler.class new file mode 100644 index 0000000..44a1f66 Binary files /dev/null and b/bin/Zaehler.class differ diff --git a/bin/ZaehlerUI.class b/bin/ZaehlerUI.class new file mode 100644 index 0000000..396fcf9 Binary files /dev/null and b/bin/ZaehlerUI.class differ diff --git a/src/Console.java b/src/Console.java new file mode 100644 index 0000000..0d35cae --- /dev/null +++ b/src/Console.java @@ -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(); + } + +} diff --git a/src/DemoConsole.java b/src/DemoConsole.java new file mode 100644 index 0000000..d634274 --- /dev/null +++ b/src/DemoConsole.java @@ -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); + } +} diff --git a/src/Unterzaehler.java b/src/Unterzaehler.java new file mode 100644 index 0000000..844724d --- /dev/null +++ b/src/Unterzaehler.java @@ -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(); + } + + + +} diff --git a/src/Verbraucher.java b/src/Verbraucher.java new file mode 100644 index 0000000..8e3b9e9 --- /dev/null +++ b/src/Verbraucher.java @@ -0,0 +1,13 @@ +public class Verbraucher { + + private String name; + + public Verbraucher(String name) { + this.name = name; + } + + public String getName() { + return name; + } + +} diff --git a/src/Zaehler.java b/src/Zaehler.java new file mode 100644 index 0000000..6cb1a2c --- /dev/null +++ b/src/Zaehler.java @@ -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(); + } + +} diff --git a/src/ZaehlerUI.java b/src/ZaehlerUI.java new file mode 100644 index 0000000..17c964e --- /dev/null +++ b/src/ZaehlerUI.java @@ -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()); + } +}