a
This commit is contained in:
11
WS23_24/Anwendungsentwicklung/Anwendungsentwicklung.iml
Normal file
11
WS23_24/Anwendungsentwicklung/Anwendungsentwicklung.iml
Normal 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>
|
||||
32
WS23_24/Anwendungsentwicklung/src/P1/Circle.java
Normal file
32
WS23_24/Anwendungsentwicklung/src/P1/Circle.java
Normal 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;
|
||||
}
|
||||
}
|
||||
6
WS23_24/Anwendungsentwicklung/src/P1/Geometry.java
Normal file
6
WS23_24/Anwendungsentwicklung/src/P1/Geometry.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package P1;
|
||||
|
||||
public interface Geometry {
|
||||
double berechneUmfang();
|
||||
double berechneFlaeche();
|
||||
}
|
||||
10
WS23_24/Anwendungsentwicklung/src/P1/Main.java
Normal file
10
WS23_24/Anwendungsentwicklung/src/P1/Main.java
Normal 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());
|
||||
}
|
||||
}
|
||||
65
WS23_24/Anwendungsentwicklung/src/P1/Person.java
Normal file
65
WS23_24/Anwendungsentwicklung/src/P1/Person.java
Normal 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;
|
||||
}
|
||||
}
|
||||
55
WS23_24/Anwendungsentwicklung/src/P1/Rectangle.java
Normal file
55
WS23_24/Anwendungsentwicklung/src/P1/Rectangle.java
Normal 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;
|
||||
}
|
||||
}
|
||||
29
WS23_24/Anwendungsentwicklung/src/P1/RefinedPerson.java
Normal file
29
WS23_24/Anwendungsentwicklung/src/P1/RefinedPerson.java
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
22
WS23_24/Anwendungsentwicklung/src/P1/Test.java
Normal file
22
WS23_24/Anwendungsentwicklung/src/P1/Test.java
Normal 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
WS23_24/Anwendungsentwicklung/src/P1/Test2.java
Normal file
14
WS23_24/Anwendungsentwicklung/src/P1/Test2.java
Normal 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));
|
||||
}
|
||||
}
|
||||
4
WS23_24/Anwendungsentwicklung/src/P2/A.java
Normal file
4
WS23_24/Anwendungsentwicklung/src/P2/A.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class A {
|
||||
}
|
||||
4
WS23_24/Anwendungsentwicklung/src/P2/B.java
Normal file
4
WS23_24/Anwendungsentwicklung/src/P2/B.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class B extends A{
|
||||
}
|
||||
9
WS23_24/Anwendungsentwicklung/src/P2/Brot.java
Normal file
9
WS23_24/Anwendungsentwicklung/src/P2/Brot.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package P2;
|
||||
|
||||
public class Brot extends Nahrungsmittel{
|
||||
|
||||
public Brot(){
|
||||
super.setName("Brot");
|
||||
super.setPreis(1f);
|
||||
}
|
||||
}
|
||||
4
WS23_24/Anwendungsentwicklung/src/P2/C.java
Normal file
4
WS23_24/Anwendungsentwicklung/src/P2/C.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class C extends A{
|
||||
}
|
||||
4
WS23_24/Anwendungsentwicklung/src/P2/D.java
Normal file
4
WS23_24/Anwendungsentwicklung/src/P2/D.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class D extends A{
|
||||
}
|
||||
4
WS23_24/Anwendungsentwicklung/src/P2/E.java
Normal file
4
WS23_24/Anwendungsentwicklung/src/P2/E.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class E {
|
||||
}
|
||||
20
WS23_24/Anwendungsentwicklung/src/P2/Einkaufswagen.java
Normal file
20
WS23_24/Anwendungsentwicklung/src/P2/Einkaufswagen.java
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
4
WS23_24/Anwendungsentwicklung/src/P2/F.java
Normal file
4
WS23_24/Anwendungsentwicklung/src/P2/F.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class F {
|
||||
}
|
||||
5
WS23_24/Anwendungsentwicklung/src/P2/MyGenericClass.java
Normal file
5
WS23_24/Anwendungsentwicklung/src/P2/MyGenericClass.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package P2;
|
||||
|
||||
public class MyGenericClass<T> {
|
||||
// Inhalt der Klasse ist nicht wichtig
|
||||
}
|
||||
24
WS23_24/Anwendungsentwicklung/src/P2/Nahrungsmittel.java
Normal file
24
WS23_24/Anwendungsentwicklung/src/P2/Nahrungsmittel.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
11
WS23_24/Anwendungsentwicklung/src/P2/Test.java
Normal file
11
WS23_24/Anwendungsentwicklung/src/P2/Test.java
Normal 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 ){
|
||||
|
||||
}
|
||||
}
|
||||
42
WS23_24/Anwendungsentwicklung/src/P2/Test2.java
Normal file
42
WS23_24/Anwendungsentwicklung/src/P2/Test2.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
8
WS23_24/Anwendungsentwicklung/src/P2/Wurst.java
Normal file
8
WS23_24/Anwendungsentwicklung/src/P2/Wurst.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package P2;
|
||||
|
||||
public class Wurst extends Nahrungsmittel{
|
||||
public Wurst(){
|
||||
super.setName("Wurst");
|
||||
super.setPreis(1.1f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user