gpt4 book ai didi

java - 错误“找不到符号 - 方法 isCompleted()

转载 作者:行者123 更新时间:2023-12-01 13:46:45 24 4
gpt4 key购买 nike

我不断收到此错误“找不到符号 - 方法 isCompleted()”,但我已经声明了它。我做错了什么???

private boolean isCompleted;

public boolean isCompleted()
{
return isCompleted = true;
}

public int getJobsWaiting()
{
int count = 0;
int i = 0;
while (i < jobList.size())
{
if(!jobList.get(i).isCompleted())
{
count = count + 1;
}
i = i+1;
}
return count;
}

最佳答案

import java.util.ArrayList;
import java.util.List;

public class Jobs {
List<Job> jobList = null;

public void createJobs(){
jobList = new ArrayList<Job>();

// create three jobs
for(int index = 0; index < 3; index++){
jobList.add(new Job());
}

}

public List<Job> getJobs(){
return jobList;
}

public int getJobsWaiting()
{
int count = 0;
int i = 0;
while (i < jobList.size())
{
if(!jobList.get(i).isCompleted())
{
count = count + 1;
}
i = i+1;
}
return count;
}


class Job {

private boolean isCompleted;


public boolean isCompleted()
{
return isCompleted;
}

}

public static void main(String[] args) {
Jobs myJob = new Jobs();
myJob.createJobs();

System.out.println(myJob.getJobsWaiting()); // return 3

List<Job> jobs = myJob.getJobs();

for(int index = 0; index < 3; index++){
System.out.println(jobs.get(index).isCompleted());
}
}
}

jobList.get(i) 应该返回一个包含 isCompleted() 的对象。因此,请确保您调用的是正确的对象。

关于java - 错误“找不到符号 - 方法 isCompleted(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20313586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com