Question
In a hotel, each room has exactly 3-digit id and a positive price. Develop a class in java to represent class Room strictly as follows:
In a hotel, each room has exactly 3-digit id and a positive price. Develop a class in java to represent class Room strictly as follows:
Define the class Room Define price fields to be private and the id to be public. Define the default constructor that sets an object with values id:1 and price:70.5 Define a setter method for price (Make sure to not accept negative price). Define a getter method for price. Define the toString method of the class such that it returns a string representing the room. e.g.: ID: 412 Price: 80.25
B. Based on the Room class above, complete the main method below
public class TestProduct{
public static void main(String[] args){
// 1. Create a Room objects r1 with the following values: id is 521 and price 100
// 2. Increment the price of r1 by 10.
// 3. Change the id of r1 to be 140.
// 4. Use toString method to print r1 id and price
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