Results 1 to 5 of 5

Thread: Need help

  1. #1
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Need help

    Hi there.

    I am doing a school assignment. I am very lost and about to give up. I have tried everything I can think of. First, I am supposed to design a console program that is an inventory. This inventory is supposed to use one array that contains the inventory number, the product name, the stock number (how much is in stock), and the value of the inventory. The array is also supposed to be sortied printing the information one line at a time. I have tried everything I can think of and I cannot figure this out. I am not asking anyone to write me code or asking for code. I need some suggestions and some direction here. Thank you. :)

    Here is the Bubblesort that I have tried to use:

    //Define Bubblesort variables
    int a, b, t;
    int size;

    //Declare the size variable
    size = 3;

    for (a = 1; a < size; a++)
    for(b=size-1; b >= a; b--){

    if (arrayName[b-1] > arrayName[b]){

    //Exchange elements
    t = arrayName[b-1];
    arrayName[b-1] = arrayName[b];
    arrayName[b] = t;
    }
    }

    This does not seem to work with strings. However, how do I make it so that I store all of those items in one array?
    How do I sort the array and print it one line at a time?

    Also, I am supposed to use a method to sort the array and calculate the inventory value. How do I do this as well?

    Thanks!
    Last edited by BenH; 01-29-2012 at 01:53 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help

    Quote Originally Posted by BenH View Post
    I am doing a school assignment. I am very lost and about to give up. I have tried everything I can think of. First, I am supposed to design a console program that is an inventory. This inventory is supposed to use one array that contains the inventory number, the product name, the stock number (how much is in stock), and the value of the inventory. The array is also supposed to be sortied printing the information one line at a time. I have tried everything I can think of and I cannot figure this out. I am not asking anyone to write me code or asking for code. I need some suggestions and some direction here. Thank you. :)
    I'm going to ask you to improve this question because as written, we can't help you much other than to refer you to the Java tutorials.

    First off, please re-name your thread title. The title is not supposed to "express the depth of your anguish" but rather is supposed to summarize your problem much like a newspaper heading is supposed to summarize the article below. This is so that experts in whatever problem you're having will quickly identify your question and help you. Your current title "Need help" tells us little other than what we already know. Of course you need help, otherwise you wouldn't be posting here, and many in this forum will ignore non-informative titles such as yours.

    Next you tell us your assignment and tell us that you've tried and failed but you show us none of your attempts nor what was wrong with your attempts. Without this information we have no idea where your errors are, what assumptions you have wrong or how to help you. Since we're not going to do the assignment for you, about all we can do (again) is to refer you to the tutorials.

    Next you don't ask any specific questions about what exactly you're confused about. Specific questions usually get specific helpful answers.

    So please give us more information, your code (with code tags), and some specific questions, and let's see what we can do to help you.

    Best of luck.

  3. #3
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Re: Need help

    So sorry about that. I asked specific questions. :) I couldn't figure out how to change the title name though.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help

    I would make a class to hold all of the information for one item, say called Product, and it would have a String for the item's product name, a String or int (depending on your requirements) for the inventory number, an int for the stock number, and a double for its value. I'd give this class a constructor that would initialize these fields through parameters, and I'd give the class setter methods for each field.

    I'd then create an array of Product type.

    As for sorting, the first thing you need to know is how you're supposed to sort the objects? Is it based on inventory number? The product name? something else?

  5. #5
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Re: Need help

    My instructor said I could sort through quantity.
    Thanks for the help :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •