Hey guys,
I currently have the following code(look below). When program is ran no errors occur, however the output isn't correct, and i've spent the past few hours trying to figure out but can't. So i've given up trying now aha, if anyone has any idea that'd be great.
Here is the output:
VVCap Image
As you see the toppings are completely messed up, no idea why. Any guidance appreciated.
/* */ import java.util.Scanner; import java.text.DecimalFormat; public class Pizza { public Pizza(String string, int pepCost) { // TODO Auto-generated constructor stub } public static void main(String [ ] args) { //Create a Scanner object to read input Scanner keyboard = new Scanner (System.in); String Name; //user's first name int inches; //size of the pizza String crustType; //code for type of crust String crust = "Hand-tossed"; //name of crust double cost = 12.99; //cost of the pizza final double TAX_RATE = .08; //sales tax rate double tax; //amount of tax char choice; //user's choice String input; //user input String toppings = "Cheese "; //list of toppings int numberOfToppings = 0; //number of toppings String Address; //prompt user and get first name System.out.println("Dominos Pizza "); System.out.print("Enter your first name: "); Name = keyboard.nextLine(); System.out.print("Please, enter your delivery address: "); Address = keyboard.nextLine(); //determine if user is eligible for discount by //having the same first name as one of the owners //ADD LINES HERE FOR TASK #1 //Pizza Costs int pepCost = 10; int ctCost = 8; int sfCost = 12; //prompt user and get pizza size choice Pizza Pep = new Pizza("Pepperoni Pizza", pepCost); Pizza ct = new Pizza("Pepperoni Pizza", ctCost); Pizza seafood = new Pizza("Pepperoni Pizza", sfCost); //Topping Costs double bCost = 1.75; double cCost = 1.75; double eCost = 1.75; double pCost = 1.75; //*****************Topping objects***************************** Toppings Bacon = new Toppings("Bacon",bCost); Toppings Cheese = new Toppings("Cheese",cCost); Toppings Egg = new Toppings("Egg",eCost); Toppings prawn = new Toppings("Prawn",pCost); //*****CRUST COSTS************************* int thinCost = 1; double deepCost = 1.50; //*****CRUST TYPES************************* CrustType thin = new CrustType("thin", thinCost); CrustType deepDish = new CrustType("DeepDish", deepCost); //***********USER INPUT************** System.out.println("What is your preference of crust?"); System.out.println(thin); System.out.println(deepDish); System.out.println("Choose your desired crust type"); crustType = keyboard.nextLine(); System.out.print("Do you want"+ Bacon + "?"); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Bacon "; } System.out.print("Do you want"+ Cheese + "?"); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Cheese "; } System.out.print("Do you want"+ Egg + "?"); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Egg"; } System.out.print("Do you want"+ prawn + "?"); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Prawn "; } //display order confirmation System.out.println(); System.out.println("Confirmation order: "); //System.out.println(inches + " inch pizza"); System.out.println(crust + " crust"); System.out.println(toppings); //*******************WORKING OUT COST********************************************************** System.out.println("Total cost: £" + cost); cost = cost + (1.25*numberOfToppings); //calculate and display tax and total cost System.out.println("Toal cost:" + (cost+1.75*numberOfToppings)); System.out.println("Thank you for shopping, with Dominos."); } }