Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago

Question

2. How were various roles filled?

Answered: 1 week ago