Question: Create a Java program to simulate the maintenance and repair operations for various types of Star Wars droids. The system will load droid data from

Create a Java program to simulate the maintenance and repair operations for various types of Star Wars droids. The system will load droid data from a JSON file, perform maintenance based on each droids specific needs, and log repairs.
Define an abstract class `Droid` with the following methods:
performMaintenance(): Abstract method to be implemented by subclasses specifying maintenance actions based on the droid type.
getStatus(): Displays the droid's ID, type, battery level, and repair status.
chargeBattery(): Charges the battery to full capacity if its below a specified threshold (e.g.,25%).
Create the following Concrete Classes for Droid Types
AstromechDroid
Implements performMaintenance() with tasks like chargeBattery() and resetting navigation data.
Custom maintenance tasks may include calibrateSensors() for astromech functions.
ProtocolDroid
Implements performMaintenance() with tasks like rechargeBattery() and updateLanguageDatabase().
Additional tasks might include polishArmor() for maintaining protocol droid appearances.
BattleDroid
Implements performMaintenance() with tasks like repairWeapons() and reloadAmmo().
Custom maintenance includes armor checks and battery recharging for combat readiness.
Exception Handling:
MissingDataException: If any required data field is missing, throw a custom MissingDataException.
InvalidBatteryLevelException: Throw an exception if the battery level is not within 0100.
UnknownDroidTypeException: If droidType does not match any known type, throw an exception and log the issue.
Each time a performMaintenance() method is called, write an entry to repair_log.json. Include repair status and timestamp. Example:
droidID: R4-C2
droidType: Astromech
status: Maintenance completed
batteryLevel: 100
repairStatus: Working
timestamp: 2024-11-01T14:35:00Z
The program should function as follows:
Prompt the user to select a droid by ID.
Call the `performMaintenance()` method for the selected droid, updating battery level and repair status.
Log maintenance in `repair_log.json`.
After maintenance operations are complete, display a summary of all droids and any still needing repairs.
json file: droids.json
[
{
"droidID": "R2-D2",
"droidType": "Astromech",
"batteryLevel": 75,
"repairStatus": "Working"
},
{
"droidID": "C-3PO",
"droidType": "Protocol",
"batteryLevel": 50,
"repairStatus": "NeedsRepair"
},
{
"droidID": "B1-007",
"droidType": "Battle",
"batteryLevel": 20,
"repairStatus": "Damaged"
},
{
"droidID": "BB-8",
"droidType": "Astromech",
"batteryLevel": 10,
"repairStatus": "NeedsRepair"
},
{
"droidID": "IG-88",
"droidType": "Assassin",
"batteryLevel": 85,
"repairStatus": "Working"
},
{
"droidID": "K-2SO",
"droidType": "Security",
"batteryLevel": 40,
"repairStatus": "Damaged"
}
]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!