私は現在、3つのメインクラスを持っています。オブジェクトとそのゲッターとセッターが含まれているテレビシリーズクラス:オブジェクト内に含まれている配列リストにデータを追加する
public class SeriesLibrary {
private ArrayList<TVSeries> tvSeries = new ArrayList<TVSeries>();
public SeriesLibrary(ArrayList<TVSeries> tvSeries) {
this.tvSeries = tvSeries;
}
public ArrayList<TVSeries> getTvSeries() {
return tvSeries;
}
public void setTvSeries(ArrayList<TVSeries> tvSeries) {
this.tvSeries = tvSeries;
}
public TVSeries addTVSeries(Scanner sc) {
System.out.println("Add a new TV Series");
System.out.println("------------------------------");
System.out.print("Please enter the TV series' Title: ");
String title = sc.nextLine();
System.out.print("Please enter the TV series' Genre: ");
String strGenre = sc.nextLine();
System.out.print("Please enter the TV series' Age Rating: ");
String strRating = sc.nextLine();
System.out.print("Please enter the number of Episodes in the TV Series: ");
int numOfEps = sc.nextInt();
sc.nextLine();
System.out.println(title + " will be set up with no actors or ratings. These can be added later.");
ArrayList<String> emptyActors = new ArrayList<String>();
ArrayList<Integer> emptyReviews = new ArrayList<Integer>();
Genre genre = Genre.valueOf(strGenre);
Rating rating = Rating.valueOf(strRating);
TVSeries newSeries = new TVSeries(title, genre, rating, numOfEps, emptyActors, emptyReviews);
return newSeries;
}
とテスタクラス:ちょうどArrayListのテレビシリーズのオブジェクトで構成されたオブジェクトである
public class TVSeries {
private String title;
private Genre genre;
private Rating rating;
private int numOfEps;
private ArrayList<String> actor = new ArrayList<String>();
private ArrayList<Integer> listOfReviews = new ArrayList<Integer>();
public TVSeries(String title, Genre genre, Rating rating, int numOfEps, ArrayList<String> actor, ArrayList<Integer> listOfReviews) {
this.title = title;
this.genre = genre;
this.rating = rating;
this.numOfEps = numOfEps;
this.actor = actor;
this.listOfReviews = listOfReviews;
シリーズライブラリクラス。私はこのデータをメニューに追加するコードを入れていますが、実際にどのように起動するのか分かりません。
私は、ユーザーが新しいテレビシリーズを作成するための情報を追加できるメソッドを持っています。このメソッドは、新しく作成されたオブジェクトを返します。
テスター内でどのようなコードを使用すれば、この新しい値をオブジェクト内の配列リストに追加することができますか(たとえばseriesLibrary)。私は新しいメソッドを作成する必要がありますか?私は現在の方法を変更しますか?
に追加whithout新しい
TVSeries
オブジェクトを作成します。PS:あなたのケースでは、このようなものかもしれません以前のコメントが削除された理由、私の現在のコードを含めるために投稿を編集した理由 – AceVenturos
下記の回答を確認しましたか?あなたが答えの1つに満足していれば、それを解決策としてマークしてください。それ以外の場合はコメントし、何が間違っているか –