Design and Analysis:
Final Assignment 7, Last Question:
- Code Review:
This iteration introduced a mutual exclusion switch and a controlled shutter. The shutter implemantation was straightforward:
class Shutter extends ControlledDevice{...}
The mutual exclusion switch posed more complexity due to its three pins, one of which can be left open. I simplified it by splitting it into two basic switches, inheriting from a generic Switch class for identification purposes. A dedicated class inherits from ControlEquipment, containing two switch variables.
In the toString() method, the state is determined by both switches' statuses. Methods like setFirstSwitch and setSecondSwitch manage these states.
For shared pin handling, especially when connecting to VCC or GND, adjustments were made in the parseComponent function, initially designed for GND connections. These switches are processed separately before combining results.
Source Monitor Analysis & Diagrams:
Omitted for brevity.
Final Assignment 8:
- Code Review:
This assignment added voltage management, complicating the logic. With switches off, parallel paths may carry voltage. Hence, code checks for open switches and assigns voltages accordingly. Current calculations involve resistance, ensuring limits aren't exceeded.
public void checkCurrent(){
for(Equipment item : equipmentList)
if(item.current > item.maxCurrent) flag = true;
outputInfo += "Overcurrent detected: " + flag;
}
device.setInputVoltage(voltage);
device.setOutputVoltage(voltage);
device.compute();
A short-circuit detection function was implemented:
public boolean detectShortCircuit(){
for(Equipment comp : components)
if(Double.isInfinite(comp.current)) return true;
return false;
}
Source Monitor Analysis & Diagrams:
Omitted for brevity.
Challenges and Insights:
Implementing mutual exclusion required careful handling of multiple pins. Simplifying this with inheritance worked but needs optimization for scalability. Voltage calculations demanded detailed conditionals, underscoring the importance of readable and robust code. Short-circuit detection was crucial, though improvements in efficiency are necessary.
Improvement Suggestions:
Plan nested circuits early to prevent oversight. Consider design patterns like State or Strategy for complex components, enhancing modularity. Emphasize modular programming and design patterns for maintainability.