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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:00:33+00:00 2026-06-13T04:00:33+00:00

Okay so I have the following code for a school project. Its only half

  • 0

Okay so I have the following code for a school project. Its only half finished so far. I have a problem with the ‘Residents’ function. It says I cannot reference a non-static variable from a static context.

import java.util.Scanner;
class Hotel
{int noofemployees=10;
 int salary2=10000;
 int salary3=8000;
 int salary4=2000;

 String resident1="John Smith";
 String resident2="John Smith";
 String resident3="John Smith";
 String resident4="John Smith";
     String resident5="John Smith";
     String resident6="John Smith";
     String resident7="John Smith";
     String resident8="John Smith";
     String resident9="John Smith";
     String resident10="John Smith";

public static void main()
{   

    Scanner input=new Scanner(System.in);
    System.out.println("     ___o___    ");
    System.out.println("    /   |   \\  ");
    System.out.println(" __/____|____\\__");
    System.out.println("|   x   |  |||  |");
    System.out.println("|  xxx  |  ooo  |");
    System.out.println("|   x   |  |||  |");
    System.out.println("|-------|-------|");
    System.out.println("\\  []   |   $$  /");
    System.out.println(" \\  []  |  $$  /");
    System.out.println("   -----|----- ");
    System.out.println("");
    System.out.println("Welcome to the hotel automated management and guest system.");
    System.out.println("Enter 1 if you're a hotel employee.");
    System.out.println("Enter 2 if you're a resident.");
    System.out.println("Enter 3 to exit.");

    int choice=input.nextInt();
    if(choice==1)
        employee();//user is an employee
    else if(choice==2)
        resident();//user is a resident
    else if(choice==1997)
        easteregg();
    else
        {
         System.out.println("That is not a valid choice.");
        }
}

public static void employee()
    {   clearscreen();
        Scanner input=new Scanner(System.in);
        System.out.println("Enter the employee code");
        int code=input.nextInt();
        if(code==1111)
            {  clearscreen();
                System.out.println("Welcome employee.");
                System.out.println("Choose your rank.");
                System.out.println("1. Manager");
                System.out.println("2. Accounts");
                System.out.println("3. Human resources");
                System.out.println("4. Cleaner");
                System.out.println("5. Return to main menu");


                int rank=input.nextInt();
                if(rank==5)
                    main();
                else employees(rank);
            }
        else
           { 
            System.out.println("You aren't an employee.");
            main();
           }
    }

public static void resident()
    {   clearscreen();
        System.out.println("Greetings, guest!");
        System.out.println("Press 1 to sign in.");
        System.out.println("Press 2 to query guestlist.");
        System.out.println("Press 3 to sign out.");
        System.out.println("Press 4 to return to the main menu.");
        Scanner input=new Scanner(System.in);
        int choice=input.nextInt();

        if(choice==1)
            {System.out.println("Enter your name");
             String name=input.nextLine();
             System.out.println("Enter the room you wish to occupy");
             int room=input.nextInt();

                residents(room,0,1,name);
            }
        else if(choice==2)
            {for(int i=1;i<=10;i++)
                {System.out.println(residents(i,0,0," "));
                }  
            }
        else if(choice==3)
            {
             System.out.println("Enter the resident number.");
             int resno=input.nextInt();

             residents(resno,1,0," ");   
            }

        else if(choice==4)
            {main();
            }
        main();
    }

public static void easteregg()
    {

    }

public static void employees(int rank)
    {
        clearscreen();clearscreen();
        if(rank==1)
            manager();
        else if(rank==2)
            accounts();
        else if(rank==3)
            hr();
        else if(rank==4)
            clean();
    }

public static void manager()
    {
        System.out.println("Welcome manager");
        System.out.println("1. View wages");
        System.out.println("2. Edit wages");
        System.out.println("3. View guests");
        System.out.println("4. Evict guests");
        Scanner input=new Scanner(System.in);
        int choice=input.nextInt();
        if(choice==1)
            {
            }
        else if(choice==2)
            {
            }
        else if(choice==3)
            {for(int i=1;i<=10;i++)
                {System.out.println(residents(i,0,0," "));
                }
             main();
            }
        else if(choice==4)
            {System.out.println("Enter the resident number.");
             int resno=input.nextInt();

             residents(resno,1,0," ");
             main();
            }
    }

public static void accounts()
    {

    }

public static void hr()
    {

    }

public static void clean()
    {

    }

public static String residents(int resname, int evict, int replace, String newname)
    {

     String cur="nobody";

    if(resname==1)
        {if(evict==1)
            resident1="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident1;
        }
    else if(resname==2)
        {if(evict==1)
            resident2="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident2;
        }
    else if(resname==3)
        {if(evict==1)
            resident3="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident3;
        }
    else if(resname==4)
        {if(evict==1)
            resident4="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident4;
        }
    else if(resname==5)
        {if(evict==1)
            resident5="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident5;
        }
    else if(resname==6)
        {if(evict==1)
            resident6="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident6;
        }
    else if(resname==7)
        {if(evict==1)
            resident7="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident7;
        }
    else if(resname==8)
        {if(evict==1)
            resident8="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident8;
        }
    else if(resname==9)
        {if(evict==1)
            resident9="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident9;
        }
    else if(resname==10)
        {if(evict==1)
            resident10="Empty";
         if(replace==1)
            resident1=newname;
         cur=resident10;
        }
    return cur;
}




public static void clearscreen()
   {for(int i=0;i<=2;i++)
       {System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("");
    }
}
}
  • 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-13T04:00:35+00:00Added an answer on June 13, 2026 at 4:00 am

    You would have to make your string variables static for this to work:

     static String resident1="John Smith";
     static String resident2="John Smith";
     static String resident3="John Smith";
     static String resident4="John Smith";
     static String resident5="John Smith";
     static String resident6="John Smith";
     static String resident7="John Smith";
     static String resident8="John Smith";
     static String resident9="John Smith";
     static String resident10="John Smith";
    

    A better preferred approach here would be to make all methods & class variables non-static create an instance of your class.

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

Sidebar

Related Questions

Okay so i have a semi weridish problem with re.sub. Take the following code:
My problem is a little bit complex. I have the following code: $(document).ready(function() {
Okay so I have the following code: function() { $(ul#postbit).load('load.php').fadeIn(slow); }, 3000); What I
Okay, I have the following PHP code to extract an email address of the
I have the following code in a project for the main navigation. It is
Okay, I have the following code: QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir::currentPath()); model->setFilter(QDir::Files |
I have the following code at JSfiddle: http://jsfiddle.net/ACG2D/ $(document).ready(function() { $('.testThis').click(function() { $('.regexValidation').each(function() {
Okay, I have the following code in my Bullet.as file: public var impact:MovieClip; public
Okay so I have the following Code which appends a string to another in
I have the following code: function dbPublish($status) { global $dbcon, $dbtable; if(isset($_GET['itemId'])) { $sqlQuery

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.