#output is wrong

1 messages · Page 1 of 1 (latest)

teal mica
#

Hi can someone tell me why my output comes out like this? Im not sure where exactly in my code its going wrong but the first line is correct but almost everything else goes wrong

mint galleonBOT
#

<@&987246399047479336> please have a look, thanks.

mint galleonBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. Input/output handling: If your program relies on user input or file input/output, make sure you handle them correctly and validate their correctness.

  6. 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.

  7. 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.

teal mica
#

The picture in my description is the expected output, heres my output

livid belfry
teal mica
#

yep

livid belfry
#

Why is expected output empty tho

teal mica
#

ah shit

#

wrong picture

#

mb

#

i changed my code a bit should i send it here

livid belfry
#

Your code checks birth month, if it's even then goes to even list otherwise odd

teal mica
#

yes

livid belfry
# teal mica

Can you send both pictures again, mark as expected vs actual output

teal mica
#

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

livid belfry
#

Yea

teal mica
#

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

livid belfry
#

Can you verify if your getDestrict method is working properly, before that also verify districtId is also correct.

teal mica
#

yup both are working fine

livid belfry
teal mica
livid belfry
#

id like to see the whole class file

teal mica
#

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;
    }
}
mint galleonBOT
teal mica
#

@livid belfry

livid belfry
#

you're calling districts.get(districtID), where is the get method? Assuming districts is an instance of District class?

teal mica
#

yes

teal mica
#

districtID should be the array elements while districts is the array