diff --git a/Classes/BowlingProgram.java b/Classes/BowlingProgram.java new file mode 100644 index 0000000..c36d5e4 --- /dev/null +++ b/Classes/BowlingProgram.java @@ -0,0 +1,34 @@ +import java.util.*; +import java.util.Iterator; + +public class Bowling { + HashMap players; + Bowling() { + players = new HashMap(); + } + public void addPlayer(String name, int p) { + players.put(name, p); + } + //your code goes here + public void getWinner() { + System.out.println(players.entrySet() + .stream().max((entry1, entry2) -> entry1.getValue() > entry2.getValue() ? 1 : -1).get().getKey()); + } + +} + +public class Program { + public static void main(String[ ] args) { + Bowling game = new Bowling(); + Scanner sc = new Scanner(System.in); + + for(int i=0;i<3;i++) { + String input = sc.nextLine(); + String[] values = input.split(" "); + String name = values[0]; + int points = Integer.parseInt(values[1]); + game.addPlayer(name, points); + } + game.getWinner(); + } +} diff --git a/ORACLE/JavaExplorerCertificateQuestion/Department.java b/ORACLE/JavaExplorerCertificateQuestion/Department.java new file mode 100644 index 0000000..ae03d80 --- /dev/null +++ b/ORACLE/JavaExplorerCertificateQuestion/Department.java @@ -0,0 +1,69 @@ +public class Department extends Employee { + + private static int counter = 0; + + private String departmentName; + + public Department(String departmentName) { + + this.departmentName = departmentName; + + } + + private Employee[] department = new Employee[10]; + + public void addEmp(Employee newEmployee) { + if (counter >= 0 && counter < 10) { + department[counter] = newEmployee; + counter++; + // System.out.println(counter); + } else { + System.out.println("Department is full!"); + } + } + + public int getNumberOfEmployees() { + return counter; + } + + public Employee[] getEmployees() { + // if(counter == 10) + return department; + + } + + public Employee getEmpWithId(int id) { + for (Employee emp : department) { + if (emp != null) { + if (emp.getID() == id) { + return emp; + } + } + } + return null; + } + + public double totalSalary() { + double totalSalary = 0.0; + + for (Employee emp : department) { + + totalSalary += (emp != null) ? emp.getSalary() : 0.0; + } + + return totalSalary; + } + + public double averageSalary() { + + return totalSalary() / counter; + + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return "Department: " + departmentName; + } + +} diff --git a/ORACLE/JavaExplorerCertificateQuestion/Employee.java b/ORACLE/JavaExplorerCertificateQuestion/Employee.java new file mode 100644 index 0000000..68b0556 --- /dev/null +++ b/ORACLE/JavaExplorerCertificateQuestion/Employee.java @@ -0,0 +1,48 @@ +public class Employee { + + private int iD; + private String name; + private double salary; + + public Employee() { + + } + + public Employee(int iD, String name, double salary) { +// super(); + this.iD = iD; + this.name = name; + this.salary = salary; + } + + public int getID() { + return iD; + } + + public void setID(int iD) { + this.iD = iD; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getSalary() { + return salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return "Employee: " + iD + " " + name + " " + salary; + } + +} diff --git a/ORACLE/JavaExplorerCertificateQuestion/HRApp.java b/ORACLE/JavaExplorerCertificateQuestion/HRApp.java new file mode 100644 index 0000000..380df7a --- /dev/null +++ b/ORACLE/JavaExplorerCertificateQuestion/HRApp.java @@ -0,0 +1,49 @@ +public class HRApp { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + System.out.println("HR App Starts"); + + Employee emp1 = new Employee(1, "Ann", 1500); + Employee emp2 = new Employee(2, "Jane", 2000); + Employee emp3 = new Employee(3, "Dirk", 2200); + Employee emp4 = new Employee(4, "Glies", 1800); + Employee emp5 = new Employee(5, "Brien", 2500); + Employee emp6 = new Employee(6, "Alex", 4000); + Employee emp7 = new Employee(7, "Lieve", 6000); + Employee emp8 = new Employee(8, "Dankun", 2000); + Employee emp9 = new Employee(9, "Sylla", 2200); + Employee emp10 = new Employee(10, "Jessica", 1800); + Employee emp11 = new Employee(11, "Yale", 2220); + + Department dp1 = new Department("Department Education"); + dp1.addEmp(emp1); + dp1.addEmp(emp2); + dp1.addEmp(emp3); + dp1.addEmp(emp4); + dp1.addEmp(emp5); + dp1.addEmp(emp6); + dp1.addEmp(emp7); + dp1.addEmp(emp8); + dp1.addEmp(emp9); + dp1.addEmp(emp10); + dp1.addEmp(emp11); + + System.out.println(dp1); + for (Employee emp : dp1.getEmployees()) { + if (emp != null) + System.out.println(emp); + } + + System.out.println("Total Salary: " + dp1.totalSalary()); + + System.out.println("Average Salary: " + dp1.averageSalary()); + + System.out.println(dp1.getNumberOfEmployees()); + + System.out.println(dp1.getEmpWithId(118)); + + } + +}