From e37a768c4d7901114fc90c046a4f0654c6422101 Mon Sep 17 00:00:00 2001 From: Amber Yeh <266454930+amberyeh41@users.noreply.github.com> Date: Thu, 2 Apr 2026 23:19:59 +0200 Subject: [PATCH] Lab JAVA Basic- Amber Yeh --- solution/.gitignore | 30 +++++++++++++++++++ solution/.idea/.gitignore | 10 +++++++ solution/.idea/misc.xml | 6 ++++ solution/.idea/modules.xml | 8 ++++++ solution/.idea/vcs.xml | 6 ++++ solution/solution.iml | 11 +++++++ solution/src/Employee.java | 59 ++++++++++++++++++++++++++++++++++++++ solution/src/Intern.java | 10 +++++++ solution/src/Task1.java | 20 +++++++++++++ solution/src/Task2.java | 21 ++++++++++++++ solution/src/Task5.java | 22 ++++++++++++++ 11 files changed, 203 insertions(+) create mode 100644 solution/.gitignore create mode 100644 solution/.idea/.gitignore create mode 100644 solution/.idea/misc.xml create mode 100644 solution/.idea/modules.xml create mode 100644 solution/.idea/vcs.xml create mode 100644 solution/solution.iml create mode 100644 solution/src/Employee.java create mode 100644 solution/src/Intern.java create mode 100644 solution/src/Task1.java create mode 100644 solution/src/Task2.java create mode 100644 solution/src/Task5.java diff --git a/solution/.gitignore b/solution/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/solution/.gitignore @@ -0,0 +1,30 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/solution/.idea/.gitignore b/solution/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/solution/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/solution/.idea/misc.xml b/solution/.idea/misc.xml new file mode 100644 index 0000000..7c3f821 --- /dev/null +++ b/solution/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solution/.idea/modules.xml b/solution/.idea/modules.xml new file mode 100644 index 0000000..7aa606b --- /dev/null +++ b/solution/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solution/.idea/vcs.xml b/solution/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/solution/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solution/solution.iml b/solution/solution.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/solution/solution.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/solution/src/Employee.java b/solution/src/Employee.java new file mode 100644 index 0000000..fe44590 --- /dev/null +++ b/solution/src/Employee.java @@ -0,0 +1,59 @@ +public class Employee { + protected double salary; + private int employeeId; + private String name; + private String jobTitle; + private double tenureYears; +//constructor + public Employee(int employeeId, String name, String jobTitle, double tenureYears, double salary){ + this.employeeId = employeeId; + this.name = name; + this.jobTitle = jobTitle; + this.tenureYears = tenureYears; + this.salary = salary; + + } +//method + public boolean canTakeLeaveOfAbsence(){ + return tenureYears >= 2; + } +//getter + + public double getSalary() { + return salary; + } + + public String getJobTitle() { + return jobTitle; + } + + public int getEmployeeId() { + return employeeId; + } + + public String getName() { + return name; + } + + public double getTenureYears() { + return tenureYears; + } + + //setter + + public void setEmployeeId(int employeeId) { + this.employeeId = employeeId; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + public void setJobTitle(String jobTitle) { + this.jobTitle = jobTitle; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/solution/src/Intern.java b/solution/src/Intern.java new file mode 100644 index 0000000..9c39929 --- /dev/null +++ b/solution/src/Intern.java @@ -0,0 +1,10 @@ +public class Intern extends Employee{ +// constructor + public Intern(int employeeId, String name, String jobTitle, double tenureYears, double salary){ + super(employeeId, name, jobTitle, tenureYears, salary > 20000 ? 20000 : salary); + } + @Override + public void setSalary(double salary) { + this.salary = salary > 20000 ? 20000 : salary; + } +} diff --git a/solution/src/Task1.java b/solution/src/Task1.java new file mode 100644 index 0000000..20f4939 --- /dev/null +++ b/solution/src/Task1.java @@ -0,0 +1,20 @@ +int range(int[] numbers) { + int highestNumber = numbers[0]; + int lowestNumber = numbers[0]; + for (int number : numbers){ + if(number > highestNumber){ + highestNumber = number; + } + if(number < lowestNumber){ + lowestNumber = number; + } + } + return highestNumber - lowestNumber; + +} + +void main() { + int[] numbers = {4, 2, 2, 12, 9, 3}; + + System.out.println("The range is " + range(numbers)); +} \ No newline at end of file diff --git a/solution/src/Task2.java b/solution/src/Task2.java new file mode 100644 index 0000000..add139b --- /dev/null +++ b/solution/src/Task2.java @@ -0,0 +1,21 @@ +int[] twoSmallest(int[] numbers) { + int[] result = {numbers[0], numbers[0]}; + + for(int number : numbers){ + if(number < result[0]){ + result[1] = result[0]; + result[0] = number; + } else if (number < result[1] && number!= result[0]){ + result[1] = number; + } + } + + return result; +} + + +void main() { + int[] numbers = {13, 6, 33, 44, 18, -24}; + int[] result = twoSmallest(numbers); + System.out.println("Smallest is " + result[0] + " and second smallest is " + result[1]); +} \ No newline at end of file diff --git a/solution/src/Task5.java b/solution/src/Task5.java new file mode 100644 index 0000000..a1c616f --- /dev/null +++ b/solution/src/Task5.java @@ -0,0 +1,22 @@ +import java.util.ArrayList; + +void main() { + ArrayList employees = new ArrayList<>(); + employees.add(new Employee(1,"John", "CFO", 15.5, 200000)); + employees.add(new Employee(2,"Amy", "CEO", 12.0, 300000)); + employees.add(new Employee(3,"Jose", "CTO", 9.0, 300000)); + employees.add(new Employee(4,"Jude", "PM", 7.5, 50000)); + employees.add(new Employee(5,"Emma", "SDE", 1.5, 35000)); + employees.add(new Employee(6,"Gala", "SDE", 5.5, 70000)); + employees.add(new Employee(7,"Uma", "QA", 2.5, 25000)); + employees.add(new Employee(8,"Alex", "CS", 1.5, 20000)); + employees.add(new Intern(9,"Maria", "SDE", 0.5, 22000)); + employees.add(new Intern(10,"Sean", "SDE", 0.5, 17000)); + + for(Employee employee:employees){ + System.out.println(employee.getName()+ " has been " + employee.getJobTitle() + " for " + employee.getTenureYears() + " years and earns " + employee.getSalary() + " euros."); + + } + +} +