The steelwork.py program, given below, creates three types of steel objects. Carbon steel (Steel) is made of carbon and iron, alloy steel (AlloySteel) contains chromium in addition to carbon and iron. Stainless steel (StainlessSteel) contains nickel and a higher proportion of chromium.  Write the missing code, in the designated locations (#TODO), in order for the program execution to yield the following output:   ['Steel01', 0.6, 91] ['ALSteel02', 0.6, 91, 1] ['SSteel02', 0.6, 91, 11, 2]

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

The steelwork.py program, given below, creates three types of steel objects. Carbon steel (Steel) is made of carbon and iron, alloy steel (AlloySteel) contains chromium in addition to carbon and iron. Stainless steel (StainlessSteel) contains nickel and a higher proportion of chromium.  Write the missing code, in the designated locations (#TODO), in order for the program execution to yield the following output:

 

['Steel01', 0.6, 91]

['ALSteel02', 0.6, 91, 1]

['SSteel02', 0.6, 91, 11, 2]

# steelwork .py
A# Author : Youcef Derbal
2
el class Steel:
def -_init__(self,*args, **kwargs):
# TODO Complete code for the __init__ method
6
7
def tostring(self):
8
return [self.code, self.carbon,self.iron]
10
@classmethod
11
def factory(cls,*args):
n = len(args)
if n == 3:
12
13
14
return Steel(*args)
15
elif n == 4:
16
return Alloysteel(*args)
17
elif n == 5:
18
return StainlessSteel(*args)
19
el class Alloysteel(Steel):
20
21
# TODO Add code for the -_init__ method
22
23 l of
def tostring(self):
return super(Alloysteel, self).tostring()+ [self.chromium]
24
25
26
eclass StainlessSteel(AlloySteel):
27
# TODO Add code for the _init__ method
28
29
of a
def tostring(self):
return super(StainlessSteel, self).tostring()+ [self.nickel]
30
31
s1 = Steel.factory('Steel01',0.6,91)
s2 = Steel.factory(1, 'ALSteel02',0.6,91)
s3 = Steel.factory(2,11,'SSteel02',0.6,91)
32
33
34
35
36
print(s1.tostring())
37
print(s2.tostring())
38
print(s3.tostring())
Transcribed Image Text:# steelwork .py A# Author : Youcef Derbal 2 el class Steel: def -_init__(self,*args, **kwargs): # TODO Complete code for the __init__ method 6 7 def tostring(self): 8 return [self.code, self.carbon,self.iron] 10 @classmethod 11 def factory(cls,*args): n = len(args) if n == 3: 12 13 14 return Steel(*args) 15 elif n == 4: 16 return Alloysteel(*args) 17 elif n == 5: 18 return StainlessSteel(*args) 19 el class Alloysteel(Steel): 20 21 # TODO Add code for the -_init__ method 22 23 l of def tostring(self): return super(Alloysteel, self).tostring()+ [self.chromium] 24 25 26 eclass StainlessSteel(AlloySteel): 27 # TODO Add code for the _init__ method 28 29 of a def tostring(self): return super(StainlessSteel, self).tostring()+ [self.nickel] 30 31 s1 = Steel.factory('Steel01',0.6,91) s2 = Steel.factory(1, 'ALSteel02',0.6,91) s3 = Steel.factory(2,11,'SSteel02',0.6,91) 32 33 34 35 36 print(s1.tostring()) 37 print(s2.tostring()) 38 print(s3.tostring())
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT