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
29 changes: 29 additions & 0 deletions Lab 1 Java Basics Cori/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### 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
8 changes: 8 additions & 0 deletions Lab 1 Java Basics Cori/.idea/.gitignore

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

6 changes: 6 additions & 0 deletions Lab 1 Java Basics Cori/.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 Lab 1 Java Basics Cori/.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 Lab 1 Java Basics Cori/.idea/vcs.xml

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

11 changes: 11 additions & 0 deletions Lab 1 Java Basics Cori/Lab 1 Java Basics Cori.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$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
104 changes: 104 additions & 0 deletions Lab 1 Java Basics Cori/src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

// Exercise 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.


class Employee {
private String name;
private String surname;
private int age;
private String namePosition;
private int levelInCompany;
private int salary;
private boolean activeWorker;

public Employee(String name, String surname, int age, String namePosition, int levelInCompany, int salary, boolean activeWorker) {
setName(name);
setSurname(surname);
setAge(age);
setNamePosition(namePosition);
setSalary(salary);
setLevelInCompany(levelInCompany);
setActiveWorker(activeWorker);
}

public Employee(String name, String surname){
setName(name);
setSurname(surname);
}


public String getName() {
return name;
}

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

public String getSurname() {
return surname;
}

public void setSurname(String surname) {
this.surname = surname;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getNamePosition() {
return namePosition;
}

public void setNamePosition(String namePosition) {
this.namePosition = namePosition;
}

public int getLevelInCompany() {
return levelInCompany;
}

public void setLevelInCompany(int levelInCompany) {
this.levelInCompany = levelInCompany;
}

public int getSalary() {
return salary;
}

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

public boolean isActiveWorker() {
return activeWorker;
}

public void setActiveWorker(boolean activeWorker) {
this.activeWorker = activeWorker;
}

public String getEmployeeDetails(){
return this.name + " " + this.surname + " is " + this.age + " years old. Works as " + this.namePosition + " level " + this.levelInCompany + " with a salary of " + this.salary + " and it's working status is " + this.activeWorker + ".";
}

public String getEmployeeFullName(){
return "The employee full name is " + this.name + " " + this.surname;
}

public void offEmployee(){
this.activeWorker = false;
}
}



24 changes: 24 additions & 0 deletions Lab 1 Java Basics Cori/src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Exercise 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.

class Intern extends Employee{

int maxSalary = 20000;

public Intern(String name, String surname) {
super(name, surname);
}


public void setSalary(int salary){
if (salary > maxSalary){
super.setSalary(maxSalary);
System.out.println("New Salary set to: " + maxSalary);
} else {
super.setSalary(salary);
}
}
}
95 changes: 95 additions & 0 deletions Lab 1 Java Basics Cori/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {


// Exercise 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.


int[] differenceLS = {10, 30, 5, 7, 6, 80, 900, 175, 250, 20};

int maxNum = differenceLS[0];
int minNum = differenceLS[0];

for(int i = 0; i < differenceLS.length; i++){
if (maxNum < differenceLS[i]){
maxNum = differenceLS[i];
}else if(minNum > differenceLS[i] ){
minNum = differenceLS[i];
}
}

int difference = maxNum - minNum;

System.out.println("The difference between the largest and smallest values is max " + difference + ".");

// Exercise 2
// Write a method in Java to find the smallest and the second smallest elements
// of a given array and print it in the console.
// Use loops and conditionals to develop the algorithm.

int[] smallestAndSecondSmallest = {510, 200, 400, 500, 350, 150, 680, 251, 925};

int smallestNum = smallestAndSecondSmallest[0];
int secondSmallestNum = smallestAndSecondSmallest[0];

for(int i = 0; i < smallestAndSecondSmallest.length; i++){
if (smallestNum > smallestAndSecondSmallest[i]){
secondSmallestNum = smallestNum;
smallestNum = smallestAndSecondSmallest[i];
} else if(secondSmallestNum > smallestAndSecondSmallest[i] && smallestNum != smallestAndSecondSmallest[i]) {
secondSmallestNum = smallestAndSecondSmallest[i];
}
}

System.out.println("The smallest number is " + smallestNum + " and the second smallest is " + secondSmallestNum + ".");




// Exercise 3 in Employee.java
// Exercise 4 in Intern.java

//Exercise 5
// Write a program that creates 10 Employees and print it al the properties.

Employee employee1 = new Employee("Marcus", "Kornelius", 29, "Data Analyst", 3, 28000, true);
Employee employee2 = new Employee("Maria", "BonDia", 32, "Accountant", 4, 36000, true);
Employee employee3 = new Employee("Joana", "Triana", 33, "Software Developer", 5, 45000, true);
Employee employee4 = new Employee("Clara", "Aldana", 25, "Project Manager", 4, 36000, true);
Employee employee5 = new Employee("Laia", "Mana", 40, "HR", 3, 28000, true);
Employee employee6 = new Employee("Kostas", "Lipon", 42, "Customer Support", 2, 24000, true);
Employee employee7 = new Employee("Carme", "Ganga", 22, "Business Analyst", 3, 28000, true);
Employee employee8 = new Employee("Ona", "Vento", 35, "Marketing Specialist", 2, 24000, true);
Employee employee9 = new Employee("Niko", "Panallet", 52, "Operations Manager", 4, 36000, true);
Employee employee10 = new Employee("Petro", "Metrio", 38, "Sales Representative", 2, 24000, true);


System.out.println(employee1.getEmployeeDetails());
System.out.println(employee2.getEmployeeDetails());
System.out.println(employee3.getEmployeeDetails());
System.out.println(employee4.getEmployeeDetails());
System.out.println(employee5.getEmployeeDetails());
System.out.println(employee6.getEmployeeDetails());
System.out.println(employee7.getEmployeeDetails());
System.out.println(employee8.getEmployeeDetails());
System.out.println(employee9.getEmployeeDetails());
System.out.println(employee10.getEmployeeDetails());


// Extra

// Intern intern1 = new Intern("Blanca", "Valeria");

// intern1.setSalary(30000);
// employee1.offEmployee();
// System.out.println(employee1.getEmployeeDetails());


}
}