ok my getBreadInfo code is
public static String[] getBreadInfo()
{
ArrayList<String> breadsList = new ArrayList<>();
try (BufferedReader in =
new BufferedReader(
new FileReader("bread.txt")))
{
String line = in.readLine();
while (line != null)
{
String[] elems = line.split("~");
breadsList.add(elems[0]+ " $" + elems[1]);
line = in.readLine();
}
}
catch(IOException e)
{
System.out.println(e);
return null;
}
String[] breadInfo = breadsList.toArray(new String[]{});
return breadInfo;
}
and in my main app to display this array is as
public static void displayBreadMenu()
{
System.out.println("=== Select Sandwich Bread ===");
String[] breadInfo = SandwichDB.getBreadInfo();
for (String breads : breadInfo)
{
System.out.println(breads);
}
}
it prints on console as
=== Select Sandwich Bread ===
White bread 1.50
Wheat bread 1.80
French bread 2.00
Organic bread 2.30
How would I add an integer value to associate with each array? like
1 White bread
2 Wheat bread
3 French bread
4 Organic bread
i’m told my getBread() is similar to getBreadInfo, except it only contains the
bread name, and return another array bread[] for SandwichApp to figure
out which bread the user selected because user type in a number
associate with the bread (index+1), rather than bread name.
Do i write the integer value in my getbread() or is the getBread just to check which bread the user selected?
how about having an counter and appending it while adding to the list.