a
This commit is contained in:
11
Anwendungsentwicklung/Anwendungsentwicklung.iml
Normal file
11
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
Anwendungsentwicklung/src/P1/Circle.java
Normal file
32
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
Anwendungsentwicklung/src/P1/Geometry.java
Normal file
6
Anwendungsentwicklung/src/P1/Geometry.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package P1;
|
||||
|
||||
public interface Geometry {
|
||||
double berechneUmfang();
|
||||
double berechneFlaeche();
|
||||
}
|
||||
10
Anwendungsentwicklung/src/P1/Main.java
Normal file
10
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
Anwendungsentwicklung/src/P1/Person.java
Normal file
65
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
Anwendungsentwicklung/src/P1/Rectangle.java
Normal file
55
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
Anwendungsentwicklung/src/P1/RefinedPerson.java
Normal file
29
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
Anwendungsentwicklung/src/P1/Test.java
Normal file
22
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
Anwendungsentwicklung/src/P1/Test2.java
Normal file
14
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user