Hard Drive $75.0 Compact Hard Drive $64.0 Large Capacity Hard Drive $130.0 SSD $80.0…
- User
Hard Drive 64.0 Large Capacity Hard Drive 80.0 Large Capacity SSD 40.0 32GB Memory Module (Ram32GB) 306.0 Powerful Processor $589.0
- Assistant
- User
(1) Create a new class ProductPackage which contains a storage, a memory and a porcessor The price = 50% of the price of the storage + 45% of the price of the memory + 90% of the price of the processor (2)Create instances of the following packages in your main program and output the price packageA: a SDD, 16G Memory and an Efficient Processor packageB: a Large Capacity Hard Drive, 32G Memory and a Powerful Processor
ProductPackage
storage : Storage memory : Memory processor : Processor +ProductPackage (storage : Storage, memory : Memory, processor : Processor) +getPrice() : double
- Assistantpython
class ProductPackage: def __init__(self, storage, memory, processor): self.storage = storage self.memory = memory self.processor = processor def get_price(self): storage_price = self.storage.get_price() * 0.5 memory_price = self.memory.get_price() * 0.45 processor_price = self.processor.get_price() * 0.9 return storage_price + memory_price + processor_price # Create instances of the packages packageA = ProductPackage(SSD(80.0), Ram16GB(40.0), EfficientProcessor(306.0)) packageB = ProductPackage(LargeCapacityHardDrive(130.0, 4), Ram32GB(69.0), PowerfulProcessor(589.0)) # Output the prices print("Package A price:", packageA.get_price()) print("Package B price:", packageB.get_price()) - User
use java
- Assistant
Sure! Here's the equivalent code in Java:
java - User
Hard Drive 64.0 Large Capacity Hard Drive 80.0 Large Capacity SSD 40.0 32GB Memory Module (Ram32GB) 306.0 Powerful Processor $589.0
- Assistant