So i need help with picking the pizza size as you can see for the if PizzaSize if i end up just using else if with the !Pizza.equals blablba it will result in massive error it says like PizzaInches and so on notrecognizable but with the current code right now everything that i pick will result in S small size even though it print the correct size that the user put in.
So yeah: if the string is not equal to "M", "L" or "H" , set it to "S"
Please help
Attach is the assignment instructions
import java.util.Scanner; //So the user can write also
/*
* PizzaOrder
* The goal of this software is to create an organize and detail order for a pizza for the user
* A software which let the user input numeric and letter and later will be calculate for the price that the user need to pay
*
* Anthony Liestyo
*
* OS: Windows 8
* Hardware: PC
*
* Sept 27th 2013
*/
public class PizzaOrder {
public static void main(String[] args) {
// TODO code application logic here
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter pizza size (S, M, L, or H): "); //Pizza sizes for the user to enter
String PizzaSize = keyboard.nextLine() ; //Print the answer in next line
PizzaSize = PizzaSize.substring(0, 1); //So it will only take the first letter
double PizzaInches; // Double = number with decimal places
double PizzaPrice; // Int = number with no decimal places
if (PizzaSize == "S") //If statement for different sizes of pizza resulting in different variation of answers
{
PizzaSize = "S";
PizzaInches = 8;
PizzaPrice = 5;
}
else if (PizzaSize == "M")
{
PizzaSize = "M";
PizzaInches = 13;
PizzaPrice = 8;
}
else if (PizzaSize == "L")
{
PizzaSize = "L";
PizzaInches = 21;
PizzaPrice = 13;
}
else if (PizzaSize == "H")
{
PizzaSize = "H";
PizzaInches = 34;
PizzaPrice = 21;
}
else if (!PizzaSize.equals("M") && !PizzaSize.equals("L") && !PizzaSize.equals("H") && !PizzaSize.equals("m") && !PizzaSize.equals("l") && !PizzaSize.equals("h"))
{
PizzaSize = "S";
PizzaInches = 8;
PizzaPrice = 5;
}
else
{
//PizzaSize = "S";
PizzaInches = 8;
PizzaPrice = 5;
}
System.out.println("Pizza Size: " + PizzaSize.toUpperCase()); //to let the lowercase letter become Capital/uppercase
System.out.println("Enter the number of toppings you want: (0-5)");
double Toppings = keyboard.nextInt();
if (Toppings < 0) //Toppings less than 0 become 0
{
Toppings = 0;
System.out.println("Your toppings is smaller than 0, resetting it to " + Toppings);
}
else if (Toppings > 5) //TOppings bigger than 5 become 5
{
Toppings = 5;
System.out.println("Your toppings is bigger than 5, resetting it to " + Toppings);
}
else if (Toppings >= 0 && Toppings <= 5) //Toppings greater than 0 and toppings less than 5 then toppings = toppings
{
Toppings = Toppings;
System.out.println("You have selected " + Toppings + " toppings for your pizza");
}
double Area = 3.14 * (PizzaInches/2) * (PizzaInches/2); //Area Formula for circle/pizza: 3,14 r * r
double subTotal = PizzaPrice + (Toppings * 0.89); //subTotal : PizzaPrice + (Toppings * 0.99)
double roundSubTotal = Math.floor(subTotal*100)/100; //roundSubTotal : Rounding to the lowest 2 decimal points
double Tax = subTotal * 0.095; //Tax is 9.5% of the subTotal
double roundTax = Math.floor(Tax*100)/100; //roundTax : Rounding to the lowest 2 decimal points
double Total = Tax + subTotal; //Total is the tax + subTotal
double roundTotal = Math.floor(Total*100)/100; //roundTotal : Rounding to the lowest 2 decimal points
double PricePerInch = roundSubTotal/Area; //PricePerInch : price for each inches square
double RoundPricePerInch = Math.floor(PricePerInch*100)/100; //roundPricePerInch : Rounding to the lowest 2 decimal points
//These are the output for the results that we calculated earlier
System.out.println("Pizza diameter: " + PizzaInches);
System.out.println("Pizza baseprice: $" + PizzaPrice);
System.out.println("Pizza Size: " + PizzaSize + " (" + PizzaInches + " inches -- " + Area + " square inches)");
System.out.println("Toppings: " + Toppings);
System.out.println("Price: " + "$" + roundSubTotal);
System.out.println("Tax: $" + roundTax);
System.out.println("Total Price: $" + roundTotal);
System.out.println("Price/sq.in.: $" + RoundPricePerInch);
}
}
Question
atyemail
So i need help with picking the pizza size as you can see for the if PizzaSize if i end up just using else if with the !Pizza.equals blablba it will result in massive error it says like PizzaInches and so on not recognizable but with the current code right now everything that i pick will result in S small size even though it print the correct size that the user put in.
So yeah: if the string is not equal to "M", "L" or "H" , set it to "S"
Please help
Attach is the assignment instructions
P1.pdf
Link to comment
Share on other sites
10 answers to this question
Recommended Posts