EldiraSesto

PCB

Mar 18th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import model.CircuitPath;
  2. import model.HardwareComponent;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Collection;
  6.  
  7. public class PCB { //Eldira Sesto, 11815163
  8.     private Collection<HardwareComponent> hwComponents = new ArrayList<>();
  9.     private Collection<CircuitPath> connections = new ArrayList<>();
  10.  
  11.     public void placeComponent(HardwareComponent hw){
  12.         hwComponents.add(hw);
  13.     }
  14.  
  15.     public boolean connectComponents(HardwareComponent hw1, HardwareComponent hw2){
  16.         int bothOnTheBoard = 0;
  17.         for(HardwareComponent hw : hwComponents){
  18.             if(hw1.equals(hw) || hw2.equals(hw)) bothOnTheBoard++;
  19.         }
  20.  
  21.         if(bothOnTheBoard != 2) return false;
  22.  
  23.         connections.add(new CircuitPath(hw1, hw2));
  24.  
  25.         return true;
  26.     }
  27.  
  28.     public void addConnection(CircuitPath connection){
  29.         hwComponents.add(connection.getHwComponent1());
  30.         hwComponents.add(connection.getHwComponent2());
  31.         connections.add(connection);
  32.     }
  33.  
  34.     public float calculatePrice(){
  35.         float totalPrice = 0;
  36.         for(HardwareComponent hw : hwComponents){
  37.             totalPrice += hw.getPrice();
  38.         }
  39.         return totalPrice;
  40.     }
  41.  
  42.     public void showConnectionDetails(){
  43.         for(CircuitPath path : connections){
  44.             System.out.println(path);
  45.         }
  46.  
  47.         System.out.println("Total price: " + calculatePrice());
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment