Question: IKEA.txt: python problem!! no further data is given modify the below given coding: Furniture - models an IKEA furniture item; considered abstract, as by

IKEA.txt:







python problem!! no further data is given modify the below given coding:
""" Furniture - models an IKEA furniture item; considered abstract, as by itself, it is meaningless as it doesn't include everything needed.
ALL CODE IN THIS LAB: Author: C.R. Vessey, SMCS Date: 17-FEB-2021 """ class Furniture: def __init__(self, s_type, s_artnum, f_price, s_name, s_desc, s_colour): # Assume that fully private instance variables will be made using # these parameter names, but without the "s_" or "f_" prefix. # "s_" denotes a string type parameter, "f_" a float. # Complete the constructor (replace these comments with appropriate code)
def __str__(self): return "Type: " + self.__type + \ " \tName: " + self.__name + \ " \tArticle: " + self.__artnum + \ " \tPrice: " + f"{self.__price:.2f}" + \ " \tDescription: " + self.__desc + \ " \tColour: " + self.__colour
def setPrice(self, p_price): # add code to set the price
def getPrice(self): # add code to return the price
""" Armchair - models an IKEA armchair, which is a type of Furniture.
Collects all data used by Furniture, which it extends, as well as data specific to this object.
Uses the superclass __init__ and superclass __str__ method to accomplish its tasks.
NOTE: This class is FULLY COMPLETE. It's intended to be an example for the other classes which you will be completing on your own. """
class Armchair(Furniture): def __init__(self, s_artnum, f_price, s_name, s_desc, s_colour, \ f_width, f_depth, f_height, f_seat_width, f_seat_depth, f_seat_height): super().__init__("Armchair", s_artnum, f_price, s_name, s_desc, s_colour) self.__width = f_width self.__depth = f_depth self.__height = f_height self.__seat_width = f_seat_width self.__seat_depth = f_seat_depth self.__seat_height = f_seat_height
def __str__(self): return super().__str__() + " \tWidth: " + f"{self.__width:.2f}" + \ " \tDepth: " + f"{self.__depth:.2f}" + \ " \tHeight: " + f"{self.__height:.2f}" + \ " \tSeat Width: " + f"{self.__seat_width:.2f}" + \ " \tSeat Depth: " + f"{self.__seat_depth:.2f}" + \ " \tSeat Height: " + f"{self.__seat_height:.2f}" ### FROM THIS POINT ONWARD, YOU WILL BE WRITING THE CONTENTS OF EACH ENTIRE CLASS ###
""" Bed - models an IKEA bed frame; collects all data used by Furniture, which it extends, as well as data specific to this object. Uses the superclass __init__ and superclass __str__ methods to accomplish its tasks. """
class Bed(Furniture): # write __init__ and __str__ methods appropriate to this
""" Nightstand - models an IKEA nightstand; collects all data used by Furniture, which it extends, as well as data specific to this object. Uses the superclass __init__ and superclass __str__ methods to accomplish its tasks. """
class Nightstand(Furniture): # you write this one's code, too
""" Floorlamp - models an IKEA floorlamp; collects all data used by Furniture, which it extends, as well as data specific to this object. Uses the superclass __init__ and superclass __str__ methods to accomplish its tasks. """
class Floorlamp(Furniture): # and you write the code for this one as well
##### MAIN UNIT TEST CODE - partial code is provided, you write what is indicated #####
""" UNIT TEST FRAMEWORK You have received one example subclass (Armchair), and the rest you will have to complete.
Below, you see partial unit test driver code. Commentary will give you hints as to how things are to be done.
* Tests Task 1 of Lab 2 * Reads data from file, figure out the category, and then creates the appropriate object, putting it into the inventory list.
* Prints out the contents of the inventory, as well as the total value of the inventory. """
# create the inventory list inventory = [] # set up the file to be read file = open("ikea.txt", "r")
# read the data file, and create objects out of what is read # note that this requires identification of the type code, which tells you # what type of object will be created from the data for line in file: data = line.split(",") # get the item type code type_code = data[0].strip().upper() # type codes should all be uppercase # now read the data common to ALL Furniture items (the stuff that Furniture's # __init__ method requires) article_number = data[1].strip() price = float(data[2].strip()) # DO THE SAME FOR NAME, DESCRIPTION, AND COLOUR (data[3] - data[5])
# Now, based on the type code, process the rest of the data and create an appropriate # object based on the data read if type_code == "B": # it's a bed length = float(data[6].strip()) width = float(data[7].strip()) footboard_height = float(data[8].strip()) headboard_height = float(data[9].strip()) inventory.append(Bed(articleNumber, price, name, description, colour, \ length, width, footboard_height, headboard_height)) elif type_code == "N": # it's a nightstand # WRITE CODE FOR THIS elif type_code == "A": # it's an armchair # WRITE CODE FOR THIS elif type_code == "F": # it's a floor lamp # WRITE CODE FOR THIS else: print("ERROR - UNIDENTIFIED TYPE CODE:", type_code)
# SET AN ACCUMULATOR VARIABLE CALLED total_value TO 0
for furniture_item in inventory: print(str(furniture_item)) # print the item print("="*30) # print a separator # ADD THE PRICE OF THE ITEM TO THE ACCUMULATOR VARIABLE
print(" Total Inventory Value:", total_value)
We want to write an inventory program to list some of their quality merchandise! To do this, we want to create a Furniture object. This represents any item at IKEA. Every IKEA product has a base type, an article number, a price, a Swedish-sounding name, a basic description, and optionally, a colour (or blank if there is no colour). Furniture objects should have the ability to store this. Furniture should, of course, be functionally abstract (that is, it would make no sense to instantiate a Furniture object, as it doesn't have all the code needed to make it actually work it is simply a parent class). It needs an accessor and mutator for the price only. F,301.841.73,9.99, HOLM, Floor lamp - gives a soft mood light, *none*,75,116,22,2.2 F,703.047.29,69.99, ANTIFONI, Floor/reading lamp, nickel plated, 6.3,180,24,2.5 F,902.865.69,49.99, SAMTID, Floor/reading lamp, nickel plated/white, 100,152,25,3.5 F,903.498.97,79.99, YPPERLIG, LED floor lamp, dark gray,7,122,15,3.5 A, 102.335.32,49.00, NOLMYRA, Armless mesh chair, black/black,64,75,75,59,46,40 A,500.395.52,69.99, IKEA PS GULLHOLMEN, Rocking chair, banana fibre, 62,68,75,44,47,34 A, 991.256.71,99.00, PONG, Armchair birch veneer, Ransta red, 68,82,100,56,60,42 A, 403.424.88, 199.00, VEDBO, Armchair, Gunnared dark gray, 75,73,65,45,48,44 N, 702.155.25,19.99, NESNA, Nighstand, bamboo,36,35,45 N,443.611.09,19.99, RAST,Nightstand, pine, 52,30,40 N,603.221.30,39.99, KULLEN, 2-Drawer Chest, black-brown, 35,40,49 N,602.360.24,59.99, TRYSIL, Nighstand, dark brown/black,45,40,53 B, 190.098.21,99.00, FJELLSE,Bed frame, Lury pine, 197,142,33,80 B,490.075.66,179.00, BRUSALI,Bed frame, Lury brown, 208,198,46,93 B, 290.077.94, 189.00, TARVA, Bed frame, Lury pine, 209,160,32,92 B,090.078.13, 199.00, TRYSIL,Bed frame, Lury dark brown, 220,157,40,98 We then want to be able to represent subcategories of their products that we would use in a bedroom (rather than everything they make!) These subcategories should extend (that is, inherit from) Furniture. A Bed also has a length, a width, a footboard height, and a headboard height. These will be expressed in cm. A Nightstand also has width, depth and height, all in cm. An Armchair is their word for a chair, whether it has arms or not. These also have a width, depth, and height, seat width, seat depth, and seat height, all in cm. A Floor Lamp also has a maximum wattage in watts), a height, shade diameter, and cord length. Height and shade diameter are in cm, cord length is in m. You'll note the "also" in each of these. This means that they inherit everything that Furniture has, but they will define more things (behaviours, instance variables) specific to the object in question. You don't have to make accessors and mutators for the subclasses - this will save you time, as the product descriptions are fixed. You will have to make a constructor that can take all these parameters, though. You will need to write a _str_magic method for each object. Read the data from the file ikea.txt - the first item on each row tells you the type of object to be created a single letter), and the rest are parameters as listed above. Have a look at the data file and be sure you understand the format. 1. Read the data, create the specified object, and place it into a list of Furniture. Repeat for each item in the data file. 2. Then, print out each object in the list, and print out the total value of the inventory. The data file will be supplied in this case for you to view. You do NOT need to put that data file anywhere in the Moodle CodeRunner question. It already has it - it's just for your reference. Hints: Furniture should store its data in fully private variables. Furniture should have a _str_method to return its data. Subclasses of Furniture must also take, in their _init_ (constructor methods), the parameters used by Furniture. The first line of a subclass constructor must therefore be super().init(parameters_for_Furniture) where you insert the parameters you're passing to Furniture. The subclasses will also take additional information and store them in their own fully private variables. The subclasses will also have __str_magic methods - these can call on the parent (Furniture) _str_method with super(_str_0 to return part of the String, and save you from having to retype the content generated by the _str_ method of the parent. If you look at similarities between some of the subclasses, you'll quickly realize that, after writing the Armchair class, the Nightstand class could be done very quickly with copy and paste, and some editing. Assume all numbers could have fractional components, including any dimensions, prices, etc. . Do not worry about using dollar signs ($) in the price outputs. Just format them to two decimal places. Sample output: Type: Floor lamp Name: HOLMO Articles 301.841.73 Price: 9.99 Description: Floor lamp - gives a soft mood light Colour: none Wattage: 75.00 Height: 116.00 Shade Diameter: 22.00 Cord Length: 2.20 Type: Floor lamp Name: ANTIFONI Article: 703.047.29 Price: 69.99 Description: Floor/reading lamp Colouri nickel plated Wattage i 6.30 Height180.00 Shade Diameter: 24.00 Cord Length: 2.50 SESSE Type: Floor lamp Name: SAMTID Article: 902.865.69 Price: 49.99 Description: Floor/reading lamp Colour: nickel plated/white Wattage: 100.00 Height : 152.00 Shade Diameter: 25.00 Cord Length: 3.50 Type: Floor lamp Name: YPPERLIG Article: 903.498.97 Price: 79.99 Description: LED floor lamp Colour: dark gray Wattage: 7.00 Height : 122.00 Shade Diameter: 15.00 Cord Length: 3.50 ====== Typer Armchair Name: NOLMYRA Article: 102.335.32 Price: 49.00 Description: Armless mesh chair Colour: black/black Width: 64.00 Depthi 75.00 Height: 75.00 Seat Width: 59.00 Seat Depth: 46.00 Seat Height: 40.00 SEEEEEEEEE EEEEEEEEEE Types Armchair Nume: IKEA PS GULLIOLIN Article: 500.395.52 Price: 69.99 Description: Rocking chair Calor: banana tibre Width: 62.00 Depth: 60.00 Height: 75.00 Seat Width 44.00 Seat Depth: 47.00 Seat Height: 34.00 Type Armchair Sume: PONG Article: 991.256.71 PESCE 99.00 Description: Armohair - birch van Colour: Ranata rad Depth: 12.00 eight: 100.00 Seat Width: 56.00 Sest Depth: 60.00 Seat Height: 42.00 Types Armchair Sme VEDNO Article403.424.00 Price: 199.00 Description Armchair Calort Gunnard dark gray Width: 75.00 Depth: 73.00 Height: 65.00 Seat Width: 45.00 Suat Depth: 48.00 Seat Height: 44.00 Type Nightstand W NESRA Article: 702.155.25 Price 19.99 Description: Nightand Color: bamboo Width: 36.00 Depth: 35.00 Height: 45.00 Type: Nightstand S: RAST Articles 443.611.09 Price 19.99 Description: Nightstand Calort pine Width: 52.00 Depth 30.00 Type: Nightstand Nume: KULLEN Article: G03.221.30 Price: 39.99 Description: 2-De Cheat Color: black-brom Width: 35.00 Depth: 10.00 Height: 49.00 Type: Nightstand Nume: TRYSIL Article 602.360.24 Price: 59.99 Description: Highstand Colour: dark brown/black Width: 45.00 Depth: 40.00 Height: 53.00 Type: Sed Article: 190.090.21 Price: 99.00 Description: led frame Colour: Lurdy pise Length: 197.00 Width: 142.00 Headboard height 10.00 Tootboard Height: 33.00 Type: Bed Nume: BRUSALE Article: 490.075.66 Price: 179.00 Description: Bled frame Color: Lurdy bone Length: 208.00 Width: 19.00 Headboard height: 93.00 Footboard Height: 45.00 Type: Bed : TARVA Article: 290.077.94 Price: 119.00 Description: Bed Frame Calor: Lurdy pine Length: 209.00 Width: 160.00 Headboard height: 92.00 Tootboard Height: 32.00 Type: Bed Sume: TRYSIL Article: 090.070.13 Price: 199.00 Description: Med frame Colour: Lurdy dark brown Length: 220.00 Width: 197.00 Headboard height: 10.00 Tootboard Height: 40.00 Total Tventory Value 1432.91 HINTS The hardest part of Task 1 is figuring out how to parse each line. Consider this: after reading the line, you can split it into its components, as they are comma delimited. You can then use the components as arguments to a construction call on a new object of the appropriate type
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
