Question
Need create a Room class contained within a Room.java file (this means that your project will now contain two .java source files: Main.java and Room.java).
Need create a Room class contained within a Room.java file (this means that your project will now contain two .java source files: Main.java and Room.java). An instance of the Room class represents a single room within the house. Presently, each room has only a single attribute: its name (i.e. Foyer or Kitchen). Within the Room class, create a private (non-static) class member variable called name of type String. Expose this class member variable through public (non-static) getter and setter methods named, getName() and setName(), respectively. Create a public Room constructor which accepts a String parameter called name. Within the body of the constructor, invoke the setName method to initialize the corresponding data member. In your Main class, replace the rooms variable type from a 3x3 array of String objects to a 3x3 array of Room objects. Keep the same floor plan as before and pass the name of each Room to the class constructor as you instantiate each object in the array. Change the code that displays the name of the current room to employ the getName() method of the Room class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started