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 8227043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:59:10+00:00 2026-06-07T15:59:10+00:00

im struggling with abit of java code. Currently i have 8 rooms room1 =

  • 0

im struggling with abit of java code.

Currently i have 8 rooms

    room1 = new Room(1,1);
    room2 = new Room(2,1);
    room3 = new Room(3,1);
    room4 = new Room(4,1);
    room5 = new Room(5,2);
    room6 = new Room(6,2);
    room7 = new Room(7,3);
    room8 = new Room(8,3);

Now i need to make it so that the user inputs a number 1 to 8 regarding the room they require, then the system needs to add that number to the prefix room so that i can call methods of the desired room.

I currently have this code to receive the selection

roomselect = scan.nextInt();

and then this is where i get stuck as im unsure how to add roomselect integer onto the prefix ‘room’

thanks

  • 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-06-07T15:59:12+00:00Added an answer on June 7, 2026 at 3:59 pm

    Just use arrays:

    // Create an array of Rooms
    Room rooms[] = new Room[8];
    // Now, you have a placeholder for 8 rooms
    // Know that it are simply placeholders, the rooms are not initialized.
    // Each element of the array is initialized to null
    
    // Assigning
    rooms[2] = new Room(3, 2); // Initialize the room at index 2 (which is the 3th 
                               // in spoken language)
    
    
    // Retrieving
    int index = 4; // Indices start at 0
    Room room4 = rooms[index];
    
    // Or...
    rooms[5].doSomething();
    
    
    // Getting the length
    int numberOfRooms = rooms.length;
    

    So, to solve your case:

    int roomselect = scan.nextInt();
    Room selectedRoom = rooms[roomselect];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently struggling a bit trying to keep my controller specs DRY and succinct
New to wpf and therefore struggling a bit. I am putting together a quick
Struggling with styling the mouse over for a button ... I have managed to
I'm currently playing with implementing various sorting algorithms in Java, mostly for fun, but
Struggling a bit today. I have the following method that returns a list of
at work I am struggling a bit with the following situation: We have a
I'm currently working on a project for class but struggling with a bit of
Im struggling a bit with the UIkeyboard, I have a datePicker, IntervalPicker some custom
I am struggling a bit with a compiler warning. Here the code: const char
I'm struggling a bit with the play 2.0 templating system; I have a method

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.