Correct the indentation errors in this code for import java.util. Scanner;public class GATestpublic static void main(String|] arg){ boolean repeat = true;while(repeat){ Scanner myScanner = new Scanner (System. in);System.out.print("\nEnter string to guess--»");String goal = myScanner.nextLine);System.out.print(Enter number of organisms per generation--»");int popSize = Integer.parseInt (myScanner.next));System.out.print("Enter numberof generations-->");int generations =Integer. parseInt (myScanner. next));System.out.print (Entermutation probability-->"):double mutateProb = Double.parseDouble (myScanner.next ());System. out.println();Population aPopulation = newPopulation(goal, popSize, generations.mutateProb) :aPopulation. iterate();System.out.println("Repeat? y/n");String answer = myScanner.next();if (answer. toUpperCase() .equals (“Y”);repeat = true;elserepeat = false;}}{import java.util. Random;public class Organism implements Comparable«Organism»{String value, goalString;double fitness;int n;Random myRandom = new Random();public Organism(String goalString){value=“”;this.goalString=goalString;this.n= goalString.length();for(int i=0; i<n; i++);{int j = myRandom. nextInt(27); //formerly 271f(j==26)value=value+" “;//else if (j==27) value = value+"”; //else if (j= 28) value=value+".";int which = myRandom. nextInt(2);if(which==0)j=j+65;elsej=j+97;value=value+ (char)j;{{{public Organism(String goalString, String value, int n){this.goalString=goalString;this.value = value;this.n=n;{public Organism(){}public String getValue(){ return this.value;}public voidsetValue (String value){this.value = value;{public String toString(){ return value +” “+ goalString+” "+getFitness(goalString);{public int getFitness(String aString)int count =0;for(int i=0; i< this.n; i++)if(this.value.charAt(1)== aString.charAt(1))count++;return count;}public int compareTo(Organism other){int thisCount, otherCount; thisCount=getFitness (goalString); otherCount=other. getFitness (goalString);if (thisCount == otherCount)return 0;else if (thisCount < otherCount)return 1;elsereturn-1;}public Organism[] mate(Organism other){Random aRandom = new Random();int crossOver = aRandom.nextInt(n);String child1=“”, child2="”;for (int i=0; i< crossOver; i++){child1=child1+this.value.charAt(i);child2 = child2+other .value.charAt(i);}for (int 1= crossOver; i<n; i++){child1=child1+other .value.charAt (1);child2=child2+this.value.charAt (1);}Organism[] children= new Organism[2];children[0] = new Organism(goalString, child1,n);children[1] = new Organism(goalString, child2, n);//System.out.println(“In mate"+children[0].getFitness(goalString));return children;}public void mutate(double mutateProb){String newString="”;for (Int i=0; i< n; i++){int k = myRandom. nextInt (100) ;if (k/100.0 >mutateProb)newString = neString+value.charAt(i);else{int j = myRandom. nextInt (27);if (j==26)newString=newString+" “;else{int which = myRandom. nextInt (2);if (which ==0)j=j +65;elsej=j+97;newString = newString+(char)j;}}}this.setValue(newString);}}
Correct the indentation errors in this code for
import java.util. Scanner;
public class GATest
public static void main(String|] arg)
{
boolean repeat = true;
while(repeat)
{
Scanner myScanner = new Scanner (System. in);
System.out.print("\nEnter string to guess--»");
String goal = myScanner.nextLine);
System.out.print(Enter number of organisms per generation--»");
int popSize = Integer.parseInt (myScanner.next));
System.out.print("Enter number
of generations-->");
int generations =
Integer. parseInt (myScanner. next));
System.out.print (Enter
mutation probability-->"):
double mutateProb = Double.parseDouble (myScanner.next ());
System. out.println();
Population aPopulation = new
Population(goal, popSize, generations.
mutateProb) :
aPopulation. iterate();
System.out.println("Repeat? y/n");
String answer = myScanner.next();
if (answer. toUpperCase() .equals (“Y”);
repeat = true;
else
repeat = false;
}
}
{
import java.util. Random;
public class Organism implements Comparable«Organism»
{
String value, goalString;
double fitness;
int n;
Random myRandom = new Random();
public Organism(String goalString)
{
value=“”;
this.goalString=goalString;
this.n= goalString.length();
for(int i=0; i<n; i++);
{
int j = myRandom. nextInt(27); //formerly 27
1f(j==26)
value=value+" “;
//else if (j==27) value = value+"”;
//else if (j= 28) value=value+".";
int which = myRandom. nextInt(2);
if(which==0)
j=j+65;
else
j=j+97;
value=value+ (char)j;
{
{
{
public Organism(String goalString, String value, int n)
{
this.goalString=goalString;
this.value = value;
this.n=n;
{
public Organism()
{
}
public String getValue()
{
return this.value;
}
public void
setValue (String value)
{
this.value = value;
{
public String toString()
{
return value +” “+ goalString+” "+getFitness(goalString);
{
public int getFitness(String aString)
int count =0;
for(int i=0; i< this.n; i++)
if(this.value.charAt(1)== aString.charAt(1))
count++;
return count;
}
public int compareTo(Organism other)
{
int thisCount, otherCount; thisCount=getFitness (goalString); otherCount=other. getFitness (goalString);
if (thisCount == otherCount)
return 0;
else if (thisCount < otherCount)
return 1;
else
return-1;
}
public Organism[] mate(Organism other)
{
Random aRandom = new Random();
int crossOver = aRandom.nextInt(n);
String child1=“”, child2="”;
for (int i=0; i< crossOver; i++)
{
child1=child1+this.value.charAt(i);
child2 = child2+other .value.charAt(i);
}
for (int 1= crossOver; i<n; i++)
{
child1=child1+other .value.charAt (1);
child2=child2+this.value.charAt (1);
}
Organism[] children= new Organism[2];
children[0] = new Organism(goalString, child1,n);
children[1] = new Organism(goalString, child2, n);
//System.out.println(“In mate"+children[0].getFitness(goalString));
return children;
}
public void mutate(double mutateProb)
{
String newString="”;
for (Int i=0; i< n; i++)
{
int k = myRandom. nextInt (100) ;
if (k/100.0 >mutateProb)
newString = neString+value.charAt(i);
else
{
int j = myRandom. nextInt (27);
if (j==26)
newString=newString+" “;
else
{
int which = myRandom. nextInt (2);
if (which ==0)
j=j +65;
else
j=j+97;
newString = newString+
(char)j;
}
}
}
this.setValue(newString);
}
}
Unlock instant AI solutions
Tap the button
to generate a solution