From eca7980b75d5e830f54c6db4c844532b68c3e9d0 Mon Sep 17 00:00:00 2001 From: Petros Kostenidis Date: Sat, 30 Aug 2025 17:23:17 +0300 Subject: [PATCH 1/2] First commit --- .idea/.gitignore | 3 +++ .idea/lab-java-basics.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 32 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/lab-java-basics.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/lab-java-basics.iml b/.idea/lab-java-basics.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a9182a4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..505d07d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From d15ec3c639b45865592025c08d7106c568f14faa Mon Sep 17 00:00:00 2001 From: Petros Kostenidis Date: Sat, 6 Sep 2025 13:36:26 +0200 Subject: [PATCH 2/2] Week_2_Lab_1 : Complete --- src/Company/Employee.java | 133 +++++++++++++++++++++ src/Company/Intern.java | 9 ++ src/Company/Registration.java | 120 +++++++++++++++++++ src/DifferenceMaxMin/DifferenceMaxMin.java | 83 +++++++++++++ src/Week_2_Lab_1.java | 21 ++++ 5 files changed, 366 insertions(+) create mode 100644 src/Company/Employee.java create mode 100644 src/Company/Intern.java create mode 100644 src/Company/Registration.java create mode 100644 src/DifferenceMaxMin/DifferenceMaxMin.java create mode 100644 src/Week_2_Lab_1.java diff --git a/src/Company/Employee.java b/src/Company/Employee.java new file mode 100644 index 0000000..c32b405 --- /dev/null +++ b/src/Company/Employee.java @@ -0,0 +1,133 @@ +package Company; + +public class Employee { + //Attributes + private String name; + private String surname; + private String birthday; + private String address; + private String email; + private String id; + private int socialSecurityNumber; + private String position; + private int level; + private double salary; + + //Constructor + public Employee(String name, String surname, String birthday, String address, String email, String id, int socialSecurityNumber, String position, int level, double salary) { + this.name = name; + this.surname = surname; + this.birthday = birthday; + this.address = address; + this.email = email; + this.id = id; + this.socialSecurityNumber = socialSecurityNumber; + this.position = position; + this.level = level; + this.salary = salary; + } + + //Getters + public String getName() { + return name; + } + + public String getSurname() { + return surname; + } + + public String getBirthday() { + return birthday; + } + + public String getAddress() { + return address; + } + + public String getEmail() { + return email; + } + + public String getId() { + return id; + } + + public int getSocialSecurityNumber() { + return socialSecurityNumber; + } + + public String getPosition() { + return position; + } + + public int getLevel() { + return level; + } + + public double getSalary() { + return salary; + } + + //Setters + public void setName(String name) { + this.name = name; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setId(String id) { + this.id = id; + } + + public void setSocialSecurityNumber(int socialSecurityNumber) { + this.socialSecurityNumber = socialSecurityNumber; + } + + public void setPosition(String position) { + this.position = position; + } + + public void setLevel(int level) { + this.level = level; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + //Methods + public void information() { + System.out.println("======================================================" + + "\nThe Information for Employee " + name + " are the following:" + + "\n======================================================" + + "\nName: " + name + + "\nSurname: " + surname + + "\nBirthday: " + birthday + + "\nAddress: " + address + + "\nemail: " + email + + "\nID: " + id + + "\nSocialSecurityNumber: " + socialSecurityNumber + + "\nPosition: " + position + + "\nLevel: " + level + + "\nSalary: " + salary + " €" + + "\n======================================================"); + } + + public void setBonus(double bonus) { + this.salary = salary + bonus; + } +} diff --git a/src/Company/Intern.java b/src/Company/Intern.java new file mode 100644 index 0000000..08ca281 --- /dev/null +++ b/src/Company/Intern.java @@ -0,0 +1,9 @@ +package Company; + +public class Intern extends Employee { + + //Constructor + public Intern(String name, String surname, String birthday, String address, String email, String id, int socialSecurityNumber, String position, int level, double salary) { + super(name, surname, birthday, address, email, id, socialSecurityNumber, position, level, salary); + } +} diff --git a/src/Company/Registration.java b/src/Company/Registration.java new file mode 100644 index 0000000..acc2fda --- /dev/null +++ b/src/Company/Registration.java @@ -0,0 +1,120 @@ +package Company; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Registration { + public static void main(String[] args) { + + //3. Create an Employee class to represent an employee of a company. Add all relevant properties and behaviors + // that you might need but you have to include a salary property. Don't forget to add getters and setters. + + //4. Create an Intern class that extends from Employee. All the Interns have a salary limit of 20000 (constant). + // You must validate if an intern is created (or salary updated) with a bigger salary than the max. The max value is set. + + //5. Write a program that creates 10 Employees and print it al the properties. + + Scanner scanner = new Scanner(System.in); + + + System.out.println(""" + ------------------------------------------------------------------------------ + If you want to do the calculation automatic answer: true + If you want to do the calculation manually answer: false"""); + + + boolean autoCalc = scanner.nextBoolean(); + + if (!autoCalc) { + System.out.println(""" + ------------------------------------------------------------------------------ + Enter the following information about the new Employee with the correct order: + Name, Surname, Birthday, Address, email, ID, Social Security Number, Position, Level, Salary"""); + + String name = scanner.nextLine(); + String surname = scanner.nextLine(); + String birthday = scanner.nextLine(); + String address = scanner.nextLine(); + String email = scanner.nextLine(); + String id = scanner.nextLine(); + int socialSecurityNumber = scanner.nextInt(); + scanner.nextLine(); + String position = scanner.nextLine(); + int level = scanner.nextInt(); + scanner.nextLine(); + double salary = scanner.nextDouble(); + + System.out.println(""" + ------------------------------------------------------------------------------ + Is this employee an intern?"""); + + boolean interntrue = scanner.nextBoolean(); + + Employee emp1; + + do + if (interntrue && salary > 20000) { + System.out.println(""" + ------------------------------------------------------------------------------ + All the Interns have a salary limit of 20000! + Please re-enter new amount"""); + salary = scanner.nextDouble(); + + } while (interntrue && salary > 20000); + + + if (!interntrue) { + emp1 = new Employee(name, surname, birthday, address, email, id, socialSecurityNumber, position, level, salary); + } else { + emp1 = new Intern(name, surname, birthday, address, email, id, socialSecurityNumber, position, level, salary); + } + + emp1.information(); + + if (interntrue && emp1.getSalary() == 20000) { + System.out.println(""" + All the Interns have a salary limit of 20000, therefore this employee can not get a bonus !"""); + System.exit(0); + } + + System.out.println(""" + ---------------------------------------------------------------------- + Enter the next bonus amount for the employer:"""); + + emp1.setBonus(scanner.nextDouble()); + + do + if (interntrue && emp1.getSalary() > 20000) { + System.out.println(""" + ------------------------------------------------------------------------------ + All the Interns have a salary limit of 20000! + Please re-enter new bonus, so that the sum is not greater than 20000"""); + emp1.setBonus(scanner.nextDouble()); + + } while (interntrue && emp1.getSalary() > 20000); + + + System.out.println("The Salary plus the bonus of " + name + " " + surname + "is: " + emp1.getSalary()); + } else { + + List employees = new ArrayList<>(); + + employees.add(new Employee("Gustav", "Paloski", "19/07/1985", "Ravestreet 53", "guPalo@gmail.com", "GUPALO", 422525909, "Mechanical Engineer", 3, 3500)); + employees.add(new Employee("Peri", "Mango", "17/07/1985", "Nordistreet 53", "perima@gmail.com", "PERIMA", 852156588, "Engineering Manager", 6, 10000)); + employees.add(new Employee("Niko", "Toski", "19/08/1985", "Eleimonor 53", "nitokoski@gmail.com", "NISKIT", 136659586, "Electrical Engineer", 3, 3700)); + employees.add(new Intern("Lary", "limou", "19/07/1989", "Mordika 53", "lalirimou@gmail.com", "lALIR", 789654357, "Automation Engineer", 4, 6000)); + employees.add(new Employee("Helen", "Depathe", "12/02/1995", "Harilaou 53", "bepanthen85@gmail.com", "HEDEPA", 763124865, "Hand Worker", 1, 2000)); + employees.add(new Employee("Susan", "Neifola", "06/03/1990", "Kaisie 53", "kimame@gmail.com", "SANFOLA", 958462352, "Mechanical Engineer", 3, 3500)); + employees.add(new Intern("Dmitry", "Koronovitsch", "23/04/1975", "Senofarstreet 53", "nustazo@gmail.com", "DIKORO", 112156811, "Hand Worker", 2, 2300)); + employees.add(new Employee("Giovani", "Garcia", "30/012/1998", "Bankisa 53", "denTheloAllopia@gmail.com", "GIGAVANI", 246885931, "Hand Worker", 1, 2000)); + employees.add(new Intern("Linore", "Aloma", "01/04/1985", "Drakainas 53", "tola56@gmail.com", "LUCYPA", 455669852, "Hand Worker", 1, 2000)); + employees.add(new Employee("Zak", "Meno", "14/01/1989", "Maindo 53", "paokararegate4@gmail.com", "MEZAK", 789654858, "Electrical Engineer", 3, 3700)); + + for (Employee employee : employees) { + employee.information(); + } + + } + } +} diff --git a/src/DifferenceMaxMin/DifferenceMaxMin.java b/src/DifferenceMaxMin/DifferenceMaxMin.java new file mode 100644 index 0000000..4f17d0a --- /dev/null +++ b/src/DifferenceMaxMin/DifferenceMaxMin.java @@ -0,0 +1,83 @@ +package DifferenceMaxMin; + +import java.util.Arrays; +import java.util.Scanner; + +public class DifferenceMaxMin { + public static void main(String[] args) { + + //1. Write a method in Java to get the difference between the largest and smallest values in an array of integers. + // The length of the array must be 1 and above. Use loops and conditionals to develop the algorithm. + + Scanner scanner = new Scanner(System.in); + //ArrayList list = new ArrayList(); + + System.out.println("-------------------------------------\n\n" + + "Enter the size of your preferred array please..."); + int size = scanner.nextInt(); + if (size < 2) { + System.out.println("Need at least 2 elements !\n" + + "Try again !"); + System.exit(0); // cleanly terminates the program + } + int[] List = new int[size]; + + System.out.println("Enter one by one " + size + " integer numbers"); + for (int i = 0; i < size; i++) { + List[i] = scanner.nextInt(); + } + + System.out.println("---Information about the List that you Created---\n" + + "-------------------------------------------------\n\n" + + "List: " + Arrays.toString(List)); + + int maxList = List[0]; + int minList = List[0]; + int doubleChecker = List[0]; + int doubleCounter = 0; + + for (int i = 0; i < size; i++) { + if (List[i] == List[0]) { + doubleCounter++; + } + if (maxList <= List[i]) { + maxList = List[i]; + } + if (minList >= List[i]) { + minList = List[i]; + } + } + + + int dif = maxList - minList; + System.out.println("1. The difference between the largest (" + maxList + ") and smallest (" + minList + ") values in your List is: " + dif); + + //2. Write a method in Java to find the smallest and second smallest elements of a given array and print it in the console. + // Use loops and conditionals to develop the algorithm. + + int[] List2 = new int[size - 1]; + int step = 0; + int minList2 = 0; + + if (doubleCounter == size) { + minList2 = minList; + } else { + for (int i = 0; i < size; i++) { + if (minList != List[i]) { + List2[step] = List[i]; + step++; + } + } + + minList2 = List2[0]; + + for (int i = 0; i < (size - 1); i++) { + if (minList2 >= List2[i]) { + minList2 = List2[i]; + } + } + } + System.out.println("2a. Smallest Element: " + minList); + System.out.println("2b. Second Smallest Element: " + minList2); + } +} diff --git a/src/Week_2_Lab_1.java b/src/Week_2_Lab_1.java new file mode 100644 index 0000000..a29e687 --- /dev/null +++ b/src/Week_2_Lab_1.java @@ -0,0 +1,21 @@ + +public class Week_2_Lab_1 { + public static void main(String[] args) { + + //1. Write a method in Java to get the difference between the largest and smallest values in an array of integers. + // The length of the array must be 1 and above. Use loops and conditionals to develop the algorithm. + + //2. Write a method in Java to find the smallest and second smallest elements of a given array and print it in the console. + // Use loops and conditionals to develop the algorithm. + + //3. Create an Employee class to represent an employee of a company. Add all relevant properties and behaviors + // that you might need but you have to include a salary property. Don't forget to add getters and setters. + + //4. Create an Intern class that extends from Employee. All the Interns have a salary limit of 20000 (constant). + // You must validate if an intern is created (or salary updated) with a bigger salary than the max. The max value is set. + + //5. Write a program that creates 10 Employees and print it al the properties. + + + } +}