Hey! guys, i need help figurering out how to make this program ran.

Jack has decided his student organization is going to sell Oktoberfest shirts at Oktoberfest. In order to compete with other clubs, he wants to offer a 10% discount to anyone who buys 5 or more shirts. Also, Jack is going to have several promotional ads before Oktoberfest to try and boost sales at his booth. If a customer mentions the ad, they receive $2.00 off their order. Jack wants the output of the program to display the quantity ordered plus the total due so everyone working at the booth can see how many shirts need to be given to the customer and also how much money to collect. Jack will be selling the shirts for $10.00 each.
Complete this program using JOptionPane and if-else statements

Not really good at the if-else statement so i would like someone to point out my mistakes.

Below is my code:

import javax.swing.JOptionPane;


public class Oktoberfest3
{
	public static void main(String[] args)
	{
		double	shirtCount, discount, answer, total;


		shirtCount = 0;
		discount = 0.1;
		total = 0.0;


		shirtCount= Double.parseDouble(JOptionPane.showInputDialog("Enter total shirt count"));

	if(shirtCount >= 5)
			{
				discount= (shirtCount* 10) * 0.1;
				total= (shirtCount * 10) - discount;
			}

	else if (shirtCount <= 4);
			{
				total= (shirtCount * 10);

			}


	int answer1 = y;
	int answer2 = n;


	int y = JOptionPane.showConfirmDialog("Did customer mention ad?",JOptionPane.YES_NO_OPTION);
	if (y == JOptionPane.YES_OPTION)
			{
				discount= (shirtCount* 10) * 0.1;
				total= ((shirtCount * 10) - discount) - 2;
			}
	else if (n == JOptionPane.NO_OPTION)
			{
				total= (shirtCount * 10);
			}

    }

}

Recommended Answers

All 5 Replies

Some suggestions:
line 17 - use Integer not Double - no fractions of shirts here!
lines 39/40, 44 - these calculations overwrite the values you calculated earlier. If the answer was Yes you need to add some extra discount, and take something off the already-calculated total.

I see what you are saying. So if i change line 17 from double to int for integer, shouldn't i change line 32 & 33 to double because they are not integers?

I don't see what you are using answer1/2 for, so I can't comment on what kind of variable they should be.

well, basically i'm trying to have a "yes" and "no" dialog box that if selected will give two different results. In other words, if the # of shirts is 5 or > then their is a 10% discount, else if # of shirts is <=4 ni 10% is given. Then i want a 2nd dialog window that asks if the ad is mentioned. if "yes" then an extra $2 off the total. if no then no $2 off.

i am new at java and not good with programs with words like yes or no. I am somewhat good at numbers though.

Lines 36/37 seem to handle that second dialog pretty well - although you need to fix up the following if clauses a bit. You defined answer1/2, but you haven't used them, and I can't see any immediate use for them. Maybe they're not needed?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.