#output is wrong
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Without seeing your code or knowing the specific output you are getting, it is difficult to determine the exact cause of the issue. However, here are a few common reasons why your Java output might be incorrect:
-
Syntax errors: Check for any syntax errors in your code, such as missing semicolons or parentheses. These errors can cause unexpected behavior and incorrect output.
-
Logic errors: Review your code's logic to ensure that it is correctly solving the problem you are trying to solve. A small mistake in your logic can lead to incorrect output.
-
Variable values: Double-check the values of your variables throughout the program. Make sure they are assigned and updated correctly to produce the desired output.
-
Loop conditions: If you have loops in your code, verify that their conditions are correct and will terminate when expected. Incorrect loop conditions can lead to unexpected or infinite loops.
-
Input/output handling: If your program relies on user input or file input/output, make sure you handle them correctly and validate their correctness.
-
Data types and conversions: Ensure that you are using appropriate data types for variables and performing necessary type conversions when needed. Incorrect data types can result in unexpected output.
-
Libraries or external dependencies: If you are using any external libraries or dependencies, make sure they are correctly installed and used in your code.
To identify the specific issue in your code, it would be helpful if you could provide more details about what your program is supposed to do, along with a snippet of the relevant code and the actual versus expected output that you are observing.
This is your output you say? And the one at top is expected?
yep
Why is expected output empty tho
Your code checks birth month, if it's even then goes to even list otherwise odd
yes
they're in the right even/odd population its just the district thats wrong
yup
this is my output which is wrong
this is the output that i should be getting
should i send my code because i changed it a bit
Yea
so the first picture is me setting up the districts with the input file
then the second picture is me attempting to put those people into their designated districts
Can you verify if your getDestrict method is working properly, before that also verify districtId is also correct.
yup both are working fine
what is districts? where it's declared?
id like to see the whole class file
okay
import java.util.ArrayList;
public class District {
private ArrayList<Person> oddPopulation;
private ArrayList<Person> evenPopulation;
private int districtID;
public District(int id) {
oddPopulation = new ArrayList<>();
evenPopulation = new ArrayList<>();
districtID = id;
}
public void addOddPerson(Person person) {
oddPopulation.add(person);
}
public void addEvenPerson(Person person) {
evenPopulation.add(person);
}
public ArrayList<Person> getOddPopulation() {
return oddPopulation;
}
public ArrayList<Person> getEvenPopulation() {
return evenPopulation;
}
public void setOddPopulation(ArrayList<Person> op) {
oddPopulation = op;
}
public void setEvenPopulation(ArrayList<Person> ep) {
evenPopulation = ep;
}
public int size() {
return oddPopulation.size() + evenPopulation.size();
}
public int getDistrictID() {
return districtID;
}
public String toString() {
return "ID: " + districtID + ", Odd Population: " + oddPopulation + ", "
+ "Even Population: " + evenPopulation;
}
}
Detected code, here are some useful tools:
@livid belfry
you're calling districts.get(districtID), where is the get method? Assuming districts is an instance of District class?
yes
districtID should be the array elements while districts is the array