Skill Week 5
Skill Week 5
Course Code-23CS2103A
Name: K. Madhu mitha
ID Number: 2300090088
Skill-Week-5
Question-1:
package Problem1;
import java.util.HashMap;
import java.util.Map;
interface Employee {
String getId();
String getName();
double getSalary();
this.id = id;
this.name = name;
this.salary = salary;
this.benefits = benefits;
}
public String getId() {
return id;
return name;
return salary;
return benefits;
this.name = name;
this.salary = salary;
this.benefits = benefits;
this.id = id;
this.name = name;
this.salary = salary;
this.contractDuration = contractDuration;
return id;
return name;
return salary;
return contractDuration;
this.name = name;
this.salary = salary;
}
public void setContractDuration(int contractDuration) {
this.contractDuration = contractDuration;
class EmployeeManager {
employees.put(employee.getId(), employee);
employees.remove(id);
return employees.get(id);
public void updateEmployee(String id, String name, double salary, String benefits, Integer contractDuration) {
if (employee != null) {
employee.setName(name);
employee.setSalary(salary);
((PermanentEmployee) employee).setBenefits(benefits);
((ContractEmployee) employee).setContractDuration(contractDuration);
}
public class Main {
manager.addEmployee(permanentEmployee);
manager.addEmployee(contractEmployee);
manager.removeEmployee("1");
if (retrieved != null) {
System.out.println(retrieved.getName());
} else {
Output:
Question-2:
package Problem2;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
class Candidate {
this.name = name;
this.votes = 0;
return name;
}
public int getVotes() {
return votes;
votes++;
class VotingSystem {
if (candidates.containsKey(name)) {
if (voters.contains(voterId)) {
if (candidate == null) {
candidate.incrementVotes();
voters.add(voterId);
}
if (candidate == null) {
return candidate.getVotes();
system.addCandidate("Alice");
system.addCandidate("Bob");
system.vote("Voter1", "Alice");
system.vote("Voter2", "Bob");
system.vote("Voter3", "Alice");
try {
system.vote("Voter1", "Bob");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
try {
system.vote("Voter4", "Charlie");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
try {
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
Output: