Question

using python 3:

Program 14: Class with Private Attribute Collection of Objects: modRoom.py Step 1: Create a class called Room as indicated by the UML shown below: Student -length: integer width: integer -height integer -roomNum: integer -roomType: String -room Capacity: integer <<constructor Room (tmpRoomNum:integer tmpRoomType: String, tmpCapacity:integer tmplength: integer, tmpWidth: integer, tmpHeight: integer) +get Length(): Integer +getWidth(): Integer +getHeight(): Integer +get RoomNum(): Integer +getRoom Type(): String +getRoomCapacity(): Integer tRoomType(): String +set +setRoomCapacity(): Integer +calcArea(): Integer +calcSurfaceArea(): nteger +str( String should return a string containing roomNum roomCapacity, roomArea Step 2: Create a testRoomModule.py file that THOROUGHLY tests your Room class. Make sure to LABEL the output so that its easy to see what is being tested Step 3: Create another class called RoomRoster as shown by the UML below, and save it into the same modstudent.py file as the Student class: Room Roster -roomCollection: st of room Objects <<constructor>> Room Roster() +add Room (room obj) void +delRoom (roomObj): integer eturns +1 if successful, -1 if unsuccessful +str String +findRoom (roomNum): Room Object or -1 if not there +findRoomsWithCapacity (tmpCapacity integer): List of Room Objects (-1 if none Step 4: Add code to the testRoomModule.py to THOROUGHLY test the RoomRoster class. Make sure to LABEL the output so that its easy to see what is being tested

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program classRoom: tmpLength, tmpWidth, tmpHeight): def init (self, tmpRoomNum, tmpRoomType,tmpCapacity, self.roomNum - tmpRoomNum self. roomType tmpRoomType self.roomCapacity - tmpCapacity self. lengthtmpLength self.width = tmpwidth self.height- tmpHeight def get RoomNum (self): return self.roomNum def, getRoomCapacity (self): return self.roomCapacit def getLength (self): return self.length def getHeight (self) return self.height def getwidth (self): return self.width def getRoomType (self): return self.roomT ype def setRoomType (self tmpRoomType): s el f . ro omType-trip RoomType def setRoomCapacity (self, tmpRoomCapacity): self.roomCapacity-tmpRoomCapacitdef calArea (self): return (self.length self.widthtself.height) def str (self): return Room Number :+str (self..roomNum)+ndef testRoomModule O: Room roster RoomRoster() room1 = Room (11, Non-AC, 2, 12, 10, 10) room2 = Room (12, AC, 3, 12 , 11,Delete Room Room Number: 11 Room Type: Non-AC Room Capacity:2 Length: 12 Height: 10 Width :10 Area: 1200 Room Number: 13 Room

Editable code

Program

class Room:
   def __init__(self, tmpRoomNum, tmpRoomType, tmpCapacity, tmpLength, tmpWidth, tmpHeight):
       self.roomNum = tmpRoomNum
       self.roomType = tmpRoomType
       self.roomCapacity = tmpCapacity
       self.length = tmpLength
       self.width = tmpWidth
       self.height = tmpHeight
  
   def getRoomNum(self):
       return self.roomNum
  
   def getRoomCapacity(self):
       return self.roomCapacity
  
   def getLength(self):
       return self.length
  
   def getHeight(self):
       return self.height
      
   def getWidth(self):
       return self.width
      
   def getRoomType(self):
       return self.roomType
   
   def setRoomType(self,tmpRoomType):
       self.roomType=tmpRoomType
       
   def setRoomCapacity(self,tmpRoomCapacity):
       self.roomCapacity=tmpRoomCapacity
   
   def calArea(self):
       return (self.length*self.width*self.height)
       
   def __str__(self):
       return "Room Number: "+str(self.roomNum)+"\nRoom Type: "+self.roomType+"\nRoom Capacity: "+str(self.roomCapacity)+"\nLength: "+str(self.length)+"\nHeight: "+str(self.height)+"\nWidth :"+str(self.width)+"\nArea: "+str(self.calArea())+"\n"
      
class RoomRoster:
   def __init__(self):
       self.roomCollection = []
      
   def addRoom(self,room):
       self.roomCollection.append(room)
      
   def delRoom(self,room):
       self.roomCollection.remove(room)
      
   def __str__(self):
       data = ""
       for room in self.roomCollection:
           data = data + str(room) +"\n"
       return data
      
   def findRoom(self,roomNum):
       for room in self.roomCollection:
           if(room.getRoomNum()==roomNum):
               return room
       return -1
  
   def findRoomWithCapacity(self,tmpCapacity):
       for room in self.roomCollection:
           if(room.getRoomCapacity()==tmpCapacity):
               return room
       return -1
      
def testRoomModule():
   Room_roster = RoomRoster()
   room1 = Room(11,"Non-AC",2,12,10,10)
   room2 = Room(12,"AC",3,12,11,11)
   room3 = Room(13,"Non-AC",4,12,12,12)
   print (room1)
   print (room2)
   print (room3)
   Room_roster.addRoom(room1)
   Room_roster.addRoom(room2)
   Room_roster.addRoom(room3)
   print("Find Room")
   print(Room_roster.findRoom(11))
   print("Delete Room")
   Room_roster.delRoom(room2)
   print(Room_roster)
testRoomModule()
Add a comment
Know the answer?
Add Answer to:
using python 3: Program 14: Class with Private Attribute Collection of Objects: modRoom.py Step 1: Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

    PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

  • Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count...

    Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count of all monsters instantiated and includes a static method that generates a new random monster object. In software engineering, a method that generates new instances of classes based on configuration information is called the Factory pattern. UML Class Diagram: Monster - name: String - health: int - strength: int - xp: int + spawn(type:String): Monster + constructor (name: String, health: int, strength: int, xp:...

  • 1. Please write the following program in Python 3. Also, please create a UML and write...

    1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...

  • Write a python program using Object Oriented and do the following: 1. create class "cat" with...

    Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • In Java please! Problem You will be using the point class discussed in class to create...

    In Java please! Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • Exercise 1: Create a class Resource. The class should have: a) Two private variables status and w...

    C++C++ Exercise 1: Create a class Resource. The class should have: a) Two private variables status and writeTo representing integer value either 0 or 1. b) One default constructor that initializes the status and writeTo to zero. c) One single parameterized constructor to initialize the writeTo variable. d) Two constant accessor functions per class that return the values of status e) Two mutator functions per class that set the values of status and writeTo One output (member) function that outputs...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT