test2
parent
0fc4ce06d7
commit
24ee1c110d
|
@ -6,5 +6,6 @@
|
|||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import java.io.*;
|
||||
|
||||
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,74 @@
|
|||
package Uebung2;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class Ag2_Junit {
|
||||
|
||||
private final InputStream systemIn = System.in;
|
||||
private ByteArrayInputStream testIn;
|
||||
private Scanner scanner;
|
||||
|
||||
@Before
|
||||
public void setUpInput() {
|
||||
scanner = new Scanner(System.in);
|
||||
System.setIn(testIn);
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreSystemInputOutput() {
|
||||
System.setIn(systemIn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextInput() {
|
||||
String input = "Test Text";
|
||||
testIn = new ByteArrayInputStream(input.getBytes());
|
||||
System.setIn(testIn);
|
||||
|
||||
assertEquals("Test Text", scanner.nextLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharInput() {
|
||||
String input = "Char Input";
|
||||
testIn = new ByteArrayInputStream(input.getBytes());
|
||||
System.setIn(testIn);
|
||||
|
||||
char[] expectedCharArray = input.toCharArray();
|
||||
assertArrayEquals(expectedCharArray, scanner.nextLine().toCharArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanInput() {
|
||||
String input = "true";
|
||||
testIn = new ByteArrayInputStream(input.getBytes());
|
||||
System.setIn(testIn);
|
||||
|
||||
assertTrue(scanner.nextBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidBooleanInput() {
|
||||
String input = "not a boolean";
|
||||
testIn = new ByteArrayInputStream(input.getBytes());
|
||||
System.setIn(testIn);
|
||||
|
||||
assertFalse(scanner.nextBoolean());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package Uebung2;
|
||||
import java.io.Console;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Uebung2_Ag2 {
|
||||
public static void main(String [] args) {
|
||||
|
||||
Scanner input = new Scanner (System.in);
|
||||
|
||||
System.out.println("Text eingeben: ");
|
||||
String text = input.nextLine();
|
||||
System.out.println("Gelesener text " + text);
|
||||
|
||||
System.out.println("Text eingeben: ");
|
||||
char [] ca = input.next().toCharArray();
|
||||
System.out.println("Gelesenes char-Feld: ");
|
||||
for(char celement: ca)
|
||||
System.out.print(celement);
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Boolean eingeben: ");
|
||||
boolean b = input.nextBoolean();
|
||||
System.out.println("Gelesener Wert: " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package Uebung2;
|
||||
|
||||
public class Unterzaehler extends Zaehler {
|
||||
|
||||
private int unterzaehlerStand;
|
||||
|
||||
public Unterzaehler(String art, Verbraucher meinVerbraucher, int zaehlerStand) {
|
||||
super(art, meinVerbraucher, zaehlerStand);
|
||||
this.unterzaehlerStand = unterzaehlerStand;
|
||||
}
|
||||
|
||||
protected Unterzaehler clone() throws CloneNotSupportedException{
|
||||
return (Unterzaehler) super.clone();
|
||||
|
||||
}
|
||||
|
||||
public int getUnterzaehlerstand() {
|
||||
return unterzaehlerStand;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package Uebung2;
|
||||
|
||||
public class Verbraucher {
|
||||
|
||||
private String name;
|
||||
|
||||
public Verbraucher (String name2) {
|
||||
this.name = name2;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package Uebung2;
|
||||
|
||||
public class Zaehler extends Object implements Cloneable {
|
||||
|
||||
private String art;
|
||||
private int zaehlerStand;
|
||||
private Verbraucher meinVerbraucher;
|
||||
|
||||
public Zaehler(String art, Verbraucher meinVerbraucher, int zaehlerStand) {
|
||||
this.meinVerbraucher = meinVerbraucher;
|
||||
this.art = art;
|
||||
this.zaehlerStand = zaehlerStand;
|
||||
}
|
||||
|
||||
public int getZaehlerstand() {
|
||||
return zaehlerStand;
|
||||
}
|
||||
|
||||
public void setZaehlerstand(int zaehlerStand) {
|
||||
this.zaehlerStand = zaehlerStand;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Zaehler clone() throws CloneNotSupportedException {
|
||||
|
||||
return (Zaehler) super.clone();
|
||||
}
|
||||
|
||||
public Verbraucher getMeinVerbraucher() {
|
||||
return meinVerbraucher;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package Uebung2;
|
||||
|
||||
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(CloneNotSupportedException 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(CloneNotSupportedException 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());
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
|
||||
public class Uebung_1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int blz;
|
||||
System.out.println(blz);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package verwaltung.kunden;
|
||||
|
||||
public class DemoKonsole {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue