こんにちは、私は現在、ユーザーが配列を作成し、配列を検索し、配列から要素を削除できるようにするプログラムを作成しています。メソッドを見るとLibraryMenu
、switch ステートメントで配列を作成する最初のケースは正常に動作しますが、他のケースではコンパイルしようとすると「シンボルが見つかりません」というエラーが発生します。
私の質問は、検索関数と削除関数が最初のスイッチ ケース (ライブラリ配列の作成) を参照するようにしたいということです。たとえそれが単純な間違いによるものであっても、どんな助けも大歓迎です。
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();
}
}