Question
Print out a list which should show a room number and rate but when i use System.out.println(rooms); I get [Room@84af5, Room@10ad950, R..m@1339bd... instead. correct this.
Print out a list which should show a room number and rate but when i use System.out.println(rooms); I get [Room@84af5, Room@10ad950, R..m@1339bd... instead. correct this.
import java.util.ArrayList;
/**
* Write description of class Hotel here.
*
*/
public class Hotel
{
// (b)
private ArrayList
private String name;
/**
* (c) Constructor for objects of class Hotel
*/
public Hotel(String aName)
{
name = aName;
rooms = new ArrayList<>();
}
/**
* (d) Adds some unoccupied test rooms to the hotel
*/
public void addRooms()
{
int i = 10;
while (i < 19) {
String number = "" + i;
double rate;
if(i % 3 == 1) {
number += "A";
rate = 100;
}
else if (i % 3 == 2) {
number += "B";
rate = 180;
}
else
{
number += "C";
rate = 250;
}
Room r = new Room("", number, rate);
rooms.add(r);
i++;
}
System.out.println(rooms);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer The issue youre encountering is that when you print out the rooms list using Systemoutprintln...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