Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:48:54+00:00 2026-05-16T08:48:54+00:00

So i need some support with my Ruby assignment, I’m not from US so

  • 0

So i need some support with my Ruby assignment, I’m not from US so you have to excuse my English.

We are building a hotel and this is the second assignment. It’s a console based application and I have a class called main.rb that handles the runtime and a guest-class.

In this second assignment we are to preload the app with five guest-objects, I guess I have to use an array but don’t really know how. Below are my guest class and my main class is simply a while-loop with a case statement.

I need help with:

  1. adding 5 guests (not to a db or textfile only to a array or so) when the program starts
  2. the hotel has 20 rooms and i need to randomize the room number and exclude already rented rooms

Hope you can help! Thanks!

 class Guest                 
  #Instance variables.
  attr_accessor :firstName, 
    :lastName,
    :address,
    :phone,
    :arrival,
    :plot,
    :gauge

  #Constructor sets the guest details.
  def initialize(first, last, adress, phone, arrival) 
    @firstName = first
    @lastName = last
    @address = address
    @phone = phone
    @arrival = arrival
    @plot = range_rand(1,32)
    @gauge = range_rand(2000,4000)
  end

  #Using rand()-method to randomize a value between min and max parameters.   
  def range_rand(min,max) 
    min + rand(max-min)
  end

  def to_string
    "Name = #{@firstName} , Plot = #{@plot}"
  end
end 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:48:55+00:00Added an answer on May 16, 2026 at 8:48 am

    Other people have already answered the first part of your question, so I’ll help you with the second one (I’ll provide the minimum, so that you still have some work to do 🙂 )

    You could create an array containing the 20 room numbers :

    empty_rooms = (1..20).to_array
    

    Then for each guest :
    1) Take a random number in this array ( hint : randomize the index )
    2) Remove this number from the array
    3) And assign the room number to a Guest
    4) Add the guest to the array of guests

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The three first arguments of a function are given in… May 16, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer I am assuming that you're trying to create the <a>… May 16, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer So I figured out what was wrong. ISession comes from… May 16, 2026 at 5:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have developed a simple library in Ruby and need to use this in
I've been using Textmate for Ruby/Python scripting for awhile and now have a need
I need to output a file in the format of a Word document from
I'm in need of a two-way encryption solution for Ruby, such as Blowfish, Rijndael
We're starting to standardise on a Ruby-based testing framework, having had some very good
I use apache/passenger on my development machine, but need to add SSL support (something
I've xcode 3.0 installed. And I need to install sqlite3-ruby gem (for rhosync). When
In need in my application to fetch remote HTML document and parse some parts
I need to use the following regular expression to validate some Asian characters $regexp
BerkeleyDB is the database equivalent of a Ruby hashtable or a Python dictionary except

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.