Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/lab-java-basics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added out/production/lab-java-basics/Employee.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Employees.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Intern.class
Binary file not shown.
Binary file added out/production/lab-java-basics/TaskOne.class
Binary file not shown.
Binary file added out/production/lab-java-basics/TaskTwo.class
Binary file not shown.
59 changes: 59 additions & 0 deletions src/main/java/Employee.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
25 changes: 25 additions & 0 deletions src/main/java/Employees.java
Original file line number Diff line number Diff line change
@@ -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<Employee> 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
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/Intern.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
29 changes: 29 additions & 0 deletions src/main/java/TaskOne.java
Original file line number Diff line number Diff line change
@@ -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(num<smallest){
smallest=num;
}
}

System.out.println("Amplitude between largest and smallest number is: " + (largest - smallest));
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/TaskTwo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//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.

public class TaskTwo {
public static void main(String[] args){
int[] nums = {3};

if(nums.length==2){
int min1 = nums[0];
int min2 = nums[1];

if(nums[1]<nums[0]){
min1 = nums[1];
min2 = nums[0];
}
System.out.println("The smallest number: " + min1);
System.out.println("The second smallest: " + min2);
} else if(nums.length>2){
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 = min1;
min1 = nums[i];
}else 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");
}

}
}