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 8449995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:51:10+00:00 2026-06-10T10:51:10+00:00

So i have a string array full of different vodkas, what i want to

  • 0

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)

  • 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-10T10:51:12+00:00Added an answer on June 10, 2026 at 10:51 am

    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:

    import java.util.ArrayList;
    
    public class VodkaList {
    
        public class Vodka {
    
            String name;
            double price; 
    
            public Vodka(String name, double price) {
                this.name = name;
                this.price = price;
            }
    
            public String getName() {
                return this.name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
    
            public double getPrice() {
                return this.price;
            }
    
            public void setPrice(double price) {
                this.price = price;
            }
    
    
        }
    
        public ArrayList<Vodka> vodkaList;
    
        public VodkaList() {
            this.vodkaList = new ArrayList<Vodka>();
    
            // here's where you can hard-code the list of Vodkas
            vodkaList.add(new Vodka("Absolut Vodka", 15.75));
            vodkaList.add(new Vodka("Findlandia", 10.25));
            // and repeat until you've hard-coded them all
        }
    
    
    }
    

    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:

    VodkaList vl = new VodkaList();
    

    Want to loop through the list and see which Vodkas you put in?

    for (Vodka vodka : vl.vodkaList)
        Log.i("Vodka", "Name = " + vodka.name + ", Price = " + vodka.price);
    

    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.

    for (Vodka vodka : vl.vodkaList) {
        if (vodka.getPrice() < 10)
            ; // the price is good! the user wants it.  show them it
        else
            ; // too expensive for the user.. don't show it
    }
    

    This class will make this sort of activity easy!

    Tell me if that works. If not, I’ll offer more suggestions.

    EDIT:

        Random random = new Random();
        boolean available = false;
    
        for (Vodka v : vodkaList) {
            if (v.price <= Price)
                available = true;
        }
    
        TextView text21 = (TextView) findViewById(R.id.display2);
    
        if (available) {
            // There exists at least one Vodka lower than the user's price
            int randomIndex = -1;
            while (true) {
                randomIndex = random.nextInt(vodkaList.size());
                Vodka v = vodkaList.get(randomIndex);
                if (v.price <= Price) {
                    // We have a match!  Display it to the user
                    text21.setText(v.name);
                    break;
                }
                // If we got here, there's no match.. loop again!
    
            }
        } else {
            // No vodka exists unders the users price! Can't display anything
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string array str[10][3] , it is full of values. Now I want
I have an array full of strings with each string being a name. Some
I have a string array of 3 different command line commands. Instead of writing
I have a string array in C named args[] - now how can I
I have an ArrayList full of strings arrays that I built like this: String[]
I have a fixed length character array I want to assign to a string.
I have a string array in C# and I intend to copy it in
I have a string array: string[] authors = new string[3]; authors[0] = Charles Dickens;
I have a string array selectCancel with setter and getter methods, which is a
I have a string array which holds the name of 500 stocks. Now i

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.