#My collections list wont print
30 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @gusty swallow! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
split it in two messages?
or only post the relevant parts
Please format your code & make it more readable.
For the java programming language, it should look like this:
```java
public class Main{
public static void main(String[] args){
System.out.println("Hello World!");
}
}```
• These are backticks, not quotes.
public static void main(String[] args) throws FileNotFoundException {
Scanner file = new Scanner(new File("/Users/michaelbalogun/Desktop/Lab11/src/main/java/applicant_data.csv"));
ArrayList<candidate> applicants = new ArrayList<>();
DecimalFormat round = new DecimalFormat("#.##");
while (file.hasNextLine()) {
String line = file.nextLine();
String[] candidates = line.split(",");
if (candidates.length >= 9) {
try {
candidate c = new candidate(candidates[0], candidates[1], candidates[2], candidates[3], candidates[4], candidates[5], candidates[6], candidates[7],
Double.parseDouble(candidates[8]), candidates[9], candidates[10]);
applicants.add(c);
} catch (NumberFormatException e) {
}
}
}
ArrayList<candidate> finalists = new ArrayList<>();
for (candidate c : applicants) {
String s1 = c.languages.toLowerCase();
if (s1.contains("java")) {
finalists.add(c);
}
}
Collections.sort(finalists);
System.out.println("The list of top 10 selected Java students are: ");
for (int i = 0; i < Math.min(10, finalists.size()); i++) {
System.out.println(finalists.get(i));
}
}
System.out.println(finalists.get(i));
wont print
It looks like you are having issues with debugging or issues that can be solved using a debugger.
Check out this article on dev.java to see how debugging works and how to use a debugger.
This Stack Overflow question and its answers also explain debugging in general.
These links describe how to use the debugger in some IDEs:
• Debugging in IntelliJ
• Debugging in Eclipse
Well it's better to check than to think
You should display information at all stages, was the split correct, are the fields where they're expected, is "java" there where expected...
Ideally with a debugger, but you can make do with whatever you know in the beginning
for soem reason my applicants gets added to
but i cant add to my finalists
ArrayList<candidate> finalists = new ArrayList<>();
for (candidate x : applicants) {
String lang = x.languages.toLowerCase();
if (lang.contains("java")) {
finalists.add(x);
}
}
Collections.sort(finalists);
System.out.println(finalists.size());
System.out.println("The list of top 10 selected Java students are: ");
for (int i = 0; i < Math.min(10, finalists.size()); i++) {
System.out.println(finalists.get(i));
}
}
maybe none of the languages contain java?