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..f76df2b --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ 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 diff --git a/out/production/lab-java-basics/Employee.class b/out/production/lab-java-basics/Employee.class new file mode 100644 index 0000000..a5775b0 Binary files /dev/null and b/out/production/lab-java-basics/Employee.class differ diff --git a/out/production/lab-java-basics/Employees.class b/out/production/lab-java-basics/Employees.class new file mode 100644 index 0000000..085e245 Binary files /dev/null and b/out/production/lab-java-basics/Employees.class differ diff --git a/out/production/lab-java-basics/Intern.class b/out/production/lab-java-basics/Intern.class new file mode 100644 index 0000000..0fde79c Binary files /dev/null and b/out/production/lab-java-basics/Intern.class differ diff --git a/out/production/lab-java-basics/TaskOne.class b/out/production/lab-java-basics/TaskOne.class new file mode 100644 index 0000000..6dd4659 Binary files /dev/null and b/out/production/lab-java-basics/TaskOne.class differ diff --git a/out/production/lab-java-basics/TaskTwo.class b/out/production/lab-java-basics/TaskTwo.class new file mode 100644 index 0000000..907b5d1 Binary files /dev/null and b/out/production/lab-java-basics/TaskTwo.class differ diff --git a/src/main/java/Employee.java b/src/main/java/Employee.java new file mode 100644 index 0000000..2ef4577 --- /dev/null +++ b/src/main/java/Employee.java @@ -0,0 +1,59 @@ +//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. + +public class Employee { + private String name; + private boolean isRemote; + private double salary; + + public Employee(String name, boolean isRemote, double salary){ + this.name = name; + this.isRemote = isRemote; + this.salary = salary; + } + + @Override + public String toString() { + return "Employee{" + + "name='" + name + '\'' + + ", isRemote=" + isRemote + + ", salary=" + salary + + '}'; + } + + //getters and setters + public String getName() { + return name; + } + public void setName(String name){ + this.name = name; + } + + public boolean getIsRemote() { + return isRemote; + } + public void setIsRemote(boolean isRemote){ + this.isRemote = isRemote; + } + + public double getSalary() { + return salary; + } + public void setSalary(double salary){ + this.salary = salary; + } + + //methods + public void giveRaise(){ + salary *= 1.05; + } + + public void changeToRemote(){ + isRemote = true; + } + + public void removeFromRemote(){ + isRemote = false; + } + +} diff --git a/src/main/java/Employees.java b/src/main/java/Employees.java new file mode 100644 index 0000000..d52f3f7 --- /dev/null +++ b/src/main/java/Employees.java @@ -0,0 +1,25 @@ +import java.util.ArrayList; + +//Write a program that creates 10 Employees and print it al the properties. + +public class Employees { + public static void main(String[] args){ + ArrayList employees = new ArrayList<>(); + + employees.add(new Employee("George Orwell", false, 18500)); + employees.add(new Employee("J.K. Rowling", false, 25000)); + employees.add(new Employee("Harper Lee", true, 34900)); + employees.add(new Employee("Harper Ende", true, 74800)); + employees.add(new Employee("Zion Frank", true, 72300)); + employees.add(new Employee("Linda Harbour", false, 32900)); + employees.add(new Employee("Greta Kinta", false, 57500)); + + employees.add(new Intern("Ashley Bronx", true, 34900)); + employees.add(new Intern("Candace Elista", false, 34900)); + employees.add(new Intern("Katie Johnson", false, 16780)); + + for (Employee e : employees) { + System.out.println(e); // now prints all properties nicely + } + } +} diff --git a/src/main/java/Intern.java b/src/main/java/Intern.java new file mode 100644 index 0000000..4f2150c --- /dev/null +++ b/src/main/java/Intern.java @@ -0,0 +1,16 @@ +//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. + + +public class Intern extends Employee{ + private static final double SALARY_LIMIT = 20000.0; + + public Intern(String name, boolean isRemote, double salary){ + super(name, isRemote, Math.min(salary, SALARY_LIMIT)); + } + + @Override + public void setIsRemote(boolean isRemote){ + super.setIsRemote(false); + } + } diff --git a/src/main/java/TaskOne.java b/src/main/java/TaskOne.java new file mode 100644 index 0000000..37d06c0 --- /dev/null +++ b/src/main/java/TaskOne.java @@ -0,0 +1,29 @@ +//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. + +public class TaskOne { + public static void main(String[] args){ + int[] nums = {5, 7, 8}; + + if(nums.length<1){ + System.out.println("Invalid array length"); + }else{ + int largest = nums[0]; + for(int num : nums){ + if(num>largest){ + largest=num; + } + } + + int smallest = largest; + for(int num : nums){ + if(num2){ + int min1 = nums[0]; + int min2 = nums[1]; + + for (int i = 2; i < nums.length; i++) { + for (int j = 2; j < nums.length; j++) { + if(nums[i]min1 && nums[i]< min2){ + min2 = nums[i]; + } + } + } + System.out.println("The smallest number: " + min1); + System.out.println("The second smallest: " + min2); + }else{ + System.out.println("Inalid array length - must be 2 numbers minimum"); + } + + } +}