Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:19:21+00:00 2026-06-15T09:19:21+00:00

ok my getBreadInfo code is public static String[] getBreadInfo() { ArrayList<String> breadsList = new

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:19:22+00:00Added an answer on June 15, 2026 at 9:19 am

    how about having an counter and appending it while adding to the list.

    int count=1;
     while (line != null)
                {
                    String[] elems = line.split("~");
                    breadsList.add(count+" " +elems[0]+ " $" + elems[1]);
                    line = in.readLine();
                     count++;
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just noticed that java.beans.Introspector getBeanInfo does not pickup any superinterface's properties. Example: public
A little back story here. I've got a public property (typeof(ObservableCollection<Area>)) that I bind
I have a relatively simple package of 8 Java classes generated from an XML
From Effective Java 2nd edition item 67 page 266-268: The background thread calls s.removeObserver
I have one field which is a composition of two values. This is the
I want to create embedded ActiveMQ broker using xbean configuration inside OSGi bundle running
A former colleague of mine started a discussion half an hour ago about JavaBeans,
I want to know a class's some member variable's annotations , I use BeanInfo
I got the following exception when marshalling Comment objects to JSON: javax.xml.bind.JAXBException: class javax.jdo.identity.LongIdentity
I am using introspection to retrieve a beans get methods and i'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.