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
27 changes: 27 additions & 0 deletions Task1and2/ArrayMinMax.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package amazon.learn.week2.arrayList.Task1and2;

public class ArrayMinMax {

public static void main(String[] args) {
// Difference between smallest and largest array - integer
int[] bunchOfNumbers = {7, 15, 444, 80, 5, 29};

int largest = 0;
for (int i = 0; i < bunchOfNumbers.length; i++) {
if( bunchOfNumbers[i] > bunchOfNumbers[largest]) {
largest = i;
}
}
System.out.println("Largest number from the list is: " + bunchOfNumbers[largest]);

int smallest = 0;
for (int i = 0; i < bunchOfNumbers.length; i++) {
if( bunchOfNumbers[i] < bunchOfNumbers[smallest]) {
smallest = i;
}
}
System.out.println("Smallest number from the list is: " + bunchOfNumbers[smallest]);
}
}


23 changes: 23 additions & 0 deletions Task1and2/ArraySecondMin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package amazon.learn.week2.arrayList.Task1and2;

public class ArraySecondMin {

public static void main(String[] args) {
// Smallest and Second smallest value
int[] bunchOfNumbers = {2, 62, 84, 79, 4, 29};

int smallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;
for (int bunchOfNumber : bunchOfNumbers) {
if (bunchOfNumber < smallest) {
secondSmallest = smallest;
smallest = bunchOfNumber;
} else if (bunchOfNumber < secondSmallest && bunchOfNumber != smallest) {
secondSmallest = bunchOfNumber;
}
}

System.out.println("Smallest number: " + smallest);
System.out.println("Second smallest number: " + secondSmallest);
}
}
36 changes: 36 additions & 0 deletions Task3and4and5/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package amazon.learn.week2.arrayList.Task3and4and5;

import java.util.ArrayList;

public class Company {

ArrayList<Employee> employees;

public static void main(String[] args) {

Company ironhack = new Company();
ironhack.employees = new ArrayList<>();

ironhack.employees.add(new Employee("Jack", "Catman", 32500, 30));
ironhack.employees.add(new Employee("Mark", "Dogman", 34500, 30));
ironhack.employees.add(new Employee("Jenny", "Mouseman", 45000, 40));
ironhack.employees.add(new Employee("Celine", "Zebraman", 45000, 40));
ironhack.employees.add(new Employee("Maria", "Rabbitman", 42500, 40));
ironhack.employees.add(new Employee("Murasaki", "Snakeman", 32500, 30));
ironhack.employees.add(new Intern("Joe", "Giraffeman", 15000, 10));
ironhack.employees.add(new Intern("Ellie", "Lionman", 15000, 10));
ironhack.employees.add(new Employee("Marco", "Tigerman", 32500, 30));
ironhack.employees.add(new Employee("Saya", "Hamsteraman", 34500, 30));

ironhack.employees.forEach(System.out::println);
System.out.println();

for (Employee emp : ironhack.employees) {
if (emp instanceof Intern) {
emp.setSalary(25000);
}
}
}
}


54 changes: 54 additions & 0 deletions Task3and4and5/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package amazon.learn.week2.arrayList.Task3and4and5;

public class Employee {

private String name;
private String lastName;
private double workHours;
private int salary;

public Employee(String name, String lastName, int salary, double workHours) {
this.name = name;
this.salary = salary;
this.workHours = workHours;
this.lastName = lastName;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getSalary() {
return salary;
}

public int setSalary(int salary) {
this.salary = salary;
return salary;
}

public double getWorkHours() {
return workHours;
}

public void setWorkHours(double workHours) {
this.workHours = workHours;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

@Override
public String toString() {
return "Our Employee " + name + " " + lastName + " works " + workHours + " hours a week and has a salary of: " + salary + "$";
}
}
30 changes: 30 additions & 0 deletions Task3and4and5/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package amazon.learn.week2.arrayList.Task3and4and5;

public class Intern extends Employee {

public Intern(String name, String lastName, int salary, double workHours) {
super(name, lastName, salary, workHours);
}



@Override
public int getSalary() {
return super.getSalary();
}

@Override
public int setSalary(int salary) {
if (salary > 0 && salary <= 20000) {
super.setSalary(salary);
} else {
System.out.println("Please enter a valid salary. Intern salary cannot exceed 20,000.");
}
return salary;
}

@Override
public String toString() {
return "Our Intern " + getName() + " " + getLastName() + " works " + getWorkHours() + " hours a week and has a salary of: " + getSalary() + "$";
}
}
11 changes: 11 additions & 0 deletions lab-java-basics.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="amazon.learn.week2.arrayList" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>