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

  • SEARCH
  • Home
  • 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 8192869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:16:52+00:00 2026-06-07T04:16:52+00:00

I need to store the following line items on a receipt: quantity, description, upc,

  • 0

I need to store the following line items on a receipt: quantity, description, upc, and price.

What is the best method in Java to store these? I need to print them to an output at some point by line, just like a receipt printer would. The number of elements in the collection should be arbitrary though because I will be adding and deleting elements.

5 item1 new item 324234  $4.99
1 item2 dish soap 34235346 $6.33

..and so on

  • 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-07T04:16:53+00:00Added an answer on June 7, 2026 at 4:16 am

    I would think about creating some objects that would reflect the items you want to represent. For example, perhaps you might have a Receipt object that has a List of ReceiptItems.

    public class Receipt {
        private List<LineItem> receiptItems;
    
        // ... 
    
        public void add(LineItem lineItem) {
            // be mindful of handling duplicates if needed
            receiptItems.add(lineItem); 
        }
    
    }
    

    Each of your items would contain the values you wish to keep track of

    public class LineItem {
        private int quantity;
        private String description;
        private String upc;
        private BigDecimal price; // depending on the accuracy you need, you might be able to get away with double
    
        // ...
    
        public String getDescription() {
            return description;
        }
    
        // ... add more getters to your heart's content ...
    }
    

    UPDATE:

    To access the private methods, you would create a few getters or action methods. I’ve added a few above as an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did you ever have the following situation: you need to store information, but a
I need store just 10 arrays in my app, which I can change from
I have id values for products that I need store. Right now they are
I need to store a very large amount of instances of my class, and
I need to store a login session when the user is login and remove
I need to store GPS coordinates in a database. I've heard that floats are
I need to store user credentials in my app. I can store and retrieve
I need to store locally on android devices some images I get from the
I need to store lotto numbers in a SQL database. There are 8 separate
I need to store a huge number of elements in a std::vector (more that

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.