Question
I'm getting the following error in my Java code from public Arraylist onwards and need help with a fix IndexOutOfBoundsException was thrown: Index: 0, Size:
I'm getting the following error in my Java code from public Arraylist
IndexOutOfBoundsException was thrown: Index: 0, Size: 0
import java.util.ArrayList;
public class Hotel { private ArrayList
public ArrayList } ROOM Class: public class Room { // instance variables - replace the example below with your own private String guest; private String number; private double dailyRate; /** * Write a description of class Room here. */ public Room(String aGuest, String aNumber, double aRate) { guest = aGuest; number = aNumber; dailyRate = aRate; } /** * Write a description of class Room here. */ public String getGuest() { return guest; } /** * Write a description of class Room here. */ public String getNumber() { return number; } /** * Write a description of class Room here. */ public double getDailyRate() { return dailyRate; } /** * Write a description of class Room here. */ public void setGuest(String guest) { this.guest = guest; } /** * Write a description of class Room here. */ public void setDailyRate(double dailyRate) { this.dailyRate = dailyRate; } /** * Write a description of class Room here. */ public boolean isAvailable(){ return this.guest.length() == 0; } public boolean verifyRoom() { if(this.getNumber().length()==3) if(this.getNumber().charAt(0)>='0' && this.getNumber().charAt(1)<='9' && !(this.getNumber().charAt(0)=='0' && this.getNumber().charAt(1)=='0')) if(this.getNumber().charAt(2)=='A' || this.getNumber().charAt(2)=='B' || this.number.charAt(2)=='C') return true; return false; } public String getType(){ String roomType = ""; if(number.charAt(2) == 'A'){ roomType = "Single"; } else if(number.charAt(2) == 'B'){ roomType = "Double"; } else{ roomType = "Family"; } return roomType; } public String description(){ String availability = isAvailable() ? "available" : "reserved"; return getType() + " room " + number + " (" + availability + ") " + guest; } }
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