Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import model.CircuitPath;
- import model.HardwareComponent;
- import java.util.ArrayList;
- import java.util.Collection;
- public class PCB { //Eldira Sesto, 11815163
- private Collection<HardwareComponent> hwComponents = new ArrayList<>();
- private Collection<CircuitPath> connections = new ArrayList<>();
- public void placeComponent(HardwareComponent hw){
- hwComponents.add(hw);
- }
- public boolean connectComponents(HardwareComponent hw1, HardwareComponent hw2){
- int bothOnTheBoard = 0;
- for(HardwareComponent hw : hwComponents){
- if(hw1.equals(hw) || hw2.equals(hw)) bothOnTheBoard++;
- }
- if(bothOnTheBoard != 2) return false;
- connections.add(new CircuitPath(hw1, hw2));
- return true;
- }
- public void addConnection(CircuitPath connection){
- hwComponents.add(connection.getHwComponent1());
- hwComponents.add(connection.getHwComponent2());
- connections.add(connection);
- }
- public float calculatePrice(){
- float totalPrice = 0;
- for(HardwareComponent hw : hwComponents){
- totalPrice += hw.getPrice();
- }
- return totalPrice;
- }
- public void showConnectionDetails(){
- for(CircuitPath path : connections){
- System.out.println(path);
- }
- System.out.println("Total price: " + calculatePrice());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment