15.04 Labor
parent
24ee1c110d
commit
4a0a222452
|
@ -0,0 +1,29 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
public class Console {
|
||||||
|
|
||||||
|
private static Scanner input;
|
||||||
|
|
||||||
|
private Console() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public static String readString() {
|
||||||
|
|
||||||
|
System.out.println("Text eingeben: ");
|
||||||
|
String text = input.nextLine();
|
||||||
|
return "Gelesener Text" + text;
|
||||||
|
}
|
||||||
|
public static char[] readCharArray(){
|
||||||
|
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();
|
||||||
|
return ca;
|
||||||
|
}
|
||||||
|
public static boolean readBoolean() {
|
||||||
|
System.out.println("Boolean eingeben: ");
|
||||||
|
boolean b = input.nextBoolean();
|
||||||
|
return b ;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package InOutPut_Fortsetzung;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Buchungen {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
int buchungsNummer = 0;
|
||||||
|
|
||||||
|
String buchungsKonto;
|
||||||
|
double buchungsBetrag = 0;
|
||||||
|
|
||||||
|
int wertUnter = 0;
|
||||||
|
int wertUeber = 0;
|
||||||
|
ArrayList <String> werteListe = new ArrayList <> ();
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new FileReader("src/InOutPut_Fortsetzung/buchungen.text"));
|
||||||
|
String zeile = reader.readLine();
|
||||||
|
|
||||||
|
while (zeile != null) {
|
||||||
|
String [] wert = zeile.split(" ");
|
||||||
|
zeile = reader.readLine();
|
||||||
|
System.out.println(zeile);
|
||||||
|
|
||||||
|
for(String w : wert) {
|
||||||
|
werteListe.add(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (wertUnter < 1000) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
1 22.03.2024 "Einzahlung" 1000.00
|
||||||
|
2 22.03.2024 "Einzahlung" 50.00
|
||||||
|
3 23.03.2024 "Einkauf Edeka" -45.45
|
||||||
|
4 24.03.2024 "Gehalt" 1200.00
|
||||||
|
5 31.03.2024 "Mietzins Wohnung" -1100.00
|
||||||
|
6 31.03.2024 "Nebenkostenpauschale Wohnung" -250.00
|
||||||
|
7 04.04.2024 "Einkauf Netto" 42.02
|
|
@ -0,0 +1,96 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Alien.
|
||||||
|
*/
|
||||||
|
public class Alien implements Cloneable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name des Aliens.
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raumanzug des Aliens.
|
||||||
|
*/
|
||||||
|
private Raumanzug raumanzug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erzeugt ein neues Alien.
|
||||||
|
*
|
||||||
|
* @param name Name des Aliens.
|
||||||
|
* @param raumanzug Anzug.
|
||||||
|
*/
|
||||||
|
public Alien(String name, Raumanzug raumanzug) {
|
||||||
|
this.name = name;
|
||||||
|
this.raumanzug = raumanzug;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt den Namen des Aliens zurück.
|
||||||
|
*
|
||||||
|
* @return Name des Aliens.
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt den Anzug zurück.
|
||||||
|
*
|
||||||
|
* @return der Anzug.
|
||||||
|
*/
|
||||||
|
public Raumanzug getAnzug() {
|
||||||
|
return raumanzug;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
result = prime * result + ((raumanzug == null) ? 0 : raumanzug.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Alien other = (Alien) obj;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!name.equals(other.name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (raumanzug == null) {
|
||||||
|
return other.raumanzug == null;
|
||||||
|
} else {
|
||||||
|
return raumanzug.equals(other.raumanzug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Alien clone() throws CloneNotSupportedException {
|
||||||
|
Alien alien1 = (Alien) super.clone();
|
||||||
|
alien1.raumanzug = (Raumanzug) super.clone();
|
||||||
|
|
||||||
|
return alien1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test für die Clone-Methoden.
|
||||||
|
*/
|
||||||
|
public class AlienCloneTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test-Methode.
|
||||||
|
*
|
||||||
|
* @throws CloneNotSupportedException wird geworfen, wenn clone_alien nicht
|
||||||
|
* korrekt implementiert wurde.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testClone() throws CloneNotSupportedException {
|
||||||
|
// TODO: Einkommentieren (strg+shift+c)
|
||||||
|
Raumanzug r1 = new Raumanzug();
|
||||||
|
Alien a1 = new Alien("Predator", r1);
|
||||||
|
|
||||||
|
Alien a2 = (Alien) a1.clone();
|
||||||
|
Raumanzug r2 = a2.getAnzug();
|
||||||
|
|
||||||
|
assertNotSame(a1, a2);
|
||||||
|
assertNotSame(r1, r2);
|
||||||
|
|
||||||
|
assertEquals(a1, a2);
|
||||||
|
assertEquals(r1, r2);
|
||||||
|
assertEquals(r1.getSauerstoffVorrat(), r2.getSauerstoffVorrat(), 0.0001);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class BufferedReader_Writer {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new FileReader("src/Uebung_15_04/Mondnacht.txt"));
|
||||||
|
int i = 0;
|
||||||
|
int counter = 0;
|
||||||
|
int wortAnzahl = 0;
|
||||||
|
|
||||||
|
String zeile = reader.readLine();
|
||||||
|
|
||||||
|
while (zeile != null) {
|
||||||
|
i++;
|
||||||
|
System.out.println("Zeile " + i + ": " + zeile);
|
||||||
|
|
||||||
|
String[] w = zeile.split(" ");
|
||||||
|
wortAnzahl += w.length;
|
||||||
|
|
||||||
|
for (String wort : w) {
|
||||||
|
counter += wort.length();
|
||||||
|
}
|
||||||
|
zeile = reader.readLine();
|
||||||
|
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
System.out.println("Anzahl der Wörter: " + wortAnzahl);
|
||||||
|
System.out.println("Anzahl der Buchstaben: " + counter);
|
||||||
|
System.out.println("Anzahl der Zeilen: " + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
public class DoubleFormatter {
|
||||||
|
|
||||||
|
public static void printDouble(double zahl, int nachkommastellen) {
|
||||||
|
int multiplikator = 1;
|
||||||
|
for (int i = 0; i <= nachkommastellen; i++) {
|
||||||
|
multiplikator *= 10;
|
||||||
|
|
||||||
|
}
|
||||||
|
zahl = zahl * (nachkommastellen * multiplikator) / (nachkommastellen * multiplikator);
|
||||||
|
System.out.println("Ausgabe: " + zahl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
printDouble(1.0, 1); // Erwartete Ausgabe: 1.0
|
||||||
|
printDouble(10.1, 1); // Erwartete Ausgabe: 10.1
|
||||||
|
printDouble(2.01, 2); // Erwartete Ausgabe: 2.01
|
||||||
|
printDouble(2.006, 2); // Erwartete Ausgabe: 2.01
|
||||||
|
printDouble(2.0001, 2); // Erwartete Ausgabe: 2.00
|
||||||
|
printDouble(2.0005, 3); // Erwartete Ausgabe: 2.001
|
||||||
|
printDouble(123.456, 1); // Erwartete Ausgabe: 123.4
|
||||||
|
printDouble(9876.54321, 3); // Erwartete Ausgabe: 9876.543
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
public class MainSerialisierung {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
Mondnacht
|
||||||
|
Es war, als hätt' der Himmel
|
||||||
|
Die Erde still geküsst,
|
||||||
|
Dass sie im Blütenschimmer
|
||||||
|
Von ihm nun träumen müsst.
|
|
@ -0,0 +1,45 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Product implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private double price;
|
||||||
|
|
||||||
|
public Product() {}
|
||||||
|
|
||||||
|
public Product(String name, String description, double price) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(double price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package Uebung_15_04;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Raumanzug.
|
||||||
|
*/
|
||||||
|
public class Raumanzug implements Cloneable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauerstoffvorrat, der noch im Raumanzug ist.
|
||||||
|
*/
|
||||||
|
private double sauerstoffVorrat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ertzeugt einen neuen Raumanzug.
|
||||||
|
*/
|
||||||
|
public Raumanzug() {
|
||||||
|
sauerstoffVorrat = Math.random();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauerstoffvorrat im Anzug.
|
||||||
|
*
|
||||||
|
* @return Vorrat in % (0.0-1.0)
|
||||||
|
*/
|
||||||
|
public double getSauerstoffVorrat() {
|
||||||
|
return sauerstoffVorrat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tankt den Anzug auf.
|
||||||
|
*/
|
||||||
|
public void auftanken() {
|
||||||
|
sauerstoffVorrat = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
long temp;
|
||||||
|
temp = Double.doubleToLongBits(sauerstoffVorrat);
|
||||||
|
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Raumanzug other = (Raumanzug) obj;
|
||||||
|
return Double.doubleToLongBits(sauerstoffVorrat) == Double.doubleToLongBits(other.sauerstoffVorrat);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Raumanzug clone() throws CloneNotSupportedException {
|
||||||
|
return (Raumanzug) super.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue