I have a Java program – which uses genetic algorithms – in which I generate a random binary string. From here, I calculate the fitness of said string and print the fitness to the output console.
I am now attempting to display the string, but I am having trouble doing this. My intention is to display the string, then mutate it by changing one gene, and then recalculate the fitness. However, whenever I try to print the string, I receive this in the output window:
Individual@23fc4bec //FYI: Class name is 'Individual'
This is my code – in the main method – so far:
Individual newIndi = new Individual();
System.out.println(newIndi.fitness);
System.out.print(newIndi);
The problem occurs on the last line – I have also attempted the following:
System.out.print(newIndi.toString());
but this still produces a similar result.
You need to override the toString method in you
Individual-Class.Note: eclipse can generate you some basic toString() methode for your class (Source > Generate toString()).