neongm

PC Builder

Sep 15th, 2022
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.45 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2. import random
  3.  
  4.  
  5. class PC:
  6.     def __init__(self) -> None:
  7.         self.Case = ''
  8.         self.Motherboard = ''
  9.         self.CPU = ''
  10.         self.GPU = ''
  11.         self.RAM = ''
  12.         self.Storage = ''
  13.         self.Price = ''
  14.    
  15.     def __repr__(self):
  16.         return f"New nice and shiny PC: \ncase: {self.Case} \nCPU: {self.CPU} \nMotherboard: {self.Motherboard} \nGPU: {self.GPU} \nRAM: {self.RAM} \nStorage: {self.Storage} \n\nfor just {self.Price}! What a deal!"
  17.    
  18.    
  19. # A - for Abstract, I  for Interface
  20. class ABuilder(ABC):
  21.     def __init__(self):
  22.         self.PC = PC()
  23.  
  24.     def getPC(self):
  25.         return self.PC
  26.  
  27.     @abstractmethod
  28.     def PrepareCase(self): pass
  29.    
  30.     @abstractmethod
  31.     def PrepareMotherboard(self): pass
  32.        
  33.     @abstractmethod
  34.     def PrepareCPU(self): pass
  35.    
  36.     @abstractmethod
  37.     def PrepareGPU(self): pass
  38.    
  39.     @abstractmethod
  40.     def PrepareRAM(self): pass
  41.    
  42.     @abstractmethod
  43.     def PrepareStorage(self): pass
  44.    
  45.     @abstractmethod
  46.     def PreparePrice(self): pass
  47.  
  48.  
  49. class WorkstationBuilder(ABuilder):
  50.     def PrepareCase(self):
  51.         self.PC.Case = random.choice(["HP Brother Tower 2", "Lenovo Buisness Korobka 2"])
  52.    
  53.     def PrepareMotherboard(self):
  54.         self.PC.Motherboard = random.choice(["Gigabyte TRX4 Doska 4.0S+Ultra", "Motherduck x99 Chinese Rice Pot 2.0"])
  55.        
  56.     def PrepareCPU(self):
  57.         self.PC.CPU = "Threadripper 5995" if "TRX4" in self.PC.Motherboard else "Xeon e5 2670v3"
  58.    
  59.     def PrepareGPU(self):
  60.         self.PC.GPU = random.choice(['Quadro p4000', 'tesla A100', 'titan X'])
  61.    
  62.     def PrepareRAM(self):
  63.         self.PC.RAM = f"{random.randint(64, 512)}GB"
  64.    
  65.     def PrepareStorage(self):
  66.         self.PC.Storage = f'{random.randint(1, 16)} TB SSD + {random.randint(16, 64)} TB HDD'
  67.    
  68.     def PreparePrice(self):
  69.         self.PC.Price = f"{random.randint(5000, 60000)}$"
  70.  
  71.  
  72. class ForGrandmaBuilder(ABuilder):
  73.     def PrepareCase(self):
  74.         self.PC.Case = random.choice(["IBM PC Generic", "Wooden box"])
  75.    
  76.     def PrepareMotherboard(self):
  77.         self.PC.Motherboard = random.choice(["Gigabyte 771 Budget MB", "Asus FM2 Budegt MB"])
  78.        
  79.     def PrepareCPU(self):
  80.         self.PC.CPU = "intel Core 2 Quad" if "771" in self.PC.Motherboard else "AMD FX4100"
  81.    
  82.     def PrepareGPU(self):
  83.         self.PC.GPU = random.choice(['Radeon HD4550', 'GT 210', 'GT 710'])
  84.    
  85.     def PrepareRAM(self):
  86.         self.PC.RAM = f"{random.randint(1,2)}GB"
  87.    
  88.     def PrepareStorage(self):
  89.         self.PC.Storage = f'{random.randint(32, 128)}GB HDD'
  90.    
  91.     def PreparePrice(self):
  92.         self.PC.Price = f"{random.randint(5000, 600000)}$"
  93.  
  94.  
  95. class GamingPCBuilder(ABuilder):
  96.     def PrepareCase(self):
  97.         self.PC.Case = random.choice(["ASUS ROG STRIX MEGA RGB TOWER", "Open Stand 2.0"])
  98.    
  99.     def PrepareMotherboard(self):
  100.         self.PC.Motherboard = random.choice(["Gigabyte AM4 Gayming WIFI", "Asus ROG LGA1700 Ultimate"])
  101.        
  102.     def PrepareCPU(self):
  103.         self.PC.CPU = "Intel i7 12700" if "LGA1700" in self.PC.Motherboard else "AMD Ryzen R7 3700x"
  104.    
  105.     def PrepareGPU(self):
  106.         self.PC.GPU = random.choice(['RTX 3060', 'GTX 1050', 'GT 710'])
  107.    
  108.     def PrepareRAM(self):
  109.         self.PC.RAM = f"{random.randint(16, 64)}GB"
  110.    
  111.     def PrepareStorage(self):
  112.         self.PC.Storage = f'{random.randint(256, 4192)}GB SSD'
  113.    
  114.     def PreparePrice(self):
  115.         self.PC.Price = f"{random.randint(1500, 1e9)}$"
  116.  
  117.  
  118. class PcVendor():
  119.     def __init__(self, builder: ABuilder) -> None:
  120.         self.builder = builder
  121.        
  122.     def build(self):
  123.         self.builder.PrepareCase()
  124.         self.builder.PrepareMotherboard()
  125.         self.builder.PrepareCPU()
  126.         self.builder.PrepareGPU()
  127.         self.builder.PrepareRAM()
  128.         self.builder.PrepareStorage()
  129.         self.builder.PreparePrice()
  130.        
  131.         return self.builder.getPC()
  132.        
  133.  
  134. def Client():
  135.     vendor = PcVendor(WorkstationBuilder())
  136.     Workstation = vendor.build()
  137.     print('\n'+str(Workstation))
  138.    
  139.     vendorForBabushka = PcVendor(ForGrandmaBuilder())
  140.     Workstation = vendorForBabushka.build()
  141.     print('\n'+str(Workstation))
  142.    
  143.     vendorForGamers = PcVendor(GamingPCBuilder())
  144.     Workstation = vendorForGamers.build()
  145.     print('\n'+str(Workstation))
  146.  
  147.  
  148. def main():
  149.     Client()
  150.    
  151. if __name__ == "__main__": main()
Advertisement
Add Comment
Please, Sign In to add comment