Java 对具体问题添加评论

Java 对具体问题添加评论,java,Java,我正在制作一个问题跟踪系统,但我一直在为您从ID收到的特定问题添加注释。 我希望能够从已经存储在ArrayList(完成)中的唯一ID中获取特定问题,然后在该特定问题上编写一条要保存的注释(可能在它自己的ArrayList中?),因此当我稍后显示有关该特定问题的信息时,注释还将显示在作出注释时的时间戳 公共类2{ 扫描仪输入=新扫描仪(System.in); ArrayList issues=新建ArrayList(); 公共无效检索问题(){ System.out.println(“写入要显示

我正在制作一个问题跟踪系统,但我一直在为您从ID收到的特定问题添加注释。 我希望能够从已经存储在ArrayList(完成)中的唯一ID中获取特定问题,然后在该特定问题上编写一条要保存的注释(可能在它自己的ArrayList中?),因此当我稍后显示有关该特定问题的信息时,注释还将显示在作出注释时的时间戳

公共类2{
扫描仪输入=新扫描仪(System.in);
ArrayList issues=新建ArrayList();
公共无效检索问题(){
System.out.println(“写入要显示的问题的ID:”;
字符串inputNewID=input.nextLine();
布尔值isIssueFound=false;
针对(问题:问题){
if(inputNewID.equals(issue.getID())){
isIssueFound=真;
System.out.println(“ID:+issue.getID()+”\n名称:“+issue.getIssueName()+”\n日期:“+issue.getLocalDate()+”\n注释:“+issue.getIssueComment()+”\n状态:“+issue.getIssueStatus());
}
}
如果(!isIssueFound){
System.out.println(“假ID.重试”);
}
}
公开发行{
System.out.println(“写下您想要评论的问题的ID:”;
字符串inputNewID=input.nextLine();
布尔值isIssueFound=false;
针对(问题:问题){
if(inputNewID.equals(issue.getID())){
isIssueFound=真;
}
System.out.println(“Vad vill du kommentera?”);
字符串issueComment=input.nextLine();
问题注释=新问题(问题注释);
}
如果(!isIssueFound){
System.out.println(“假ID.重试”);
}
}
}
公共类问题{
私有字符串ID;
私有字符串issueName;
私有字符串localDate;
私有字符串issueStatus;
私有字符串issueComment;
公共问题(字符串ID、字符串issueName、字符串issueStatus){
this.ID=ID;
this.issueName=issueName;
this.localDate=new Date().toString();
this.issueStatus=issueStatus;
}
公开发行(字符串issueComment){
this.issueComment=issueComment;
}
公共无效集合ID(字符串ID){
this.ID=ID;
}
public void setIssueName(字符串issueName){
this.issueName=issueName;
}
公共无效setIssueStatus(字符串issueStatus){
this.issueStatus=issueStatus;
}
public void setLocalDate(字符串localDate){
this.localDate=localDate;
}
public void setIssueComment(字符串issueComment){
this.issueComment=issueComment;
}
公共字符串getID(){
返回此.ID;
}
公共字符串getIssueName(){
返回此.issueName;
}
公共字符串getLocalDate(){
返回this.localDate;
}
公共字符串getIssueStatus(){
将此文件退回。issueStatus;
}
公共字符串getIssueComment(){
返回此。issueComment;
}
}

如果要为注释分配具有指定ID的问题,则必须使用在问题类中实现的
setIssueComment
方法添加注释

而不是做

Issue comment = new Issue(issueComment);
试一试


这应该会更新您所查找问题的问题注释。

为了使您的类
问题
能够存储多个注释,您必须为注释提供合适的数据结构,单个
字符串
是不够的。如果要添加注释,请提供相应的方法。参见类
问题
轻微更改:

公共类问题{
私有字符串ID;
私有字符串issueName;
私有字符串localDate;
私有字符串issueStatus;
private List issueComments;//这是第一个更改
公共问题(字符串ID、字符串issueName、字符串issueStatus){
this.ID=ID;
this.issueName=issueName;
this.localDate=new Date().toString();
this.issueStatus=issueStatus;
this.issueComments=new ArrayList();//列表需要初始化
}
//此getter提供问题实例的所有注释
公共列表getIssueComments(){
退货建议;
}
//为简洁起见,省略了其他getter和setter
/**
*向问题注释集合添加新注释
*/
公共void addComment(字符串注释){
问题建议。添加(评论);
}
}
Class2
commentIssue()
方法中,您必须在增强的
for
循环中使用当前的
问题
,并添加新的注释。请参见下面类中的代码注释:

公共类2{
扫描仪输入=新扫描仪(System.in);
ArrayList issues=新建ArrayList();
公共无效检索问题(){
System.out.println(“写入要显示的问题的ID:”;
字符串inputNewID=input.nextLine();
布尔值isIssueFound=false;
针对(问题:问题){
if(inputNewID.equals(issue.getID())){
isIssueFound=真;
System.out.println(“ID:+issue.getID()
+“\n名称:”+issue.getIssueName()
+“\n日期:”+issue.getLocalDate()
+“\n建议:”+issue.getIssueComment()
+“\n状态:“+issue.getIssueStatus());
}
}
如果(!isIssueFound){
System.out.println(“假ID.重试”);
}
}
公开发行{
System.out.println(“写下您想要评论的问题的ID:”;
字符串inputNewID=input.nextLine();
布尔isIssueFound=
issue.setIssueComment(issueComment);