Add worker interface
Problem Context
We have different types of workers: full-time employees who work, eat lunch, and attend meetings; and robots that only work.
Intermediate
100 points
File Changes (2)
src/main/java/com/example/hr/Worker.java
ADDED
@@ -0 +1 @@
| 1 | +package com.example.hr; |
|
| 2 | + |
|
| 3 | +public interface Worker { |
|
| 4 | + void work(); |
|
| 5 | + void eat(); |
|
| 6 | + void attendMeeting(); |
|
| 7 | + void takeBreak(); |
|
| 8 | + void receiveSalary(); |
|
| 9 | +} |
src/main/java/com/example/hr/RobotWorker.java
ADDED
@@ -0 +1 @@
| 1 | +package com.example.hr; |
|
| 2 | + |
|
| 3 | +public class RobotWorker implements Worker { |
|
| 4 | + |
|
| 5 | + @Override |
|
| 6 | + public void work() { |
|
| 7 | + System.out.println("Robot working..."); |
|
| 8 | + } |
|
| 9 | + |
|
| 10 | + @Override |
|
| 11 | + public void eat() { |
|
| 12 | + // Robots don't eat |
|
| 13 | + throw new UnsupportedOperationException("Robots don't eat"); |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + @Override |
|
| 17 | + public void attendMeeting() { |
|
| 18 | + // Robots don't attend meetings |
|
| 19 | + throw new UnsupportedOperationException("Robots don't attend meetings"); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + @Override |
|
| 23 | + public void takeBreak() { |
|
| 24 | + // Robots don't take breaks |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + @Override |
|
| 28 | + public void receiveSalary() { |
|
| 29 | + // Robots don't receive salary |
|
| 30 | + throw new UnsupportedOperationException("Robots don't receive salary"); |
|
| 31 | + } |
|
| 32 | +} |
Login Required: You must be registered to submit reviews and receive AI feedback.
Register or
login to start reviewing!
Your Review
Review Tips
- Look for security vulnerabilities (SQL injection, XSS, etc.)
- Check for null pointer exceptions and error handling
- Consider performance implications
- Evaluate code maintainability and readability
- Check for proper resource management
- Look for logic errors or edge cases