Just wanted to first off come back and let you know I updated the code entirely, just to make it easier to read and also to fix some poor coding style on my own part, but the problem still stands. I think I am halfway to getting it though but here is the new code:
import java.util.Scanner; //Importing the Scanner class.
import java.text.DecimalFormat; //Importing DecimalFormat class.
public class A_Gray_PizzaPartyMild
public static void main(String args)
//Variable declaration and initialization block.
//Pizza prices and pizza sizes variables:
final double SMALL_PIZZA_PRICE = 7.99;
final double MEDIUM_PIZZA_PRICE = 11.59;
final double LARGE_PIZZA_PRICE = 19.35;
final int NUMBER_OF_SLICES_SMALL = 4;
final int NUMBER_OF_SLICES_MEDIUM = 6;
final int NUMBER_OF_SLICES_LARGE = 12;
final int MAX_EXTRA_SLICES = 3;
//Variables for number of people/slices and the number of pizzas of each size:
int numberOfPeople = 0;
int numberOfSlices = 0;
int numberOfSmallPizzas = 0;
int numberOfMediumPizzas = 0;
int numberOfLargePizzas = 0;
double orderCost = 0.00; //Will hold the total cost of the order after price calculations are completed.
//Introduce program to user.
System.out.println("\t\t\t " + "|**Welcome to**|");
System.out.println("\t\t " + "|Aaron's Pizza Party Planning Program!|");
//Create the Scanner object: keyinput.
Scanner keyinput = new Scanner(System.in);
//Create the DecimalFormat object: formatter.
DecimalFormat formatter = new DecimalFormat("#0.00"); //This object will be used to round and format the orderCost variable
//to two places.
//Prompt user to input the amount of people at the party that want pizza and how many slices they will each want.
System.out.print("\nHow many people at your party would like some pizza: ");
numberOfPeople = keyinput.nextInt();
System.out.print("How many slices are being bought per person: ");
numberOfSlices = keyinput.nextInt();
//Output required slices to feed the people at the party that requested pizza.
int requiredSlices = numberOfPeople * numberOfSlices; //Variable that will hold the required number of slices for the guests.
System.out.println("\nYou will need " + requiredSlices + " slices of pizza to feed all these hungry party-goers!");
/*Make a sequence of if statements that will run and determine how many pizzas of each size are needed
*to fulfill the required number of slices. The if structure will also calculate the cost for the order.
*This will be done by taking the required pizzas of a certain size and multiplying them by their price
*and adding it to the orderCost variable.
int currentSlices = requiredSlices; //Declare and initialize a variable that will keep track of remaining slices after each sequential step.
if(currentSlices >= NUMBER_OF_SLICES_LARGE)
numberOfLargePizzas = (currentSlices / NUMBER_OF_SLICES_LARGE);
currentSlices %= NUMBER_OF_SLICES_LARGE; /*Use modulus division to find out how many pizza slices remain.
*This will give us a remainder which we will use to see how many medium or small pizzas,
*if any, will be required.
System.out.println("\t" + numberOfLargePizzas +" large pizza(s) at $" + LARGE_PIZZA_PRICE);
orderCost += (numberOfLargePizzas * LARGE_PIZZA_PRICE); //Storing the total cost of the large pizzas into the overall orderCost.
if(currentSlices >= NUMBER_OF_SLICES_MEDIUM)
numberOfMediumPizzas = (currentSlices / NUMBER_OF_SLICES_MEDIUM); //Add MAX_EXTRA_SLICES in here?
currentSlices %= NUMBER_OF_SLICES_MEDIUM;
System.out.println("\t" + numberOfMediumPizzas +" medium pizza(s) at $" + MEDIUM_PIZZA_PRICE);
orderCost += (numberOfMediumPizzas * MEDIUM_PIZZA_PRICE);
if(currentSlices <= NUMBER_OF_SLICES_SMALL)
System.out.println("\t" + numberOfSmallPizzas +" small pizza(s) at $" + SMALL_PIZZA_PRICE);
orderCost += (numberOfSmallPizzas * SMALL_PIZZA_PRICE);
currentSlices = (numberOfLargePizzas * NUMBER_OF_SLICES_LARGE) +
(numberOfMediumPizzas * NUMBER_OF_SLICES_MEDIUM) +
(numberOfSmallPizzas * NUMBER_OF_SLICES_SMALL); //Add total number of slices by pizza size to totalSlices.
int extraSlices = currentSlices - requiredSlices; /*Declare and initialize a variable to hold the extra slices.
*Will equate to the currentSlices in the order subtracted by the requiredSlices
*needed in order to satisfy the party guests.
//Output the results of the calculations for totalSlices and extraSlices.
System.out.println("\nYour order will include " + currentSlices + " slices, which means there will be " + extraSlices + " left-over!");
//Output the results of the orderCost calculations
System.out.println("\nYour order will come to $ " + formatter.format(orderCost));
The project states that the minimum amount of extra slices we can have per order is 3, so that is the reason for the MAX_EXTRA_SLICES constant. So I actually managed to fix the first issue that we were having getting the 70 slices to output with an extra of 2. That now works. However, I am using new test data of 17 people ordering 1 slice each. This almost always returns 1 large pizza + 1 small pizza (only 16) and gives me a left-over of -1. Obviously that left-over should be +1 (1 large + 1 medium). I have been trying to find a way in my if statements to get the MAX_EXTRA_SLICES to act as range but after the first large pizza calculation, I am left with 5 slices remaining which seems to kind of just disappear. It doesnt fall into the medium pizza range but, if I was to write a condition that said if ((currentSlices >= NUMBER_OF_MEDIUM_SLICES) - MAX_EXTRA_SLICES)) it will fall under the small pizza range (<= NUMBER_OF_SMALL_SLICES...3 is less than 4). So, I am completely lost with this one. I've been trying to get help from a friend of mine who knows more than I do and he said to add MAX_EXTRA_SLICES to update currentSlices by adding it into the if statements and the calculations for the number of pizzas for a given size. I am completely lost now, ive tried every combination of if statements and ive written out the code and just cant seem to get it to click. Im probably missing the most obvious thing, but I just cant seem to get what to do.