Smaller task & refactoring co2

This commit is contained in:
Sage The DM 2024-11-06 15:41:49 +01:00
parent e45d52037f
commit 1464df11cf
29 changed files with 683 additions and 0 deletions

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View 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).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,28 @@
// Main application class where we create a Teacher object and display some
// info.
public class App {
public static void main(String[] args) throws Exception {
// Sample data for creating a Teacher object.
String firstname = "Karl";
String lastname = "Marx";
int compensation = 1000000;
String[] subjects = { "Economics", "Math", "German" };
// Creating a Teacher object using the data above.
Teacher teacher = new Teacher(firstname, lastname, compensation, subjects);
// Printing the teacher's full name.
System.out.println("Teacher: " + teacher.getFirstname() + " " + teacher.getLastname());
// Printing the teacher's compensation.
System.out.println("Compensation: " + teacher.getCompensation());
// Printing the subjects the teacher teaches.
System.out.print("Subjects: ");
// Loop through each subject in the array and print it.
for (String subject : teacher.getSubjects()) {
System.out.print(subject + " ");
}
}
}

Binary file not shown.

View file

@ -0,0 +1,61 @@
// The Teacher class represents a teacher with a first name, last name, compensation, and subjects they teach.
public class Teacher {
// Private fields to store the teacher's first name, last name, compensation,
// and subjects.
private String firstname;
private String lastname;
private int compensation;
private String[] subjects;
// Constructor for initializing a Teacher object with provided details.
public Teacher(String firstname, String lastname, int compensation, String[] subjects) {
// Assigning the provided first name to the teacher's firstname field.
this.firstname = firstname;
// Assigning the provided last name to the teacher's lastname field.
this.lastname = lastname;
// Assigning the provided compensation to the teacher's compensation field.
this.compensation = compensation;
// Assigning the provided array of subjects to the teacher's subjects field.
this.subjects = subjects;
}
// Getter method for getting the teacher's first name.
public String getFirstname() {
return firstname;
}
// Setter method for setting a new first name for the teacher.
public void setFirstname(String firstname) {
this.firstname = firstname;
}
// Getter method for getting the teacher's last name.
public String getLastname() {
return lastname;
}
// Setter method for setting a new last name for the teacher.
public void setLastname(String lastname) {
this.lastname = lastname;
}
// Getter method for getting the teacher's compensation.
public int getCompensation() {
return compensation;
}
// Setter method for setting a new compensation for the teacher.
public void setCompensation(int compensation) {
this.compensation = compensation;
}
// Getter method for getting the array of subjects the teacher teaches.
public String[] getSubjects() {
return subjects;
}
// Setter method for setting a new array of subjects for the teacher.
public void setSubjects(String[] subjects) {
this.subjects = subjects;
}
}