私が作成しているプログラムでは、ユーザーは値を入力してビデオの配列を作成します。各ビデオには、いくつかのデータ フィールド (番号、タイトル、発行元、期間、日付) が含まれています。ただし、私が現在達成しようとしているのは、ユーザーが作成したばかりの配列で特定のビデオを選択し、名前を変更するデータ フィールドを選択し、値の名前を変更してから、名前を変更した値を新しい値として設定することです。配列にビデオを追加するための私のコードは次のとおりです。
public Library createLibrary()
{
Library video = new Library();
java.util.Scanner scannerObject =new java.util.Scanner(System.in);
for (int i = 0; i < videos.length; i++)
{
//User enters values into set methods within the 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 video;
}
そして、私が何を意味するのか理解できない人のために、選択と置換機能の基本的な概念を次に示します。
public void replaceVideo(Library[] videos, String replaceTo, String replaceWith)
{
for (int i = 0; i < videos.length; i++)
if (videos[i].equals(replaceTo)) {
videos[i]= replaceWith;
}
}
より簡単な解決策をいただければ幸いです。ありがとう。