Ice Cream Inventory

Learn Intermediate Java | Codecademy

I need help with Intermediate Java project Ice Cream Inventory. I have step 1 done and the begining of 2. I need help in general with it all.

Hi, there!

What exactly are you having trouble with? Perhaps I can help explain.

Hi, pretty much everything in that project I need help with.

Well, the first thing I would suggest if you’re having trouble with the concepts in the entire project, would be to go back and review previous lessons on what is being asked to be done.

But let’s take a look at this together.

You said you have step one done, and the beginning of step 2. So, as of right now your code should look something like this:

class ShopItems {
  int totalCount;

  class NonVegan {
    int iceCreamCount;
    int shakeCount;
    int totalCount;

    void increaseCount(int type, int count) {
        if (type == 1) {
            this.iceCreamCount += count;
        } else if (type == 2) {
            this.shakeCount += count;
        }
     }
   }
}

The second part of step two is asking you to increase the totalCount variable of NonVegan and ShopItems
image

Essentially, increasing totalCount by the parameter count

The hint below step 2 should be able to guide you the correct direction.

Thank you, for step 3, do I need to create “Shopping Items”?
3.

Inside ShoppingItems, create a class named Vegan that contains the following fields:

Well, if you look at the instructions for steps 3 and 4, you’ll recognize that they are exactly the same as steps 1 and 2. (Other than making the class name and parameters different).

image

Is a typo and is supposed to be ShopItems as in the first step.

There is another typo in the instructions here:

image

Where it is supposed to be inside the main of IceCreamShop

Ok, thank you, I was stressing myself out because of the typo. I got through step 4 and 5. Now I’m on step 6.
Complete the if-statement within the while loop in the main() method. Call the proper increaseCount() method within each if or else if block based on the type of order and whether it is vegan or non-vegan. Use the following table as a guide:

type number kind of treat class
1 ice cream non-vegan
2 shake non-vegan
3 smoothie vegan
4 slushie vegan

Hint

Here is an example of how you may call the function increaseCount() for shakes:

nonVegan.increaseCount(2,itemCount);

So for this step, what it is asking you to do inside the if…else statement is to call the increaseCount() method with the appropriate class just as the hint is telling you to do so.

For instance, if you were to do what was explained in the example, it would look like this:

image

You would only need to do the same for the three other options.

So would I put the new 'else if’s under the ‘if’ statements I created earlier or create new ‘if’ statements? or something like this?

Wait, no. You put that inside the already created block above.
image

OH, i didn’t scroll down far enough.

1 Like

I have 1 error left. I’m not sure how to fix it. I’m assuming it’s a really simple fix.

I have 1 error left. I’m not sure how to fix it. I’m assuming it’s a really simple fix.

I will not be available for the next hour or so, could you post the entirety of your code? If you have not figured it out by the time I get back I will take a look at it for you. :slight_smile:

Thank you! I really appreciate your help!

import java.util.Scanner;

class ShopItems {
int totalCount;

class NonVegan {
int iceCreamCount;
int shakeCount;
int totalCount;

  ShopItems items = new ShopItems();

ShopItems.NonVegan vegan = items.new NonVegan();
ShopItems.Vegan nonVegan = items.new Vegan();

void increaseCount(int type, int count) {
    if (type == 1) {
        this.iceCreamCount += count;
    } else if (type == 2) {
        this.shakeCount += count;
    }
 }

}
class Vegan {
int smoothieCount;
int slushieCount;
int totalCount;

   void increaseCount(int type, int count) {
    if (type == 3) {
        this.smoothieCount += count;
    } else if (type == 4) {
        this.slushieCount += count;
    }
 }

}

public class IceCreamShop {

public static void main(String args) {
int orderType = 0;
Scanner input = new Scanner(System.in);
int itemCount = 0;
String itemName;

System.out.println("Hello! Welcome to the ice cream shop. We are ready to take your order. For ice-cream type 1, for shakes type 2, for smoothies type 3, and for slushies type 4. If you are done ordering type 0.");
orderType = input.nextInt();

while(orderType != 0) {
  System.out.println("How many items of this item would you like to order?");
  itemCount = input.nextInt();
  if(orderType == 1){
    itemName = "ice cream";
    nonVegan.increaseCount(1,itemcount);
  } else if(orderType == 2) {
    itemName = "shake";
      nonVegan.increaseCount(2,itemcount);
  } else if(orderType == 3) {
    itemName = "smoothie";
    vegan.increaseCount(3,itemcount);
  } else if(orderType == 4) {
    itemName = "slushie";
    vegan.increaseCount(4,itemcount);
  } else {
    break;
  }

  System.out.println("Adding " + itemCount + " of the item "+ itemName + " to your order!");

  System.out.println("Type a number for the next item in your order:\n1: Ice cream\n2: Shake\n3: Smoothie\n4: Slushie\n");
  orderType = input.nextInt();

  System.out.println(" Thank you for your order! Today we have sold " + items.totalCount + " orders of sweetness!");

  System.out.println(nonVegan.totalCount + " items have been ice cream and shakes.");

  System.out.println(vegan.totalCount + " items have been smoothies and slushies.");
}

}
}

So, there a few problems I see.

These class declarations you want inside the IceCreamShop main() method.

And if you look at these parameters, itemcount is not a valid variable. Looking at your code, do you see why?

I moved the
“ShopItems items = new ShopItems();
ShopItems.NonVegan vegan = items.new NonVegan();
ShopItems.Vegan nonVegan = items.new Vegan();”
into IceCreamShop Main().

and for the (1,Itemcount); I did not capitalize itemCount.

1 Like

The last thing I will mention (since your code should be working now) is that you may want to move the last three System prints outside of the while loop, otherwise those will print every single time an item is entered rather than after the final count.

  while(orderType != 0) {
    System.out.println("How many items of this item would you like to order?");
    itemCount = input.nextInt();
    if(orderType == 1){
      itemName = "ice cream";
      nonVegan.increaseCount(1,itemcount);
    } else if(orderType == 2) {
      itemName = "shake";
        nonVegan.increaseCount(2,itemcount);
    } else if(orderType == 3) {
      itemName = "smoothie";
      vegan.increaseCount(3,itemcount);
    } else if(orderType == 4) {
      itemName = "slushie";
      vegan.increaseCount(4,itemcount);
    } else {
      break;
   }
    System.out.println("Adding " + itemCount + " of the item "+ itemName + " to your order!");
    System.out.println("Type a number for the next item in your order:\n1: Ice cream\n2: Shake\n3: Smoothie\n4: Slushie\n");
    orderType = input.nextInt();
  }

  System.out.println(" Thank you for your order! Today we have sold " + items.totalCount + " orders of sweetness!");
  System.out.println(nonVegan.totalCount + " items have been ice cream and shakes.");
  System.out.println(vegan.totalCount + " items have been smoothies and slushies.");
}

YAY it works! Thank you for your help! Another question I have is, what alternative learning source would you recommend to help me understand java?

1 Like

Well, I don’t feel too comfortable advertising competitor courses and such on Codecademy. :sweat_smile:

What I would recommend is just Googling “learn Java” and see what resources come up. It’s really easy to look at reviews to see what other people are saying. You could also look at top creator’s on YouTube who offer tutorials on topics you want to learn.