So i have a string array full of different vodkas, what i want to do is attach a price to each vodka (string) in the array so that i can display the vodka along with its price on the screen, i also want to use this to filter out higher price or lower price vodkas depending on the users input.
Here is an example array:
public static final String[] Vodka = {"Absolut Vodka","Finlandia","Ketel One","Polmos Krakow","Skyy","Smirnoff Vodka",
"Stolichnaya","Fleischmann's","Gilbey's","Wolfschmitt","Five-O-Clock", "Grey Goose",};
Thanks in advance everyone!
=================================
Here is a bit of code i was trying out thank to mike!
if(Price != 0){
for (com.famousmods.what.should.i.drink.VodkaList.Vodka vodka : vl.vodkaList){
// Set vodka brand final
TextView text21 = (TextView) findViewById(R.id.display2);
test = random.next(vodka.getPrice() <= Price);
text21.setText(test);
}
}
The Price is the max amount that the user inputs, it a double, what i was trying to do with that piece of code was randomly get a drink that is less than the price that is inputted. (it was just a shot in the dark really)
Just make a custom class “Vodka” that has 2 fields: name and price. Then make a “VodkaList” class that encapsulates the “Vodka” class and includes an
ArrayList<Vodka>This keeps everything well organized.So, for example:
By using a custom class, you can alter the name/price of Vodka at any time, not worry about keeping track of array indices, and easily search the list for the names/prices you want.
Here’s what you’ll put in your main activity to initialize your VodkaList:
Want to loop through the list and see which Vodkas you put in?
Let’s explore a sample scenario (to address the issue in your problem statement). Let’s say the user enters “10” for the highest price he/she will pay.
This class will make this sort of activity easy!
Tell me if that works. If not, I’ll offer more suggestions.
EDIT: