我目前有三個主要類。電視劇類,其中包含一個對象,它的getter和setter方法:將數據添加到對象中包含的數組列表中
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;
一系列的庫類,這是由只是一個ArrayList的電視連續劇對象的對象:
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;
}
以及測試類。我將代碼添加到菜單中,但我不知道如何啓動它。
我有一個系列庫類中的方法,它允許用戶添加信息來創建一個新的電視劇,該方法返回他們新創建的對象。
在測試儀內部,我會用什麼代碼將這個新值添加到對象中的數組列表中,例如稱爲seriesLibrary。我需要創建一個新的方法嗎?我是否改變我目前的方法?
對於一些之所以前面的評論已經被刪除了,以及我的,我已經編輯了這篇文章,以包含我當前的代碼。 – AceVenturos
你檢查了下面的答案嗎?如果您對其中一個答案感到滿意,請將其標記爲解決方案。否則發表評論並說出了什麼問題! –