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...

  • Language Java Step 1: Design a class called Student. The Student class should contain the following...

    Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...

  • Using Classes/Objects Part-1 Create 3 frame/label objects Place 2 objects side-by-side on top of the screen...

    Using Classes/Objects Part-1 Create 3 frame/label objects Place 2 objects side-by-side on top of the screen Place the 3rd object below the top 2, spanning two columns Display a picture in one of the top 2 objects Display some text(any) in each of the other 2, or text in one and navigation buttons in the other Part-2 Load student data from database file in a list of Student class objects Add navigation features, however way you see fit Bottom-line: picture...

  • 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...

  • 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:...

  • 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...

  • PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to...

    PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Python...

  • 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...

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