Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CS V13 Object-Oriented Group Project 8. Created class Computer with 12 iterations.

97 views
ubuntu2004
Kernel: Python 3 (system-wide)

GP_08_Computer_v01

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v01.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- class Computer: pass # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates first object # Default constructor com1 = Computer() print('1st object: ', com1) # This instantiates second object # Default constructor com2 = Computer() print('2nd object: ', com2)
1st object: <__main__.Computer object at 0x000002B416667E20> 2nd object: <__main__.Computer object at 0x000002B416667EB0>

GP_08_Computer_v02

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v02.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) """ ''' Methods: __init__(): To initialize attributes displayComputer(): To display object ''' class Computer: # Constructor def __init__(self, brand='None',): self.brand = brand def displayComputer(self): print('Brand: ', self.brand) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() comp1.displayComputer() # Non-default constructor comp2 = Computer('Apple') comp2.displayComputer() # Non-default constructor comp3 = Computer('Dell') comp3.displayComputer()
Brand: None Brand: HP Brand: Lenovo

GP_08_Computer_v03

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v03.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects displayComputer(): To display object ''' class Computer: # Constructor def __init__(self, brand='None'): self.brand = brand # Destructor def __del__(self): print('The object with the brand', self.brand, 'was destroyed.') def displayComputer(self): print('Brand: ', self.brand) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() comp1.displayComputer() # Non-default constructor comp2 = Computer('Apple') comp2.displayComputer() # Delete objects del comp1 del comp2
Brand: None Brand: HP The object with the brand None was destroyed. The object with the brand HP was destroyed.

GP_08_Computer_v04

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v04.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects displayComputer(): To display object ''' class Computer: # Constructor def __init__(self, brand='None', motherboard='None'): self.brand = brand self.motherboard = motherboard # Destructor def __del__(self): print('The object with the brand', self.brand, 'was destroyed.') def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() comp1.displayComputer() # Non-default constructor comp2 = Computer('Apple') comp2.displayComputer() # Non-default constructor comp3 = Computer('Apple', 'M1') comp3.displayComputer() # This instantiates second set of objects # Non-default constructor comp4 = Computer('Dell') comp4.displayComputer() # Non-default constructor comp5 = Computer('Dell', 'Gigabyte') comp5.displayComputer() # Delete objects del comp1 del comp2 del comp3 del comp4 del comp5
Brand: None Motherboard: None Brand: HP Motherboard: None Brand: Apple Motherboard: M1 Brand: Dell Motherboard: None Brand: Lenovo Motherboard: Gigabyte The object with the brand None was destroyed. The object with the brand HP was destroyed. The object with the brand Apple was destroyed. The object with the brand Dell was destroyed. The object with the brand Lenovo was destroyed.

GP_08_Computer_v05

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v05.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard displayComputer(): To display object ''' class Computer: # Constructor def __init__(self, brand='None', motherboard='None'): self.brand = brand self.motherboard = motherboard # Destructor def __del__(self): print('The object with the brand and motherboard of', self.brand, 'with', self.motherboard, ' was destroyed.') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() comp1.displayComputer() # Non-default constructor comp2 = Computer('Apple') comp2.displayComputer() # Non-default constructor comp3 = Computer('Apple', 'M1') # Using accessor methods print('---------- Note the effect of accessor and mutator methods below \ ----------') print('\nUsing accessor method for the object comp3 - the value of Brand = ', comp3.getBrand()) print('Using accessor method for the object comp3 - the value of Motherboard = ', comp3.getMotherboard(), '\n') # Using mutator methods print('\nUsing mutator method for the object comp3 - \ the new value of Brand = ', comp3.setBrand('Lenovo')) print('Using mutator method for the object comp3 - \ the new value of Motherboard = ', comp3.setMotherboard('Asus'), '\n') comp3.displayComputer() print('---------- Note the effect of accessor and mutator methods above \ ----------') # This instantiates second set of objects # Non-default constructor comp4 = Computer('Dell') comp4.displayComputer() # Non-default constructor comp5 = Computer('Dell', 'AMD') comp5.displayComputer() # Delete objects del comp1 del comp2 del comp3 del comp4 del comp5
Brand: None Motherboard: None Brand: Apple Motherboard: None ---------- Note the effect of accessor and mutator methods below ---------- Using accessor method for the object comp3 - the value of Brand = Apple Using accessor method for the object comp3 - the value of Motherboard = M1 Using mutator method for the object comp3 - the new value of Brand = None Using mutator method for the object comp3 - the new value of Motherboard = None Brand: Lenovo Motherboard: Asus ---------- Note the effect of accessor and mutator methods above ---------- Brand: Dell Motherboard: None Brand: Dell Motherboard: AMD The object with the brand and motherboard of None with None was destroyed. The object with the brand and motherboard of Apple with None was destroyed. The object with the brand and motherboard of Lenovo with Asus was destroyed. The object with the brand and motherboard of Dell with None was destroyed. The object with the brand and motherboard of Dell with AMD was destroyed.

GP_08_Computer_v06

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v06.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu displayComputer(): To display object ''' class Computer: # Constructor def __init__(self, brand='None', motherboard='None', cpu='None', ram='None', hd='None', gpu='None', os='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu # Destructor def __del__(self): print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard and', self.cpu, 'CPU was destroyed.') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard def setCPU(self, cpu): self.cpu = cpu # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() # Non-default constructor comp2 = Computer('HP') comp3 = Computer('HP', 'Intel') comp4 = Computer('HP', 'Intel', 'i3') # This instantiates second set of objects # Non-default constructor comp5 = Computer('Dell') comp6 = Computer('Dell', 'AMD') comp7 = Computer('Dell', 'AMD', 'Ryzen 5') comp1.displayComputer() comp2.displayComputer() comp3.displayComputer() comp4.displayComputer() comp5.displayComputer() comp5.displayComputer() comp6.displayComputer() comp7.displayComputer() # Using accessor methods print('---------- Note the effect of accessor and mutator methods below \ ----------') print('\nUsing accessor method for the object comp7 - the value of Brand = ', comp7.getBrand()) print('Using accessor method for the object comp7 - the value of Motherboard = ', comp7.getMotherboard(), '\n') print('Using accessor method for the object comp7 - the value of CPU = ', comp7.getCPU(), '\n') # Using mutator methods print('\nUsing mutator method for the object comp7 - the new value of Brand = ', comp7.setBrand('Lenovo')) print('Using mutator method for the object comp7 - the new value of Motherboard = ', comp7.setMotherboard('Asus'), '\n') print('Using mutator method for the object comp7 - the new value of CPU = ', comp7.setCPU('Intel i7'), '\n') print('---------- Note the effect of accessor and mutator methods above \ ----------')
Brand: None Motherboard: None CPU: None Brand: HP Motherboard: None CPU: None Brand: HP Motherboard: Intel CPU: None Brand: HP Motherboard: Intel CPU: i3 Brand: Dell Motherboard: None CPU: None Brand: Dell Motherboard: None CPU: None Brand: Dell Motherboard: AMD CPU: None Brand: Dell Motherboard: AMD CPU: Ryzen 5 ---------- Note the effect of accessor and mutator methods below ---------- Using accessor method for the object comp7 - the value of Brand = Dell Using accessor method for the object comp7 - the value of Motherboard = AMD Using accessor method for the object comp7 - the value of CPU = Ryzen 5 Using mutator method for the object comp7 - the new value of Brand = None Using mutator method for the object comp7 - the new value of Motherboard = None Using mutator method for the object comp7 - the new value of CPU = None ---------- Note the effect of accessor and mutator methods above ----------

GP_08_Computer_v07

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v07.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu displayComputer(): To display object ''' class Computer: # Constructor def __init__(self, brand='None', motherboard='None', cpu='None', ram='None', hd='None', gpu='None', os='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu # Destructor def __del__(self): print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard and', self.cpu, 'CPU was destroyed.') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard def setCPU(self, cpu): self.cpu = cpu # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() # Non-default constructor comp2 = Computer('HP') comp3 = Computer('HP', 'Intel') comp4 = Computer('HP', 'Intel', 'i3') # This instantiates second set of objects # Non-default constructor comp5 = Computer('Dell') comp6 = Computer('Dell', 'AMD') comp7 = Computer('Dell', 'AMD', 'Ryzen 5') comp1.displayComputer() comp2.displayComputer() comp3.displayComputer() comp4.displayComputer() comp5.displayComputer() comp5.displayComputer() comp6.displayComputer() comp7.displayComputer() # Using accessor methods print('---------- Note the effect of accessor and mutator methods below \ ----------') print('\nUsing accessor method for the object comp7 - the value of Brand = ', comp7.getBrand()) print('Using accessor method for the object comp7 - the value of Motherboard = ', comp7.getMotherboard(), '\n') print('Using accessor method for the object comp7 - the value of CPU = ', comp7.getCPU(), '\n') # Using mutator methods print('\nUsing mutator method for the object comp7 - the new value of Brand = ', comp7.setBrand('Lenovo')) print('Using mutator method for the object comp7 - the new value of Motherboard = ', comp7.setMotherboard('Asus'), '\n') print('Using mutator method for the object comp7 - the new value of CPU = ', comp7.setCPU('Intel i7'), '\n') print('---------- Note the effect of accessor and mutator methods above \ ----------') # Destroying objects print('\n---------- Starting to destroy objects ----------\n') del comp1 del comp2 del comp3 del comp4 del comp5 del comp6 del comp7
Brand: None Motherboard: None CPU: None Brand: HP Motherboard: None CPU: None Brand: HP Motherboard: Intel CPU: None Brand: HP Motherboard: Intel CPU: i3 Brand: Dell Motherboard: None CPU: None Brand: Dell Motherboard: None CPU: None Brand: Dell Motherboard: AMD CPU: None Brand: Dell Motherboard: AMD CPU: Ryzen 5 ---------- Note the effect of accessor and mutator methods below ---------- Using accessor method for the object comp7 - the value of Brand = Dell Using accessor method for the object comp7 - the value of Motherboard = AMD Using accessor method for the object comp7 - the value of CPU = Ryzen 5 Using mutator method for the object comp7 - the new value of Brand = None Using mutator method for the object comp7 - the new value of Motherboard = None Using mutator method for the object comp7 - the new value of CPU = None ---------- Note the effect of accessor and mutator methods above ---------- ---------- Starting to destroy objects ---------- The object with the brand None with a None motherboard and None CPU was destroyed. The object with the brand HP with a None motherboard and None CPU was destroyed. The object with the brand HP with a Intel motherboard and None CPU was destroyed. The object with the brand HP with a Intel motherboard and i3 CPU was destroyed. The object with the brand Dell with a None motherboard and None CPU was destroyed. The object with the brand Dell with a AMD motherboard and None CPU was destroyed. The object with the brand Lenovo with a Asus motherboard and Intel i7 CPU was destroyed.

GP_08_Computer_v08

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v08.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) Each instance has its own attributes """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu displayComputer(): To display object ''' class Computer: # Class variable to keep track of number of instantiated objects. Shared by all instances compCountAdded = 0 # Constructor def __init__(self, brand='None', motherboard='None', cpu='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu Computer.compCountAdded += 1 # Destructor def __del__(self): print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard and', self.cpu, 'CPU was destroyed.') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard def setCPU(self, cpu): self.cpu = cpu # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu, '\t' ', ', Computer.compCountAdded, 'object(s) instantiated.') def displayCount(self): print('\nTotal Object (Computers) Instantiated so far: ', Computer.compCountAdded, '\n') # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() # Non-default constructor comp2 = Computer('HP') comp2.displayComputer() comp3 = Computer('HP', 'Intel') comp3.displayComputer() comp4 = Computer('HP', 'Intel', 'i3') comp4.displayComputer() # This instantiates second set of objects # Non-default constructor comp5 = Computer('Dell') comp5.displayComputer() comp6 = Computer('Dell', 'AMD') comp6.displayComputer() comp7 = Computer('Dell', 'AMD', 'Ryzen 5') comp7.displayComputer() # displayCount() shows the total number of objects instantiated so far. comp7.displayCount() # Using accessor methods print('---------- Note the effect of accessor and mutator methods below \ ----------') print('\nUsing accessor method for the object comp7 - the value of Brand = ', comp7.getBrand()) print('Using accessor method for the object comp7 - the value of Motherboard = ', comp7.getMotherboard(), '\n') print('Using accessor method for the object comp7 - the value of CPU = ', comp7.getCPU(), '\n') # Using mutator methods print('\nUsing mutator method for the object comp7 - the new value of Brand = ', comp7.setBrand('Lenovo')) print('Using mutator method for the object comp7 - the new value of Motherboard = ', comp7.setMotherboard('Asus'), '\n') print('Using mutator method for the object comp7 - the new value of CPU = ', comp7.setCPU('Intel i7'), '\n') print('---------- Note the effect of accessor and mutator methods above \ ----------') # Destroying objects print('\n---------- Starting to destroy objects ----------\n') del comp1 del comp2 del comp3 del comp4 del comp5 del comp6 del comp7
Brand: HP Motherboard: None CPU: None , 2 object(s) instantiated. Brand: HP Motherboard: Intel CPU: None , 3 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 , 4 object(s) instantiated. Brand: Dell Motherboard: None CPU: None , 5 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: None , 6 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 , 7 object(s) instantiated. Total Object (Computers) Instantiated so far: 7 ---------- Note the effect of accessor and mutator methods below ---------- Using accessor method for the object comp7 - the value of Brand = Dell Using accessor method for the object comp7 - the value of Motherboard = AMD Using accessor method for the object comp7 - the value of CPU = Ryzen 5 Using mutator method for the object comp7 - the new value of Brand = None Using mutator method for the object comp7 - the new value of Motherboard = None Using mutator method for the object comp7 - the new value of CPU = None ---------- Note the effect of accessor and mutator methods above ---------- ---------- Starting to destroy objects ---------- The object with the brand None with a None motherboard and None CPU was destroyed. The object with the brand HP with a None motherboard and None CPU was destroyed. The object with the brand HP with a Intel motherboard and None CPU was destroyed. The object with the brand HP with a Intel motherboard and i3 CPU was destroyed. The object with the brand Dell with a None motherboard and None CPU was destroyed. The object with the brand Dell with a AMD motherboard and None CPU was destroyed. The object with the brand Lenovo with a Asus motherboard and Intel i7 CPU was destroyed.

GP_08_Computer_v09

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v09py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Class variables: crsCountAdded: It keeps track of number of instantiated objects. crsCountDeleted: It keeps track of number of deleted objects. Both class variables shared by all instances of the class "Computer" Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) RAM: amount of RAM (e.g., 32 GB DDR4) Each instance has its own attributes """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu getRAM(): To access the attribute ram Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu setRAM(): To modify the attribute rams Other methods: displayComputer(): To display object displayCount(): It prints the number of instances instantiated/deleted ''' class Computer: # Class variable to keep track of number of instantiated/deleted objects. Shared by all instances compCountAdded = 0 CompCountDeleted = 0 # Constructor def __init__(self, brand='None', motherboard='None', cpu='None', ram='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu self.ram = ram Computer.compCountAdded += 1 # Destructor def __del__(self): Computer.CompCountDeleted += 1 print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard ', self.cpu, 'CPU and ' , self.ram, 'RAM was destroyed. ', Computer.CompCountDeleted, 'object(S) deleted') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu def getRAM(self): return self.ram # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard def setCPU(self, cpu): self.cpu = cpu def setRAM(self, ram): self.ram = ram # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu, '\t', 'RAM: ', self.ram, '\t', ', ', Computer.compCountAdded, 'object(s) instantiated.') def displayCount(self): print('\nTotal Computers Instantiated: ', Computer.compCountAdded, '\n') # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() # Non-default constructor comp2 = Computer('HP') comp2.displayComputer() comp3 = Computer('HP', 'Intel') comp3.displayComputer() comp4 = Computer('HP', 'Intel', 'i3') comp4.displayComputer() comp5 = Computer('HP', 'Intel', 'i3', '32 GB DDR3') comp5.displayComputer() # This instantiates second set of objects # Non-default constructor comp6 = Computer('Dell') comp6.displayComputer() comp7 = Computer('Dell', 'AMD') comp7.displayComputer() comp8 = Computer('Dell', 'AMD', 'Ryzen 5') comp8.displayComputer() comp9 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4') comp9.displayComputer() ''' The following block of codes placed after each object instantiation to address the problem in the previous version. This signifies the importance of the first logical pattern: Sequence Did you see any problem in the previous version? Is the problem addressed in this version? Yes, the problem was using the method Computer.displayCourse() at the end after instantiating all objects can cause difficulties when troubleshooting compared to now calling the method after each instantiated an object to better address the issues more efficiently. ''' ##comp1.displayComputer() ##comp2.displayComputer() ##comp3.displayComputer() ##comp4.displayComputer() ##comp5.displayComputer() ##comp6.displayComputer() ##comp7.displayComputer() # displayCount() shows the total number of objects instantiated so far. comp7.displayCount() # Using accessor methods print('---------- Note the effect of accessor and mutator methods below \ ----------') print('\nUsing accessor method for the object comp9 - the value of Brand = ', comp9.getBrand()) print('Using accessor method for the object comp9 - the value of Motherboard = ', comp9.getMotherboard(), '\n') print('Using accessor method for the object comp9 - the value of CPU = ', comp9.getCPU(), '\n') print('Using accessor method for the object comp9 - the value of RAM = ', comp9.getRAM(), '\n') # Using mutator methods print('\nUsing mutator method for the object comp9 - the new value of Brand = ', comp9.setBrand('Lenovo')) print('Using mutator method for the object comp9 - the new value of Motherboard = ', comp9.setMotherboard('Asus'), '\n') print('Using mutator method for the object comp9 - the new value of CPU = ', comp9.setCPU('Intel i7'), '\n') print('Using mutator method for the object comp9 - the new value of RAM = ', comp9.setRAM('32 GB DDR4'), '\n') print('---------- Note the effect of accessor and mutator methods above \ ----------') # Destroying objects print('\n---------- Starting to destroy objects ----------\n') del comp1 del comp2 del comp3 del comp4 del comp5 del comp6 del comp7 del comp8 del comp9
Brand: HP Motherboard: None CPU: None RAM: None , 2 object(s) instantiated. Brand: HP Motherboard: Intel CPU: None RAM: None , 3 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: None , 4 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 , 5 object(s) instantiated. Brand: Dell Motherboard: None CPU: None RAM: None , 6 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: None RAM: None , 7 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: None , 8 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 , 9 object(s) instantiated. Total Computers Instantiated: 9 ---------- Note the effect of accessor and mutator methods below ---------- Using accessor method for the object comp9 - the value of Brand = Dell Using accessor method for the object comp9 - the value of Motherboard = AMD Using accessor method for the object comp9 - the value of CPU = Ryzen 5 Using accessor method for the object comp9 - the value of RAM = 16 GB DDR4 Using mutator method for the object comp9 - the new value of Brand = None Using mutator method for the object comp9 - the new value of Motherboard = None Using mutator method for the object comp9 - the new value of CPU = None Using mutator method for the object comp9 - the new value of RAM = None ---------- Note the effect of accessor and mutator methods above ---------- ---------- Starting to destroy objects ---------- The object with the brand None with a None motherboard None CPU and None RAM was destroyed. 1 object(S) deleted The object with the brand HP with a None motherboard None CPU and None RAM was destroyed. 2 object(S) deleted The object with the brand HP with a Intel motherboard None CPU and None RAM was destroyed. 3 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU and None RAM was destroyed. 4 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU and 32 GB DDR3 RAM was destroyed. 5 object(S) deleted The object with the brand Dell with a None motherboard None CPU and None RAM was destroyed. 6 object(S) deleted The object with the brand Dell with a AMD motherboard None CPU and None RAM was destroyed. 7 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU and None RAM was destroyed. 8 object(S) deleted The object with the brand Lenovo with a Asus motherboard Intel i7 CPU and 32 GB DDR4 RAM was destroyed. 9 object(S) deleted

GP_08_Computer_v10

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v10.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Class variables: crsCountAdded: It keeps track of number of instantiated objects. crsCountDeleted: It keeps track of number of deleted objects. Both class variables shared by all instances of the class "Computer" Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) RAM: amount of RAM (e.g., 32 GB DDR4) HD: size and type of hard disk drive (e.g., 1 TB NVMe SSD) Each instance has its own attributes """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu getRAM(): To access the attribute ram getHD(): To access the attribute hd Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu setRAM(): To modify the attribute ram setHD(): To modify the attribute hd Other methods: displayComputer(): To display object displayCount(): It prints the number of instances instantiated/deleted ''' class Computer: # Class variable to keep track of number of instantiated/deleted objects. Shared by all instances compCountAdded = 0 compCountDeleted = 0 # Constructor def __init__(self, brand='None', motherboard='None', cpu='None', ram='None', hd='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu self.ram = ram self.hd = hd Computer.compCountAdded += 1 # Destructor def __del__(self): Computer.compCountDeleted += 1 print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard ', self.cpu, 'CPU ', self.ram, 'RAM and ', self.hd, 'was destroyed. ', Computer.compCountDeleted, 'object(S) deleted') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu def getRAM(self): return self.ram def getHD(self): return self.hd # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard def setCPU(self, cpu): self.cpu = cpu def setRAM(self, ram): self.ram = ram def setHD(self, hd): self.hd = hd # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu, '\t', 'RAM: ', self.ram, '\t', 'Hard Disk: ', self.hd, ', ', Computer.compCountAdded, 'object(s) instantiated.') def displayCount(self, c): if c == 'a': print('\nTotal Objects (Computers) Instantiated so far: ', Computer.compCountAdded) else: print('\nTotal Object (Computers) Deleted so far: ', Computer.compCountDeleted) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() # Non-default constructor comp2 = Computer('HP') comp2.displayComputer() comp3 = Computer('HP', 'Intel') comp3.displayComputer() comp4 = Computer('HP', 'Intel', 'i3') comp4.displayComputer() comp5 = Computer('HP', 'Intel', 'i3', '32 GB DDR3') comp5.displayComputer() comp6 = Computer('HP', 'Intel', 'i3', '32 GB DDR3', '500GB NVME SSD') comp6.displayComputer() # This instantiates second set of objects # Non-default constructor comp7 = Computer('Dell') comp7.displayComputer() comp8 = Computer('Dell', 'AMD') comp8.displayComputer() comp9 = Computer('Dell', 'AMD', 'Ryzen 5') comp9.displayComputer() comp10 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4') comp10.displayComputer() comp11 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4', '1 TB HDD') comp11.displayComputer() ''' The following block of codes placed after each object instantiation to address the problem in the previous version. This signifies the importance of the first logical pattern: Sequence Did you see any problem in the previous version? Is the problem addressed in this version? Yes, the problem was using the method Computer.displayCourse() at the end after instantiating all objects can cause difficulties when troubleshooting compared to now calling the method after each instantiated an object to better address the issues more efficiently. ''' ##comp1.displayComputer() ##comp2.displayComputer() ##comp3.displayComputer() ##comp4.displayComputer() ##comp5.displayComputer() ##comp6.displayComputer() ##comp7.displayComputer() # displayCount() shows the total number of objects instantiated/deleted so far based on argument given. comp11.displayCount('a') print('\n--------------------------------------------\n') # Using accessor methods print('---------- Note the effect of accessor and mutator methods below \ ----------') print('\nUsing accessor method for the object comp11 - the value of Brand = ', comp11.getBrand()) print('Using accessor method for the object comp11 - the value of Motherboard = ', comp11.getMotherboard(), '\n') print('Using accessor method for the object comp11 - the value of CPU = ', comp11.getCPU(), '\n') print('Using accessor method for the object comp11 - the value of RAM = ', comp11.getRAM(), '\n') print('Using accessor method for the object comp11 - the value of HD = ', comp11.getHD(), '\n') # Using mutator methods print('\nUsing mutator method for the object comp11 - the new value of Brand = ', comp11.setBrand('Lenovo')) print('Using mutator method for the object comp11 - the new value of Motherboard = ', comp11.setMotherboard('Asus'), '\n') print('Using mutator method for the object comp11 - the new value of CPU = ', comp11.setCPU('Intel i7'), '\n') print('Using mutator method for the object comp11 - the new value of RAM = ', comp11.setRAM('32 GB DDR4'), '\n') print('Using mutator method for the object comp11 - the new value of HD = ', comp11.setHD('1 TB NVME SSD'), '\n') print('---------- Note the effect of accessor and mutator methods above \ ----------') # Destroying objects print('\n---------- Starting to destroy objects ----------\n') del comp1 del comp2 del comp3 del comp4 del comp5 del comp6 del comp7 del comp8 del comp9 del comp10 comp11.displayCount('d') del comp11 print('Total Courses Deleted: ', Computer.compCountDeleted)
Brand: HP Motherboard: None CPU: None RAM: None Hard Disk: None , 2 object(s) instantiated. Brand: HP Motherboard: Intel CPU: None RAM: None Hard Disk: None , 3 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: None Hard Disk: None , 4 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: None , 5 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: 500GB NVME SSD , 6 object(s) instantiated. Brand: Dell Motherboard: None CPU: None RAM: None Hard Disk: None , 7 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: None RAM: None Hard Disk: None , 8 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: None Hard Disk: None , 9 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: None , 10 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: 1 TB HDD , 11 object(s) instantiated. Total Objects (Courses) Instantiated so far: 11 -------------------------------------------- ---------- Note the effect of accessor and mutator methods below ---------- Using accessor method for the object comp11 - the value of Brand = Dell Using accessor method for the object comp11 - the value of Motherboard = AMD Using accessor method for the object comp11 - the value of CPU = Ryzen 5 Using accessor method for the object comp11 - the value of RAM = 16 GB DDR4 Using accessor method for the object comp11 - the value of HD = 1 TB HDD Using mutator method for the object comp11 - the new value of Brand = None Using mutator method for the object comp11 - the new value of Motherboard = None Using mutator method for the object comp11 - the new value of CPU = None Using mutator method for the object comp11 - the new value of RAM = None Using mutator method for the object comp11 - the new value of HD = None ---------- Note the effect of accessor and mutator methods above ---------- ---------- Starting to destroy objects ---------- The object with the brand None with a None motherboard None CPU None RAM and None was destroyed. 1 object(S) deleted The object with the brand HP with a None motherboard None CPU None RAM and None was destroyed. 2 object(S) deleted The object with the brand HP with a Intel motherboard None CPU None RAM and None was destroyed. 3 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU None RAM and None was destroyed. 4 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM and None was destroyed. 5 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM and 500GB NVME SSD was destroyed. 6 object(S) deleted The object with the brand Dell with a None motherboard None CPU None RAM and None was destroyed. 7 object(S) deleted The object with the brand Dell with a AMD motherboard None CPU None RAM and None was destroyed. 8 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU None RAM and None was destroyed. 9 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM and None was destroyed. 10 object(S) deleted Total Object (Courses) Deleted so far: 10 The object with the brand Lenovo with a Asus motherboard Intel i7 CPU 32 GB DDR4 RAM and 1 TB NVME SSD was destroyed. 11 object(S) deleted Total Courses Deleted: 11

GP_08_Computer_v11

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v11.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Class variables: crsCountAdded: It keeps track of number of instantiated objects. crsCountDeleted: It keeps track of number of deleted objects. Both class variables shared by all instances of the class "Computer" Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) RAM: amount of RAM (e.g., 32 GB DDR4) HD: size and type of hard disk drive (e.g., 1 TB NVMe SSD) GPU: graphics processing unit (e.g., NVIDIA GeForce RTX 3080) Each instance has its own attributes """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu getRAM(): To access the attribute ram getHD(): To access the attribute hd getGPU(): To access the attribute gpu Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu setRAM(): To modify the attribute ram setHD(): To modify the attribute hd setGPU(): To modify the attribute gpu Other methods: displayComputer(): To display object displayCount(): It prints the number of instances instantiated/deleted ''' class Computer: # Class variable to keep track of number of instantiated/deleted objects. Shared by all instances compCountAdded = 0 compCountDeleted = 0 # Constructor def __init__(self, brand='None', motherboard='None', cpu='None', ram='None', hd='None', gpu='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu self.ram = ram self.hd = hd self.gpu = gpu Computer.compCountAdded += 1 # Destructor def __del__(self): Computer.compCountDeleted += 1 print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard ', self.cpu, 'CPU ', self.ram, 'RAM ', self.hd, 'and ', self.gpu, 'GPU was destroyed. ', Computer.compCountDeleted, 'object(S) deleted') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu def getRAM(self): return self.ram def getHD(self): return self.hd def getGPU(self): return self.gpu # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand def setMotherboard(self, motherboard): self.motherboard = motherboard def setCPU(self, cpu): self.cpu = cpu def setRAM(self, ram): self.ram = ram def setHD(self, hd): self.hd = hd def setGPU(self, gpu): self.gpu = gpu # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu, '\t', 'RAM: ', self.ram, '\t', 'Hard Disk: ', self.hd, '\t', 'GPU: ', self.gpu, '\t', ', ', Computer.compCountAdded, 'object(s) instantiated.') def displayCount(self, c): if c == 'a': print('\nTotal Computers Instantiated so far: ', Computer.compCountAdded) else: print('\nTotal Computers Deleted so far: ', Computer.compCountDeleted) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- # This instantiates a computer object # Default constructor comp1 = Computer() # Non-default constructor comp2 = Computer('HP') comp2.displayComputer() # Non-default constructor comp3 = Computer('HP', 'Intel') comp3.displayComputer() # Non-default constructor comp4 = Computer('HP', 'Intel', 'i3') comp4.displayComputer() # Non-default constructor comp5 = Computer('HP', 'Intel', 'i3', '32 GB DDR3') comp5.displayComputer() # Non-default constructor comp6 = Computer('HP', 'Intel', 'i3', '32 GB DDR3', '500GB NVME SSD') comp6.displayComputer() # Non-default constructor comp7 = Computer('HP', 'Intel', 'i3', '32 GB DDR3', '500GB NVME SSD', 'GTX 1080 TI') comp7.displayComputer() # Changing attributes' values using attributes' names. This is NOT recommended print("\n----- New Attributes' Values using attributes' names instead of mutator method -----") comp4.brand = 'Acer' comp4.displayComputer() print("----- New attribute's value is (Using Attributes' Names): -----\nBrand: {}".format(comp4.brand)) print("----- New attributes' values are (Using Getter Methods): -----\nBrand: {}\n".format(comp4.getBrand())) # This instantiates second set of objects # Non-default constructor comp8 = Computer('Dell') comp8.displayComputer() # Non-default constructor comp9 = Computer('Dell', 'AMD') comp9.displayComputer() # Non-default constructor comp10 = Computer('Dell', 'AMD', 'Ryzen 5') comp10.displayComputer() # Non-default constructor comp11 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4') comp11.displayComputer() # Non-default constructor comp12 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4', '1 TB HDD') comp12.displayComputer() # Non-default constructor comp13 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4', '1 TB HDD', 'GTX 2060') comp13.displayComputer() ''' The following block of codes placed after each object instantiation to address the problem in the previous version. This signifies the importance of the first logical pattern: Sequence Did you see any problem in the previous version? Is the problem addressed in this version? Yes, the problem was using the method Computer.displayCourse() at the end after instantiating all objects can cause difficulties when troubleshooting compared to now calling the method after each instantiated an object to better address the issues more efficiently. ''' ##comp1.displayComputer() ##comp2.displayComputer() ##comp3.displayComputer() ##comp4.displayComputer() ##comp5.displayComputer() ##comp6.displayComputer() ##comp7.displayComputer() # displayCount() shows the total number of objects instantiated/deleted so far based on argument given. comp13.displayCount('a') print('\n--------------------------------------------\n') # Destroying objects print('\n---------- Starting to destroy objects ----------\n') del comp1 del comp2 del comp3 del comp4 del comp5 del comp6 del comp7 del comp8 del comp9 del comp10 del comp11 del comp12 comp13.displayCount('d') del comp13 print('Total Courses Deleted: ', Computer.compCountDeleted)
Brand: HP Motherboard: None CPU: None RAM: None Hard Disk: None GPU: None , 2 object(s) instantiated. Brand: HP Motherboard: Intel CPU: None RAM: None Hard Disk: None GPU: None , 3 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: None Hard Disk: None GPU: None , 4 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: None GPU: None , 5 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: 500GB NVME SSD GPU: None , 6 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: 500GB NVME SSD GPU: GTX 1080 TI , 7 object(s) instantiated. ----- New Attributes' Values using attributes' names instead of mutator method ----- Brand: Acer Motherboard: Intel CPU: i3 RAM: None Hard Disk: None GPU: None , 7 object(s) instantiated. ----- New attribute's value is (Using Attributes' Names): ----- Brand: Acer ----- New attributes' values are (Using Getter Methods): ----- Brand: Acer Brand: Dell Motherboard: None CPU: None RAM: None Hard Disk: None GPU: None , 8 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: None RAM: None Hard Disk: None GPU: None , 9 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: None Hard Disk: None GPU: None , 10 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: None GPU: None , 11 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: 1 TB HDD GPU: None , 12 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: 1 TB HDD GPU: GTX 2060 , 13 object(s) instantiated. Total Computers Instantiated so far: 13 -------------------------------------------- ---------- Starting to destroy objects ---------- The object with the brand None with a None motherboard None CPU None RAM None and None GPU was destroyed. 1 object(S) deleted The object with the brand HP with a None motherboard None CPU None RAM None and None GPU was destroyed. 2 object(S) deleted The object with the brand HP with a Intel motherboard None CPU None RAM None and None GPU was destroyed. 3 object(S) deleted The object with the brand Acer with a Intel motherboard i3 CPU None RAM None and None GPU was destroyed. 4 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM None and None GPU was destroyed. 5 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM 500GB NVME SSD and None GPU was destroyed. 6 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM 500GB NVME SSD and GTX 1080 TI GPU was destroyed. 7 object(S) deleted The object with the brand Dell with a None motherboard None CPU None RAM None and None GPU was destroyed. 8 object(S) deleted The object with the brand Dell with a AMD motherboard None CPU None RAM None and None GPU was destroyed. 9 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU None RAM None and None GPU was destroyed. 10 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM None and None GPU was destroyed. 11 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM 1 TB HDD and None GPU was destroyed. 12 object(S) deleted Total Computers Deleted so far: 12 The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM 1 TB HDD and GTX 2060 GPU was destroyed. 13 object(S) deleted Total Courses Deleted: 13

GP_08_Computer_v12

# This program declares class "Computer" """ CS V13: Object-Oriented Programming Section: 31239 Group Members: 1. Team Coordinator: Martin Delgado 2. Jalen Ellis Purpose: To instantiate a class called "computer" with attributes and methods for Group Project 8 Program Name: GP-08-Computer-v012.py Martin Delgado, Jalen Ellis copyright © 2021 CS V13 Team 2 """ # ------------------------- start of class Computer ------------------------- """ Class variables: crsCountAdded: It keeps track of number of instantiated objects. crsCountDeleted: It keeps track of number of deleted objects. Both class variables shared by all instances of the class "Computer" Attributes: Brand: computer brand (e.g., HP) Motherboard: motherboard model (e.g., ASUS Z590-A) CPU: CPU model (e.g., Intel Core i9-11900K) RAM: amount of RAM (e.g., 32 GB DDR4) HD: size and type of hard disk drive (e.g., 1 TB NVMe SSD) GPU: graphics processing unit (e.g., NVIDIA GeForce RTX 3080) OS: operating system (e.g., Windows 10 Home) Each instance has its own attributes """ ''' Methods: __init__(): To initialize attributes __del__(): To destroy objects Accessor methods: getBrand(): To access the attribute brand getMotherboard(): To access the attribute motherboard getCPU(): To access the attribute cpu getRAM(): To access the attribute ram getHD(): To access the attribute hd getGPU(): To access the attribute gpu getOS(): To access the attribute os Mutator methods: setBrand(): To modify the attribute brand setMotherboard(): To modify the attribute motherboard setCPU(): To modify the attribute cpu setRAM(): To modify the attribute ram setHD(): To modify the attribute hd setGPU(): To modify the attribute gpu setOS(): To modify the attribute os Other methods: displayComputer(): To display object displayCount(): It prints the number of instances instantiated/deleted ''' class Computer: # Class variable to keep track of number of instantiated/deleted objects. Shared by all instances compCountAdded = 0 compCountDeleted = 0 # Constructor def __init__(self, brand='None', motherboard='None', cpu='None', ram='None', hd='None', gpu='None', os='None'): self.brand = brand self.motherboard = motherboard self.cpu = cpu self.ram = ram self.hd = hd self.gpu = gpu self.os = os Computer.compCountAdded += 1 # Destructor def __del__(self): Computer.compCountDeleted += 1 print('The object with the brand ', self.brand, 'with a ', self.motherboard, 'motherboard ', self.cpu, 'CPU ', self.ram, 'RAM ', self.hd, 'with a ', self.gpu, 'GPU and ', self.os, 'as the operating system was destroyed. ', Computer.compCountDeleted, 'object(S) deleted') # Accessor method(s) ------------------------------------- def getBrand(self): return self.brand def getMotherboard(self): return self.motherboard def getCPU(self): return self.cpu def getRAM(self): return self.ram def getHD(self): return self.hd def getGPU(self): return self.gpu def getOS(self): return self.os # Mutator method(s) --------------------------------------- def setBrand(self, brand): self.brand = brand return self.brand def setMotherboard(self, motherboard): self.motherboard = motherboard return self.motherboard def setCPU(self, cpu): self.cpu = cpu return self.cpu def setRAM(self, ram): self.ram = ram return self.ram def setHD(self, hd): self.hd = hd return self.hd def setGPU(self, gpu): self.gpu = gpu return self.gpu def setOS(self, os): self.os = os return self.os # Other methods ------------------------------------------- def displayComputer(self): print('Brand: ', self.brand, '\t', 'Motherboard: ', self.motherboard, '\t', 'CPU: ', self.cpu, '\t', 'RAM: ', self.ram, '\t', 'Hard Disk: ', self.hd, '\t', 'GPU: ', self.gpu, '\t', 'Operating System: ', self.os, ', ', Computer.compCountAdded, 'object(s) instantiated.') # Allows method to take 'a' as an argument and display instantiated objects and any other argument gives # the Computers deleted so far. def displayCount(self, c): if c == 'a': print('\nTotal Computers Instantiated so far: ', Computer.compCountAdded) else: print('\nTotal Computers Deleted so far: ', Computer.compCountDeleted) # End of Class Computer # ------------------------- end of class Computer ------------------------- # ------------------------- test the class ------------------------- def main(): # This instantiates a computer object # Default constructor comp1 = Computer() comp1.displayComputer() # Non-default constructor comp2 = Computer('HP') comp2.displayComputer() comp3 = Computer('HP', 'Intel') comp3.displayComputer() comp4 = Computer('HP', 'Intel', 'i3') comp4.displayComputer() comp5 = Computer('HP', 'Intel', 'i3', '32 GB DDR3') comp5.displayComputer() comp6 = Computer('HP', 'Intel', 'i3', '32 GB DDR3', '500GB NVME SSD') comp6.displayComputer() comp7 = Computer('HP', 'Intel', 'i3', '32 GB DDR3', '500GB NVME SSD', 'GTX 1080 TI') comp7.displayComputer() comp8 = Computer('HP', 'Intel', 'i3', '32 GB DDR3', '500GB NVME SSD', 'GTX 1080 TI', 'Windows 10 Home') comp8.displayComputer() # Changing attributes' values using attributes' names. This is NOT recommended print("\n----- New Attributes' Values using attributes' names instead of mutator method -----") comp4.brand = 'Acer' comp4.displayComputer() print("----- New attribute's value is (Using Attributes' Names): -----\nCredit Hours: {0}".format(comp4.brand)) print("----- New attributes' values are (Using Getter Methods): -----\nCredit Hours: {0}\n".format (comp4.getBrand())) # This instantiates second set of objects # Non-default constructor comp9 = Computer('Dell') comp9.displayComputer() comp10 = Computer('Dell', 'AMD') comp10.displayComputer() comp11 = Computer('Dell', 'AMD', 'Ryzen 5') comp11.displayComputer() comp12 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4') comp12.displayComputer() comp13 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4', '1 TB HDD') comp13.displayComputer() comp14 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4', '1 TB HDD', 'GTX 2060') comp14.displayComputer() comp15 = Computer('Dell', 'AMD', 'Ryzen 5', '16 GB DDR4', '1 TB HDD', 'GTX 2060', 'Ubuntu') comp15.displayComputer() ''' The following block of codes placed after each object instantiation to address the problem in the previous version. This signifies the importance of the first logical pattern: Sequence Did you see any problem in the previous version? Is the problem addressed in this version? Yes, the use of an if else statement helped allow the function displayCount() be used to show the count of instantiated or deleted objects based on given argument. ''' # comp1.displayComputer() # comp2.displayComputer() # comp3.displayComputer() # comp4.displayComputer() # comp5.displayComputer() # comp6.displayComputer() # comp7.displayComputer() # comp8.displayComputer() # comp9.displayComputer() # comp10.displayComputer() # comp11.displayComputer() # comp12.displayComputer() # comp13.displayComputer() # comp14.displayComputer() # comp15.displayComputer() # displayCount() shows the total number of objects instantiated/deleted so far based on argument given. comp15.displayCount('a') print('\n--------------------------------------------\n') # Destroying objects print('\n---------- Starting to destroy objects ----------\n') del comp1 del comp2 del comp3 del comp4 del comp5 del comp6 del comp7 del comp8 del comp9 del comp10 del comp11 del comp12 del comp13 del comp14 comp15.displayCount('d') del comp15 print('Total Courses Deleted: ', Computer.compCountDeleted) main()
Brand: None Motherboard: None CPU: None RAM: None Hard Disk: None GPU: None Operating System: None , 1 object(s) instantiated. Brand: HP Motherboard: None CPU: None RAM: None Hard Disk: None GPU: None Operating System: None , 2 object(s) instantiated. Brand: HP Motherboard: Intel CPU: None RAM: None Hard Disk: None GPU: None Operating System: None , 3 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: None Hard Disk: None GPU: None Operating System: None , 4 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: None GPU: None Operating System: None , 5 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: 500GB NVME SSD GPU: None Operating System: None , 6 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: 500GB NVME SSD GPU: GTX 1080 TI Operating System: None , 7 object(s) instantiated. Brand: HP Motherboard: Intel CPU: i3 RAM: 32 GB DDR3 Hard Disk: 500GB NVME SSD GPU: GTX 1080 TI Operating System: Windows 10 Home , 8 object(s) instantiated. ----- New Attributes' Values using attributes' names instead of mutator method ----- Brand: Acer Motherboard: Intel CPU: i3 RAM: None Hard Disk: None GPU: None Operating System: None , 8 object(s) instantiated. ----- New attribute's value is (Using Attributes' Names): ----- Credit Hours: Acer ----- New attributes' values are (Using Getter Methods): ----- Credit Hours: Acer Brand: Dell Motherboard: None CPU: None RAM: None Hard Disk: None GPU: None Operating System: None , 9 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: None RAM: None Hard Disk: None GPU: None Operating System: None , 10 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: None Hard Disk: None GPU: None Operating System: None , 11 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: None GPU: None Operating System: None , 12 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: 1 TB HDD GPU: None Operating System: None , 13 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: 1 TB HDD GPU: GTX 2060 Operating System: None , 14 object(s) instantiated. Brand: Dell Motherboard: AMD CPU: Ryzen 5 RAM: 16 GB DDR4 Hard Disk: 1 TB HDD GPU: GTX 2060 Operating System: Ubuntu , 15 object(s) instantiated. Total Computers Instantiated so far: 15 -------------------------------------------- ---------- Starting to destroy objects ---------- The object with the brand None with a None motherboard None CPU None RAM None with a None GPU and None as the operating system was destroyed. 1 object(S) deleted The object with the brand HP with a None motherboard None CPU None RAM None with a None GPU and None as the operating system was destroyed. 2 object(S) deleted The object with the brand HP with a Intel motherboard None CPU None RAM None with a None GPU and None as the operating system was destroyed. 3 object(S) deleted The object with the brand Acer with a Intel motherboard i3 CPU None RAM None with a None GPU and None as the operating system was destroyed. 4 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM None with a None GPU and None as the operating system was destroyed. 5 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM 500GB NVME SSD with a None GPU and None as the operating system was destroyed. 6 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM 500GB NVME SSD with a GTX 1080 TI GPU and None as the operating system was destroyed. 7 object(S) deleted The object with the brand HP with a Intel motherboard i3 CPU 32 GB DDR3 RAM 500GB NVME SSD with a GTX 1080 TI GPU and Windows 10 Home as the operating system was destroyed. 8 object(S) deleted The object with the brand Dell with a None motherboard None CPU None RAM None with a None GPU and None as the operating system was destroyed. 9 object(S) deleted The object with the brand Dell with a AMD motherboard None CPU None RAM None with a None GPU and None as the operating system was destroyed. 10 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU None RAM None with a None GPU and None as the operating system was destroyed. 11 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM None with a None GPU and None as the operating system was destroyed. 12 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM 1 TB HDD with a None GPU and None as the operating system was destroyed. 13 object(S) deleted The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM 1 TB HDD with a GTX 2060 GPU and None as the operating system was destroyed. 14 object(S) deleted Total Computers Deleted so far: 14 The object with the brand Dell with a AMD motherboard Ryzen 5 CPU 16 GB DDR4 RAM 1 TB HDD with a GTX 2060 GPU and Ubuntu as the operating system was destroyed. 15 object(S) deleted Total Courses Deleted: 15