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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:43:49+00:00 2026-06-05T11:43:49+00:00

Hi guys I’m currently creating a program that allows the user to create an

  • 0

Hi guys I’m currently creating a program that allows the user to create an array, search an array and delete an element from an array. Looking at the LibraryMenu method, the first case where you create an array in the switch statement works fine, however the other ones create a “cannot find symbol error” when I try to compile.

My question is I want the search and delete functions to refer to the first switch case – the create Library array. Any help is appreciated, even if its likely from a simple mistake.

import java.util.*;
public class EnterLibrary
{

public static void LibraryMenu()
    {
        java.util.Scanner scannerObject =new java.util.Scanner(System.in);
        LibraryMenu Menu = new LibraryMenu();
        Menu.displayMenu();
        switch (scannerObject.nextInt() )
        {
            case '1':
            {
                System.out.println ("1 - Add Videos");
                Library[] newLibrary;
                newLibrary = createLibrary();
            }
            break;
            case '2':
                System.out.println ("2 - Search Videos");
                searchLibrary(newLibrary);
                break;
            case '3':
            {
                System.out.println ("3 - Change Videos");
                    //Change video method TBA
            }
            break;      
            case '4':
                System.out.println ("4 - Delete Videos");
                deleteVideo(newLibrary);
                break;
            default:
                System.out.println ("Unrecognized option - please select options 1-3 ");
                break;
        }
    }

public static Library[] createLibrary()
{
    Library[] videos = new Library[4];
    java.util.Scanner scannerObject =new java.util.Scanner(System.in); 
    for (int i = 0; i < videos.length; i++)
    {
        //User enters values into set methods in Library class
        System.out.print("Enter video number: " + (i+1) + "\n");
        String number = scannerObject.nextLine();
        System.out.print("Enter video title: " + (i+1) + "\n");
        String title = scannerObject.nextLine();
        System.out.print("Enter video publisher: " + (i+1) + "\n");
        String publisher = scannerObject.nextLine();
        System.out.print("Enter video duration: " + (i+1) + "\n");
        String duration = scannerObject.nextLine();
        System.out.print("Enter video date: " + (i+1) + "\n");
        String date= scannerObject.nextLine();
        System.out.print("VIDEO " + (i+1) + " ENTRY ADDED " + "\n \n");
        //Initialize arrays
        videos[i] = new Library ();
        videos[i].setVideo( number, title, publisher, duration, date  );
    }
    return videos;
}

public static void printVidLibrary( Library[] videos)
{
    //Get methods to print results
    System.out.print("\n======VIDEO CATALOGUE====== \n");
    for (int i = 0; i < videos.length; i++)
    {
        System.out.print("Video number " + (i+1) + ": \n" + videos[i].getNumber() + "\n ");
        System.out.print("Video title " + (i+1) + ": \n" + videos[i].getTitle() + "\n ");
        System.out.print("Video publisher " + (i+1) + ": \n" + videos[i].getPublisher() + "\n ");
        System.out.print("Video duration " + (i+1) + ": \n" + videos[i].getDuration() + "\n ");
        System.out.print("Video date " + (i+1) + ": \n" + videos[i].getDate() + "\n ");
    }
}

public static Library searchLibrary( Library[] videos)
{
    //User enters values to setSearch
    Library titleResult = new Library();
    java.util.Scanner scannerObject =new java.util.Scanner(System.in); 
    for (int n = 0; n < videos.length; n++)
    {
        System.out.println("Search for video number:\n");
        String newSearch = scannerObject.nextLine();
        titleResult.getSearch( videos, newSearch);

        if (!titleResult.equals(-1))
        {
        System.out.print("Match found!\n" + newSearch + "\n");
        }
        else if (titleResult.equals(-1))
        {
        System.out.print("Sorry, no matches found!\n");
        }
    }
    return titleResult;
}

public static void deleteVideo( Library[] videos)
{
    Library titleResult = new Library();
    java.util.Scanner scannerObject =new java.util.Scanner(System.in); 
    for (int n = 0; n < videos.length; n++)
    {
        System.out.println("Search for video number:\n");
        String deleteSearch = scannerObject.nextLine();
        titleResult.deleteVideo(videos, deleteSearch);
        System.out.print("Video deleted\n");
    }
}



public static void main(String[] args)
{
    Library[] newLibrary;

    new LibraryMenu();
}
}
  • 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-05T11:43:51+00:00Added an answer on June 5, 2026 at 11:43 am

    Library[] newLibrary; is defined in your case ‘1’ only, you should define it in a wider scope, like your LibraryMenu method. Also, the Library[] newLibrary declared in your main is not called anywhere, and maybe you should add Null check in your search, print an delete methods.

    Your constructor class must have the same name of your class and not have any modifier keywords in it. Also, when you create an object of your class, it wont use the static methods declared in there.

    A note: when you work with your own declared arrays, it would be better that you declare a int variable to keep track of the actual size of the array. Note that array.length returns how many items the array can have, not how many items it already has.

    I would redesign your definitions (not the code) to something like this:

    //Note I changed the classname from EnterLibrary to LibraryMenu. Apparently you
    //wanted a LibraryMenu class.
    public class LibraryMenu {
    
        private final int MAX_ITEMS = 50;
        private Library[] videos;
        private int size = 0;
    
        //remove the static and void keyworkds from this method, so this will be 
        //the constructor.
        public LibraryMenu() {
            videos = new Library[MAX_ITEMS];
            //the rest of your code here...
            switch (scannerObject.nextInt()) {
            //if you're reading an int, keep the constants in the case as int.
            case 1: 
                //no need of brackets inside a case statement
                //check that you can add an item in your Library array
                //also, its not good to ask the user to add 4 (or N) videos in 1 round :).
                if (size < MAX_ITEMS) {
                    Library video = addVideo();
                    videos[size++] = video;
                }
                break;
            case 2:
                break;
            }
        }
    
        //remove the static keyword so the instance of your class can call the method.
        public Library addVideo() {
            Library video = new Library();
            //your code to read data goes here...
            //then fulfill the video and return it.
            return video;
        }
    
        //The Library[] videos is declared in your class, so all other methods could
        //use it without having to receive it as a parameter.
        public void printVidLibrary() {
            //your code goes here...
        }
    
        public Library searchLibrary() {
            //your code goes here...
        }
    
        public void deleteVideo( Library[] videos) {
            //your code goes here...
        }
    
        public static void main(String[] args) {
            new LibraryMenu();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys that is code copied from a book (Programming Windows 5th edition): #include <windows.h>
Guys i am looking for some awesome tips for developing a page which allows
Guys; How are you doing today? I have to create a dll project on
Guys, I'm trying to write xpath or css to find/click on list element All
guys i got a php file that use it as xml for a flash
Guys I have been trying lots of different options from cutting up to building
Guys, Is there an easy way to return different fields names from different models
Guys, Can you please tell me that ,I wants to learn Azure , by
Guys. I use getpixel & getdata to retrieve data from the same pic.but some
guys. I'm working on some audio services on iOS. I trying to search any

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.