• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hi I'm new to coding and getting into arrays, I want to know how to collect specific information

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I want to collect specific data from a list to get the elements I want but don't know how to approach that. I have already curated list of information that has matching index throughout all 4 list so for example the parent class is Ice cream. One list is for icecream name, color, availability( Common or Not Common), and Review (Good or Bad). So the list look like List 1: Names - Rocky Road[0], List2: color - brown[0], List3: availability - Common [0], and List4: Review - Good [0]. (IDK if that wasn't already clear.)

I want to create a code that can tell me an Icecream's name, color, availability, and review but only with my asked condition. So I would ask for "green" icecreams and so it would print out the amount of green icecreams, the names, availability, and review. Any type of advice would be appreciated Thank you.

I've tried scanner methods and get methods but don't know how to implement them to a condition to get a specific element from a list. So far I've had to manually insert information I want to print via method.add(String) with a scanner class. And I'm looking more for a data collect then sort program.

I understand this is an extensive project and I would appreciate any help. So even an explanation/ list of what you think could work would help because I don't know where to start, Thanks.

edit: I should have made it clear the list are list in 4 separate files that were part of a template I made.
 
Saloon Keeper
Posts: 10927
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off having four lists to maintain in sync is not the Object Oriented way to do things. Create an IceCream class with 4 member variables and then just have a single list  of IceCream objects.
Secondly, Color, Availability, and Review have a fixed set of options and so should be implemented as enums.
Here is an example also showing an implementation of equals() that will only match on the selected fields.
 
Barry's Boothang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This helps sm, Thank you.  But I've been working with a template for the project that has 4 files that just list data should I still take this approach?
 
Bartender
Posts: 5549
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

If you have been given a template, then you should use that. Can you show us that template?

A problem with using four lists is for instance, is that if you sort one of these lists, you must somehow keep the other lists in sync, and that is far from easy.
 
Marshal
Posts: 79948
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, welcome to the Ranch

Piet Souris wrote:. . . A problem with using four lists is . . . you must somehow keep the other lists in sync . . .

I would go further and say that design is an accident waiting to happen. You can of course have multiple Lists or arrays of IceCream objects, and sort them by different features. As for sorting, have a look at this Java™ Tutorials section. Maybe this section will help you, too. There are methods like clone(), which allows you to copy an array, or you could try new XYZList(myOldList) to create a copy of a List.
 
Marshal
Posts: 8957
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Barry's Boothang wrote:edit: I should have made it clear the list are list in 4 separate files that were part of a template I made.


Template you made or template you have been given?

What Piet asked still remains. Can you share that template?
 
Carey Brown
Saloon Keeper
Posts: 10927
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Barry's Boothang wrote: I've been working with a template for the project that has 4 files that just list data should I still take this approach?

Keeping the data in four separate files has some of the same issues as keeping them in four separate arrays: what if the file entries get out of sync? In situations like yours a typical file structure to store a list of some object type (e.g. IceCream) would be using comma separated values (CSV). Each row would represent a single object and each column would represent an attribute of that object. For IceCream it would look like:
To load it into an array of IceCream objects you'd loop through the lines in the CSV file and for each line use String[] data = line.split( "," ); to break out the individual columns and build an IceCream object.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic