The first block is all of my methods and stuff and the second block is just the driver. i'm trying to get it to ask the user if it wants to repeat the whole thing again, but it only works with the last 2 choices
import java.util.*;
public class methodsForTest
{
Scanner input = new Scanner(System.in);
public void choose()
{
System.out.println("Which method do you want to do?");
System.out.println("Choose from:");
System.out.println("\t square \n\t rectangle \n\t triangle\n");
String choice = input.nextLine();
if(choice.equals("square"))
{
square();
}
else if(choice.equals("rectangle"))
{
rectangle();
}
else if(choice.equals("triangle"))
{
triangle();
}
else
{
System.out.println("That's not a choice.");
}
}
public void square()
{
System.out.println("Enter length of side.");
int side = input.nextInt();
for (int x = 0; x<side; x++)
{
for (int y = 0; y<side; y++)
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
public void rectangle()
{
System.out.println("Enter height.");
int height = input.nextInt();
System.out.println("Enter width.");
int width = input.nextInt();
for (int x = 0; x<height; x++)
{
for (int y = 0; y<width; y++)
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
public void triangle()
{
System.out.println("Enter side length. This method will print out an equilateral triangle.");
}
public String repeat()
{
System.out.println("Another method? \nChoose yes or no.");
String repeat = input.nextLine();
return repeat;
}
}
import java.util.*;
public class test
{
Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
String repeat = "yes";
while (repeat.equals("yes"))
{
methodsForTest choice = new methodsForTest();
choice.choose();
repeat = choice.repeat();
}
}
}