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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:27:54+00:00 2026-06-16T16:27:54+00:00

I have a class named worker and a class called Pass which is the

  • 0

I have a class named worker and a class called Pass which is the pass of the worker.
Im trying to built the main class in which all the processes are read from a text file.My code is full of loops and hopefully will work, but im having a problem.The first line of the text is plain text something like Worker: 1 worker1 , which simply means create a Worker object named worker1 and with passid (the id of his pass) number 1.This is do’able.However after this i simply put in the loop the creation of his pass.Which is my problem.
The 2n line of the text file gives my an AccessLog for the worker1 giving me a date of entry and exit.

    public static void main(String[ ] args) throws IOException {

  String file_name = "data.txt";

  try {
      FileRead file = new FileRead( file_name );
      String[ ] aryLines = file.Openfile();

      int i;
      for ( i=0; i < aryLines.length; i++ ) {
             String phrase = aryLines[i];
             String div = "[ ]+";
             String[] tokens = phrase.split(div);

             if (tokens[0].equals("Officer:")){

               if (tokens[1].equals("1")){

               Officer worker1 = new Worker("1","worker1",1);
               Pass worker1Pass = worker1.getPass();
               }


             //etc. for other workers                   
             }

Here comes the code for the access log and will explain the error

    else{
                 if (tokens[0].equals("AccessLog:")){

                  if (tokens[1].equals("1")){
                  String s1 = tokens[2] + tokens[3] ;
                  String s2 = tokens[4] + tokens[5] ;

                  try{
                      Date entry = new SimpleDateFormat("dd/MM/yyHH:mm:ss").parse(s1);

                      Date exit = new SimpleDateFormat("dd/MM/yyHH:mm:ss").parse(s2);
                      worker1Pass.workerEntry(entry);
                      worker1Pass.workerExit(exit);


                  }
                    catch (ParseException a) {
                       System.out.println( a.getMessage() );
                    }  
               }

workerentry and exit are methods in the pass class that log the access, and i get an error for missing symbol worker1pass.Also there seems to be a problem in the workerpass declaration because in netbeans there is a grey line beneath worker1pass calling it as an unused object.Lastly i would like to add that except the workaround code for the external text file the code works 100%.
Any tips and suggestions are welcome.

EDIT——-

    Worker worker1 = new Worker("1","worker1",1);
               Pass worker1Pass = worker1.getPass();

under worker1Pass im getting : variable worker1Pass is not used

                          worker1Pass.workerEntry(entry);
                  worker1Pass.workerExit(exit);

Here im getting cannot find symbol : worker1pass
Is like the pass worker1pass declaration does not declare a new pass as it should do and thus the methods don’t add the entry and exit to the log as they should do.

  • 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-16T16:27:56+00:00Added an answer on June 16, 2026 at 4:27 pm

    You are getting the missing symbol error because worker1Pass was defined in the first if statement and is visible only in the if context. That is why netbeans is complaining too, because the worker1Pass in the first if is not visible (and not used) anywhere else.
    You should declare worker1Pass outside of your if, at least, to be visible in the second if statement too.

    Like @HovercraftFullOfEels suggested, if you need to maintain all the workers and the pass objects you can use a Collection or a List, your code will look something like:

    List<Officer> workers = new ArrayList<Officer>();
    List<Pass> passes = new ArrayList<Pass>();
    for ( i=0; i < aryLines.length; i++ ) { 
      String phrase = aryLines[i];
      String div = "[ ]+";
      String[] tokens = phrase.split(div);
      Officer worker = null; // and from this point on use this variable to represent a worker
      Pass workerPass = null; // used to represent a pass
      if (tokens[0].equals("Officer:")){
         if (tokens[1].equals("1")){
            worker = new Worker("1","worker1",1);
            workerPass = worker1.getPass();
            workers.add(worker); // add the worker in the workers list
            passes.add(workerPass); // add the pass in the passes list
    
         } 
         //etc. for other workers                   
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named CropImageView which is extended from ImageView . but the
I have a class named FirstViewController which is a subclass of UIViewController and I
I have a class named baseClass. From this class I inherit a class names
I have a Class named Constants that contains all the constant variable in my
I have a class named toto which I send to a function that does
I have created a CSS class called 'button' and applied it to all of
I have a class called Worker public class Worker : BaseEntity { public virtual
i have class named Group i tried to test configuration: var cfg = new
I have a Class named Question and a related Class named Answers. I want
I have a class named Person and in this class is the property PersonName

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.