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 eg
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
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 repairlogjson. Include repair status and timestamp. Example:
droidID: RC
droidType: Astromech
status: Maintenance completed
batteryLevel:
repairStatus: Working
timestamp: T::Z
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 repairlogjson
After maintenance operations are complete, display a summary of all droids and any still needing repairs.
json file: droids.json
"droidID": RD
"droidType": "Astromech",
"batteryLevel":
"repairStatus": "Working"
"droidID": CPO
"droidType": "Protocol",
"batteryLevel":
"repairStatus": "NeedsRepair"
"droidID": B
"droidType": "Battle",
"batteryLevel":
"repairStatus": "Damaged"
"droidID": BB
"droidType": "Astromech",
"batteryLevel":
"repairStatus": "NeedsRepair"
"droidID": IG
"droidType": "Assassin",
"batteryLevel":
"repairStatus": "Working"
"droidID": KSO
"droidType": "Security",
"batteryLevel":
"repairStatus": "Damaged"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
