#Assignment problem (help me ! D:)

40 messages · Page 1 of 1 (latest)

muted ferry
#

I would honestly appreciate if somebody could explain this to me. I know this is something that can be fixed easily and I don't understand how.

The insertArticles option doesn't actually insert the articles immediately like it is supposed to. It does it AFTER expanding the array, so basically you have to re-type Option 1 and then how many articles you would like to insert.

gusty bronzeBOT
#

This post has been reserved for your question.

Hey @muted ferry! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

ocean dew
#

Isn't that method overwriting articles at the beginning?

muted ferry
#

The thing I don't get is why the code basically adds new articles after like, 2 runs, instead of doing it directly.

#

Do you have any idea? If you could be concrete it would help a lot.

ocean dew
#

it deletes the first few articles and replaces them

#

or not?

muted ferry
#

Look

#
  1. Insert articles
  2. Remove an article
  3. Display a list of articles
  4. Register a sale
  5. Display order history
  6. Sort and display order history table.
    q. Quit
    1
    How many articles do you want to add?
    2
    There are not enough free slots.
    I need to expand the array by 2 slots.

Article Table


Item number Amount Price
1000 7 177
1001 1 9
1002 10 55
1003 7 151
1004 8 9
1005 7 74
1006 4 10
1007 5 63
1008 10 139
1009 10 162

  1. Insert articles
  2. Remove an article
  3. Display a list of articles
  4. Register a sale
  5. Display order history
  6. Sort and display order history table.
    q. Quit
    1
    How many articles do you want to add?
    2

Article Table


Item number Amount Price
1000 7 177
1001 1 9
1002 10 55
1003 7 151
1004 8 9
1005 7 74
1006 4 10
1007 5 63
1008 10 139
1009 10 162
1009 4 145
1010 7 145

  1. Insert articles
  2. Remove an article
  3. Display a list of articles
  4. Register a sale
  5. Display order history
  6. Sort and display order history table.
    q. Quit
gusty bronzeBOT
ocean dew
muted ferry
#

i asked to insert 2, and after doing the same process twice it added one new article

#

I use replit

ocean dew
#

in the last article table

#

so it seems like it did insert two article

#

just one is a duplicate

muted ferry
#

It used to work before with the same code, but when I fixed another method it affected this somehow.

ocean dew
#

What about the following approach: You first check whether it is full and expand it if necessary and after it, you insert the articles?

#
    public static int[][] insertArticles(int[][] articles, int noOfArticles) {
        System.out.println("How many articles do you want to add?");
        int numberOfArticles = userInput.nextInt();

        int articlesInserted = 0;
        if (articlesInserted < numberOfArticles) {
            articles = checkFull(articles, numberOfArticles);
        }
        for (int row = 0; row < articles.length && articlesInserted < numberOfArticles; row++) {
            for (int column = 0; column < 3; column++) {
                if (articles[row][column] == 0) {
                    articles[row][0] = articleNumber;
                    articles[row][1] = (int) (Math.random() * 10) + 1;
                    articles[row][2] = 145;
                    articlesInserted++;
                    articleNumber++;
                }
            }
        }

        printArticles(articles);
        return articles; // Return the modified articles array
    }
#

something like that

muted ferry
#

correct

#

You wrote that?

#

Just like now?

muted ferry
ocean dew
#

maybe you need to change articles[row][0] = articleNumber; to articles[row][0] = articleNumber+1;

muted ferry
gusty bronzeBOT
muted ferry
#

Java is very fun, but an uphill battle lol

gusty bronzeBOT
muted ferry
#

I will get eclipse.

ocean dew
# gusty bronze

that can really help you with finding out where the problems are

muted ferry
#

So I can use debugger

ocean dew
#

yeah you should definitely use an IDE