I'm trying to make a store-type program where you can add a max of 10 items to your cart and at the end, it will display the set cost. You can choose the amount of one item you buy too, but for whatever reason, whenever I select to buy more than 1 of the first item, the switch statement skips the entirety of the next item and jumps to the third item.
Is there anything I can do to fix this?
Here's the code itself:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
//Shopping Cart
int cart = 0;
/****
STOCK
****/
//Swords
int swordcost = 500;
int swordstock = 5;
int swordcount = 0;
//Elixirs
int elixircost = 345;
int elixirstock = 7;
int elixircount = 0;
//Charms
int charmcost = 213;
int charmstock = 2;
int charmcount = 0;
//Arrows
int arrowcost = 5;
int arrowstock = 5;
int arrowcount = 0;
//Spellbooks
int spellbookcost = 899;
int spellbookstock = 1;
int spellbookcount = 0;
//Boots
int bootcost = 60;
int bootstock = 15;
int bootcount = 0;
//Travel Sack
int travelsackcost = 65;
int travelsackstock = 7;
int travelsackcount = 0;
//Hammers
int hammercost = 780;
int hammerstock = 3;
int hammercount = 0;
//Saddles
int saddlecost = 540;
int saddlestock = 4;
int saddlecount = 0;
//Capes
int capecost = 45;
int capestock = 18;
int capecount = 0;
//Cost
int cartcost = (swordcount * swordcost) + (elixircount * elixircost) + (charmcount * charmcost) + (arrowcount * arrowcost) + (spellbookcount * spellbookcost) + (bootcount * bootcost) + (travelsackcount * travelsackcost) + (hammercount * hammercost) + (saddlecount * saddlecost) + (capecount * capecost);
/****
SHOPPING
****/
Scanner a = new Scanner(System.in);
System.out.println("Warner: Welcome to Warner's Weaponary and Wizardly Wares! What is your name, traveller?");
String b = a.nextLine();
System.out.println("You: " + b + "\nWarner: Nice to meet ya, " + b + "! What can I do you for?");
System.out.println("Say what, ya look like a swordsman, can I intrest you in some of our fine blades? |CHOICES: yes | no|");
String c = a.nextLine();
if (c.equalsIgnoreCase("yes")) {
System.out.println("You: Yes \nWarner: Here they are, there's 5 to choose from. How many would you like?");
int d = a.nextInt();
switch (d) {
case 1:
System.out.println("You: One, please \nWarner: Here it is.");
swordcount++;
cart++;
break;
case 2:
System.out.println("You: Two, please \nWarner: Here are two swords.");
swordcount+=2;
cart+=2;
break;
case 3:
System.out.println("You: Three, please \nWarner: Here are three, that's quite a few");
swordcount+=2;
cart+=2;
break;
case 4:
System.out.println("You: Four, please \nWarner: Are you constantly breaking your blade?");
swordcount+=4;
cart+=4;
break;
case 5:
System.out.println("You: Five, please \nWarner: I'm not selling you my entire stock. Here's one.");
swordcount++;
cart++;
break;
}
} else if (c.equalsIgnoreCase("no")) {
System.out.println("You: No thank you \nWarner: Sure thing traveller.");
}
System.out.println("Warner: We also have powerful elixirs to give you big boosts to your skills!");
System.out.println("Warner: We have 7 packs of two. Take a peek and tell me if you want any |CHOICES: sure | no |");
String e = a.nextLine();
if (e.equalsIgnoreCase("sure")) {
System.out.println("You: Sure \nWarner: How many would you like? You can only take a maximum of two");
int f = a.nextInt();
switch (f) {
case 1:
System.out.println("You: One, please \nWarner: Here it is.");
elixircount++;
cart++;
break;
case 2:
System.out.println("You: Two, please \nWarner: Here you go.");
elixircount+=2;
cart+=2;
break;
case 3:
System.out.println("You: " + f + ", please \nWarner: What part of you can only take two do you not understand, my friend?");
System.out.println("Warner: In fact, you can have none.");
break;
}
} else if (e.equalsIgnoreCase("no")) {
System.out.println("Warner: Tough crowd, I see.");
}
System.out.println("Warner: Anyway, into charms or advanced archery? |CHOICES: archery | charms | neither |");
String g = a.nextLine();
switch (g) {
case "archery":
System.out.println("You: Archery \nWarner: Hey-ho, my as well " + b + "! We 5 five bundles of 20 arrows for 5 pieces");
System.out.println("Warner: How many bundles would you like?");
int h = a.nextInt();
switch (h) {
case 1:
System.out.println("Warner: Here's a bundle, that'll be five pieces");
}
}
}
}
I've tried changing the indents, rewriting the code block, and outright removing it. None of those attempts worked.