【发布时间】:2020-10-23 15:23:15
【问题描述】:
我正在做一个销售游戏的程序。现在在我的代码中,它只会显示客户写的最后一条评论,但我希望它包含游戏获得的所有评论的列表。我在想是否可以将ArrayList 作为变量而不是String 审查。下面是一个例子,说明它现在的样子。
public class Game {
private String gameName;
private int gamePrice;
private String gameReviews;
public Game(String gameName, int gamePrice, String gameReviews) {
this.gameName = gameName;
this.gamePrice = gamePrice;
this.gameReviews = gameReviews;
}
}
然后,如果我想创建一个对象来替换我拥有的旧对象,它会是什么样子?
public class Games {
public static void main(String[] args) {
String gameN = "Name";
int gameP = 10;
String gameR = "Review";
Game game = new Game(gameN, gameP,gameR);
}
}
【问题讨论】: