import java.util.Scanner;
class AlbumTester
{
private static void printChoices()
{
System.out.println("add\nadd <0 or positive int>\nshow\nquit");
}
public static void main(String[] asdf)
{
Scanner sc = new Scanner(System.in);
System.out.println("Album capacity:");
int requestedCapacity = sc.nextInt();
sc.nextLine();
//Read and throw away the newline after the int
Album myAlbum = new Album(requestedCapacity);
System.out.println("Pick the directory for your digital images.");
FileChooser.pickMediaPath();
boolean stillChoosing = true;
int nAdds = 0;
while( stillChoosing )
{
printChoices();
String choice = sc.nextLine();
if(choice.equals("quit"))
{
System.out.println("Thanks for the test!");
stillChoosing = false;
}
else if(choice.equals("add"))
{
System.out.println("You chose add");
Picture p = new Picture(FileChooser.pickAFile());
boolean added;
added = myAlbum.addPicture(p);
if(added) nAdds++;
else System.out.println("addPicture(Picture) returned false.");
}
else if(choice.equals("show"))
{
System.out.println("You chose show");
System.out.println("You should see " + nAdds
+ " images in your Album");
myAlbum.explore();
}
else if(choice.startsWith("add "))
{
System.out.println("Your choice started with \"add \".");
String[] tokens = choice.split("\\s+");
//Purpose: Split the input line into tokens separated by whitespace
int inputNumber = 0;
boolean inputNumberOK = false;
try {
inputNumber = Integer.parseInt(tokens[1]);
inputNumberOK = true;
}
catch (NumberFormatException e)
{
System.out.println("Whoops, you mistyped the number after add!");
}
if(inputNumberOK)
{
Picture p = new Picture(FileChooser.pickAFile());
boolean added;
added = myAlbum.addPicture(p,inputNumber);
if(added) nAdds++;
else System.out.println("addPicture(Picture,int) returned false.");
}
}
else
{
System.out.println("The command to the tester was not recognized.");
System.out.println("Try again.");
}
}
return;
}
}
This is what goes with the class. I need to write something in the explore method so that I can continue with what this program executes which is to create a picture album.