Repetition Präsentation
This commit is contained in:
parent
a87e5186f6
commit
f37709767f
13 changed files with 143 additions and 0 deletions
7
Code/Steiner/oopRepetition - 24-23-10/.vscode/settings.json
vendored
Normal file
7
Code/Steiner/oopRepetition - 24-23-10/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
18
Code/Steiner/oopRepetition - 24-23-10/README.md
Normal file
18
Code/Steiner/oopRepetition - 24-23-10/README.md
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||||
|
|
||||||
|
## Folder Structure
|
||||||
|
|
||||||
|
The workspace contains two folders by default, where:
|
||||||
|
|
||||||
|
- `src`: the folder to maintain sources
|
||||||
|
- `lib`: the folder to maintain dependencies
|
||||||
|
|
||||||
|
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||||
|
|
||||||
|
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||||
|
|
||||||
|
## Dependency Management
|
||||||
|
|
||||||
|
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
BIN
Code/Steiner/oopRepetition - 24-23-10/bin/DateOfBirth.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/bin/DateOfBirth.class
Normal file
Binary file not shown.
BIN
Code/Steiner/oopRepetition - 24-23-10/bin/Main.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/bin/Main.class
Normal file
Binary file not shown.
BIN
Code/Steiner/oopRepetition - 24-23-10/bin/Person.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/bin/Person.class
Normal file
Binary file not shown.
BIN
Code/Steiner/oopRepetition - 24-23-10/src/App.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/src/App.class
Normal file
Binary file not shown.
BIN
Code/Steiner/oopRepetition - 24-23-10/src/DateOfBirth.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/src/DateOfBirth.class
Normal file
Binary file not shown.
33
Code/Steiner/oopRepetition - 24-23-10/src/DateOfBirth.java
Normal file
33
Code/Steiner/oopRepetition - 24-23-10/src/DateOfBirth.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// DateOfBirth class to manage birth date and age calculation
|
||||||
|
class DateOfBirth {
|
||||||
|
private int birthYear;
|
||||||
|
private int birthMonth;
|
||||||
|
private int birthDay;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public DateOfBirth(int birthYear, int birthMonth, int birthDay) {
|
||||||
|
this.birthYear = birthYear;
|
||||||
|
this.birthMonth = birthMonth;
|
||||||
|
this.birthDay = birthDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to calculate the age based on the hardcoded current date (23.10.2024)
|
||||||
|
public int calculateAge() {
|
||||||
|
int currentYear = 2024;
|
||||||
|
int currentMonth = 10;
|
||||||
|
int currentDay = 23;
|
||||||
|
|
||||||
|
int age = currentYear - birthYear;
|
||||||
|
|
||||||
|
// Adjust the age if the birthday hasn't happened yet this year
|
||||||
|
if (birthMonth > currentMonth || (birthMonth == currentMonth && birthDay > currentDay)) {
|
||||||
|
age--;
|
||||||
|
}
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to return the birth date as a string
|
||||||
|
public String getBirthDate() {
|
||||||
|
return birthDay + "." + birthMonth + "." + birthYear;
|
||||||
|
}
|
||||||
|
}
|
BIN
Code/Steiner/oopRepetition - 24-23-10/src/Main.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/src/Main.class
Normal file
Binary file not shown.
38
Code/Steiner/oopRepetition - 24-23-10/src/Main.java
Normal file
38
Code/Steiner/oopRepetition - 24-23-10/src/Main.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Main class with methods to create, modify, and display a person
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Create a Person object with all parameters
|
||||||
|
Person person = createPerson();
|
||||||
|
|
||||||
|
// Print the introduction and list of information
|
||||||
|
printPersonDetails(person);
|
||||||
|
|
||||||
|
// Modify the person and return a new object
|
||||||
|
Person updatedPerson = modifyPerson(person, "Bob", "789 Oak Street");
|
||||||
|
|
||||||
|
// Print the updated person information
|
||||||
|
System.out.println("\nAfter modification:");
|
||||||
|
printPersonDetails(updatedPerson);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to create and return a Person object
|
||||||
|
public static Person createPerson() {
|
||||||
|
DateOfBirth dob = new DateOfBirth(1994, 6, 15); // Example birth date
|
||||||
|
return new Person("Alice", dob, "1234 Elm Street");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to print a person's details
|
||||||
|
public static void printPersonDetails(Person person) {
|
||||||
|
person.introduce(); // Print the introduction
|
||||||
|
person.listInformation(); // Print the full list of details
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to modify a person object and return the modified person (custom
|
||||||
|
// object as return type)
|
||||||
|
public static Person modifyPerson(Person originalPerson, String newName, String newAddress) {
|
||||||
|
// Modify the person's details and return the modified object
|
||||||
|
originalPerson.setName(newName); // Update the name
|
||||||
|
originalPerson.setAddress(newAddress); // Update the address
|
||||||
|
return originalPerson; // Return the modified object
|
||||||
|
}
|
||||||
|
}
|
BIN
Code/Steiner/oopRepetition - 24-23-10/src/Person.class
Normal file
BIN
Code/Steiner/oopRepetition - 24-23-10/src/Person.class
Normal file
Binary file not shown.
47
Code/Steiner/oopRepetition - 24-23-10/src/Person.java
Normal file
47
Code/Steiner/oopRepetition - 24-23-10/src/Person.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// Person class that uses the DateOfBirth class
|
||||||
|
class Person {
|
||||||
|
private String name;
|
||||||
|
private DateOfBirth dateOfBirth; // Using DateOfBirth for birth date management
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public Person(String name, DateOfBirth dateOfBirth, String address) {
|
||||||
|
this.name = name;
|
||||||
|
this.dateOfBirth = dateOfBirth;
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to introduce the person
|
||||||
|
public void introduce() {
|
||||||
|
System.out.println("Hi, I'm " + name + ". I was born on " + dateOfBirth.getBirthDate() + " and I am "
|
||||||
|
+ dateOfBirth.calculateAge() + " years old.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to list the person's details
|
||||||
|
public void listInformation() {
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
System.out.println("Birth Date: " + dateOfBirth.getBirthDate());
|
||||||
|
System.out.println("Age: " + dateOfBirth.calculateAge());
|
||||||
|
System.out.println("Address: " + address);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter for name
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter for name
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter for address
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter for address
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
}
|
BIN
Notizen/Objekte als Parameter.pptx
Normal file
BIN
Notizen/Objekte als Parameter.pptx
Normal file
Binary file not shown.
Loading…
Reference in a new issue