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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:39:09+00:00 2026-05-27T07:39:09+00:00

I am building an application with a Room class which is abstract and a

  • 0

I am building an application with a Room class which is abstract and a Standard class which inherits from Room. I have then created a Hostel class. Within the Hostel class is ArrayList<Room> rooms to which rooms can be added. I have created a method in the Hostel class which shows all available rooms but when I try and instantiate this in another class (MainGUI) nothing is shown. As far as I can see this is because I am creating a new hostel each time I click the button but would like to know how to pass the data across instead of creating a new hostel each time. Below are the relevant snippets of code.

Hostel Class

public Hostel()
{
    rooms = new ArrayList<Room>();
}

public void showAvail()
{
    for (Room room : rooms)
    {
        if (room.available == true) 
        {
                 theString = room.getRoomData() + "\n";
                 //System.out.println("Available Rooms" + "\n" + theString);
                 JOptionPane.showMessageDialog(null,theString);
        }
    }
}

public void addRoom(Room theRoom)
{
    rooms.add(theRoom);
}

MainGUI Class

roomsFreeB.addActionListener(new ActionListener()
{
    public void actionPerformed(ActionEvent e)
    {
        Hostel host = new Hostel();
        host.showAvail();
    }
});

Any help would be appreciated

  • 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-27T07:39:10+00:00Added an answer on May 27, 2026 at 7:39 am

    Your problem is exactly what you thought, you are making a new ArrayList each time you click the button so you will never see the data. You should begin by creating a hostel object in your MainGUI class,

    private Hostel hostel;

    this will allow previously entered information to be referenced

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

Sidebar

Related Questions

In building my application which is a tab based application, from the first tab,
I am building application that required some data from iPhone's Call log(read only). The
I'm building a chat room application where new events are being polled for every
I have application building using third party apis, j2me apis,application code distributed in various
I'm using this script for building application from command line: #!/bin/bash TARGET=signtest CONFIGURATION=Debug SDK=iphoneos
I am developing an application in mootools. I have used Reqeust class to implement
Building an application to calculate metrics on Service Level Agreements. I have access to
I'm building application, which paints raw bitmap images on label's hdc using StrechDIBits. ptr
I am beginner in C# programming. I have encountered small problem during building application
im building an application which loads some products on main page with search.also after

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.