This commit is contained in:
Your Name
2023-10-03 23:28:51 +02:00
parent 9a83c28137
commit 42f2899bbf
162 changed files with 9 additions and 13 deletions

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-21" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,32 @@
package P1;
public class Circle implements Geometry {
private int radius;
public Circle(int radius) {
this.radius = radius;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
@Override
public double berechneUmfang() {
return 2*Math.PI*radius;
}
@Override
public double berechneFlaeche() {
return Math.pow(radius,2)*Math.PI;
}
public String toString(){
return "Radius: " + radius;
}
}

View File

@@ -0,0 +1,6 @@
package P1;
public interface Geometry {
double berechneUmfang();
double berechneFlaeche();
}

View File

@@ -0,0 +1,10 @@
package P1;
public class Main {
public static void main(String[] args) {
var rec1 = new Rectangle(11,20);
var rec2 = new Rectangle(10,20);
System.out.println(rec1.equals(rec2));
System.out.println(rec1.toString()+" "+ rec2.toString());
}
}

View File

@@ -0,0 +1,65 @@
package P1;
import java.util.Objects;
public class Person {
private final String name;
private final String city;
private String street;
private String zipcode;
public Person(final String name, final String city, String street, String zipcode) {
Objects.requireNonNull(name, "NOT NULL");
Objects.requireNonNull(city, "NOT NULL");
this.name = name;
this.city = city;
this.street = street;
this.zipcode = zipcode;
}
// public boolean equals(Person input) {
// if (!name.equals(input.name))
// return false;
// if (!city.equals(input.city))
// return false;
// if (!street.equals(input.street))
// return false;
// if (!zipcode.equals(input.zipcode))
// return false;
// return true;
// }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
return Objects.equals(name, person.name) && Objects.equals(city, person.city) && Objects.equals(street, person.street) && Objects.equals(zipcode, person.zipcode);
}
public String getName() {
return name;
}
public String getCity() {
return city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
}

View File

@@ -0,0 +1,55 @@
package P1;
public class Rectangle implements Geometry{
private int breite;
private int hoehe;
public Rectangle(int breite, int hoehe) {
this.breite = breite;
this.hoehe = hoehe;
}
public int getBreite() {
return breite;
}
public void setBreite(int breite) {
this.breite = breite;
}
public int getHoehe() {
return hoehe;
}
public void setHoehe(int hoehe) {
this.hoehe = hoehe;
}
public boolean equals(Rectangle input){
if(breite==input.breite && hoehe == input.hoehe){
return true;
}
return false;
}
public int hashCode(){
final int prime = 31;
int result = 1;
result = prime * result + hoehe; result = prime * result + breite;
return result;
}
public String toString(){
return "breite: " + breite + "hoehe: " + hoehe+"hash: " + hashCode();
}
@Override
public double berechneUmfang() {
return 2*breite+2*hoehe;
}
@Override
public double berechneFlaeche() {
return hoehe * breite;
}
}

View File

@@ -0,0 +1,29 @@
package P1;
import java.util.Objects;
public class RefinedPerson extends Person{
private String nickName;
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public RefinedPerson(String name, String city, String street, String zipcode) {
super(name, city, street, zipcode);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RefinedPerson that = (RefinedPerson) o;
return Objects.equals(nickName, that.nickName);
}
}

View File

@@ -0,0 +1,22 @@
package P1;
public class Test {
public static void main(String[] args) {
Geometry[] rec = {
new Rectangle(10,10),
new Rectangle(10,10),
new Rectangle(10,10),
new Rectangle(10,10),
new Circle(10),
new Circle(10),
new Circle(10),
new Circle(10)};
for(Geometry g:rec){
System.out.println("Flache: " +g.berechneFlaeche());
System.out.println("Umfang: "+ g.berechneUmfang());
System.out.println("String: "+ g.toString());
}
}
}

View File

@@ -0,0 +1,14 @@
package P1;
public class Test2 {
public static void main(String[] args) {
var p1 = new Person("a","a","a","a");
var p2 = new Person("a","a","a","b");
var rp1 = new RefinedPerson("a","a","a","b");
rp1.setNickName("bob");
var rp2 = new RefinedPerson("a","a","a","b");
rp2.setNickName("bob");
System.out.println(p1.equals(p2));
System.out.println(rp1.equals(rp2));
}
}

View File

@@ -0,0 +1,4 @@
package P2;
public class A {
}

View File

@@ -0,0 +1,4 @@
package P2;
public class B extends A{
}

View File

@@ -0,0 +1,9 @@
package P2;
public class Brot extends Nahrungsmittel{
public Brot(){
super.setName("Brot");
super.setPreis(1f);
}
}

View File

@@ -0,0 +1,4 @@
package P2;
public class C extends A{
}

View File

@@ -0,0 +1,4 @@
package P2;
public class D extends A{
}

View File

@@ -0,0 +1,4 @@
package P2;
public class E {
}

View File

@@ -0,0 +1,20 @@
package P2;
public class Einkaufswagen<T> {
Nahrungsmittel[] produkte = new Nahrungsmittel[10];
int amount = 0;
void hinzufuegen(Nahrungsmittel produkt){
if (amount < 9){
produkte[amount++] = produkt;
}
else {
System.out.println("voller Lachs");
}
}
void ausgeben(){
for(int i = 0; i<amount;i++){
System.out.println(produkte[i].getName());
}
}
}

View File

@@ -0,0 +1,4 @@
package P2;
public class F {
}

View File

@@ -0,0 +1,5 @@
package P2;
public class MyGenericClass<T> {
// Inhalt der Klasse ist nicht wichtig
}

View File

@@ -0,0 +1,24 @@
package P2;
public abstract class Nahrungsmittel {
private String name;
private float preis;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPreis() {
return preis;
}
public void setPreis(float preis) {
this.preis = preis;
}
}

View File

@@ -0,0 +1,11 @@
package P2;
public class Test {
public static void main(String[] args) {
var test= new MyGenericClass<A>();
testCreate(test);
}
static void testCreate(MyGenericClass<? super C> c ){
}
}

View File

@@ -0,0 +1,42 @@
package P2;
import java.util.Scanner;
public class Test2 <T,X>{
public static void main(String[] args) {
boolean end = false;
Scanner sc = new Scanner(System.in);
Einkaufswagen<? extends Nahrungsmittel> einkaufswagen = new Einkaufswagen();
while (!end) {
System.out.println("1: Brot");
System.out.println("2: Wurst");
System.out.println("3: Ausgeben");
System.out.println("4: handelsbuch(produkt, menge)");
System.out.println("5: Ende");
System.out.println("");
switch (sc.nextInt()) {
case 1:
einkaufswagen.hinzufuegen(new Brot());
break;
case 2:
einkaufswagen.hinzufuegen(new Wurst());
break;
case 3:
einkaufswagen.ausgeben();
break;
case 4:
case 5:
end = true;
break;
}
}
}
}

View File

@@ -0,0 +1,8 @@
package P2;
public class Wurst extends Nahrungsmittel{
public Wurst(){
super.setName("Wurst");
super.setPreis(1.1f);
}
}