import javax.swing.JOptionPane; public class test { int pepToppings = 0; int mushToppings = 0; int totalToppings = 0; int smallPizza = 0; int pizzaCount = 0; int smallPizzaTotal = 0; String[] toppingsArray = { "pepperoni", "mushroom"}; int[] numToppingsArray = { pepToppings, mushToppings }; int[] numToppingsOrderedArray = { pepToppings, mushToppings }; public void onHand() { for( int i = 0; i < toppingsArray.length; i++ ) { numToppingsArray[i] = Integer.parseInt(JOptionPane.showInputDialog("Please enter number of " + toppingsArray[i] + " toppings on hand:", "0" )); System.out.println(toppingsArray[i] + " on hand:\t" + numToppingsArray[i]); } } public void orderedToppings() { //brings up pizza input dialog smallPizza = Integer.parseInt(JOptionPane.showInputDialog ( "How many small pizzas would you like to order?" , "0" )); pizzaCount += smallPizza; //computes total number of small pizzas ordered smallPizzaTotal = smallPizza + smallPizzaTotal; String smallToppings = JOptionPane.showInputDialog ( "What kind of toppings do you want on your small pizza?\nWe currently have pepperoni and mushroom.\n" + "Please enter your toppings with spaces in between (ex: pepperoni mushroom)\nFor cheese only, please click OK." ); int smallCount = 0; int smallToppingsTotal = 0; String[] arr = smallToppings.split(" "); smallCount = 0; for(int i = 0; i <arr.length;i++) {//start for if(arr[i].equals("")) {//start if smallCount = 0; }//end if else {//start else smallCount++; }//end else }//end for //computes total number of small toppings ordered smallToppingsTotal = (smallCount * smallPizza) + smallToppingsTotal; String nameToFind = smallToppings; boolean found = false; int location = -1; int i = 0; String output = ""; do { if( nameToFind.equals(toppingsArray[i]) ) { found = true; location = i; if (numToppingsArray[i] > smallToppingsTotal) { numToppingsArray[i] = numToppingsArray[i] - smallToppingsTotal; System.out.println("We can make your pizza."); } else System.out.println("We can't make your pizza."); } i++; } while( found == false && i < toppingsArray.length ); if( location != -1 ) { if (numToppingsArray[location] <= 0) { JOptionPane.showMessageDialog( null, "We are out of those toppings, sorry." ); } else { output += "\n" + nameToFind + " found at nameArray[" + location + "]" + "there are " + numToppingsArray[location] + " left!"; JOptionPane.showMessageDialog( null, output, "Original and Sorted Array", JOptionPane.INFORMATION_MESSAGE ); } } else { output += "\n" + nameToFind + " not found in nameArray[]"; JOptionPane.showMessageDialog( null, output, "Original and Sorted Array", JOptionPane.INFORMATION_MESSAGE ); } } public void check() { for( int i = 0; i < toppingsArray.length; i++ ) { System.out.println(toppingsArray[i] + " on hand:\t" + (numToppingsArray[i] - numToppingsOrderedArray[i])); } } public static void main( String[] args ) { test pizza = new test(); pizza.onHand(); pizza.orderedToppings(); int checkInv = 0; checkInv = JOptionPane.showConfirmDialog(null , "Would you like to check the inventory?" , "Pizza Palace" , JOptionPane.YES_NO_OPTION); if (checkInv == JOptionPane.YES_OPTION) { pizza.check(); } else { System.out.print("Thanks!"); } } }
package com.gaurav; import javax.swing.JOptionPane; publicclass test { int pepToppings = 0; int mushToppings = 0; int totalToppings = 0; int smallPizza = 0; int pizzaCount = 0; int smallPizzaTotal = 0; int totalAvailableToppings = 0; boolean NotEnoughQuantity = false; String[] toppingsArray = { "pepperoni", "mushroom" }; int[] numToppingsArray = { pepToppings, mushToppings }; int[] numToppingsOrderedArray = { pepToppings, mushToppings }; public void onHand() {for (int i = 0; i < toppingsArray.length; i++) {} public void orderedToppings() {numToppingsArray[i] = Integer.parseInt(JOptionPane.showInputDialog("Please enter number of " + toppingsArray+ " toppings on hand:", "0"));totalAvailableToppings = totalAvailableToppings[i]+ numToppingsArray;[i]System.out.println(toppingsArray + " on hand:\t"[i]+ numToppingsArray);}// brings up pizza input dialog[i]smallPizza = Integer.parseInt(JOptionPane.showInputDialog("How many small pizzas would you like to order?", "0"));pizzaCount += smallPizza;// computes total number of small pizzas orderedsmallPizzaTotal = smallPizza + smallPizzaTotal;String smallToppings = JOptionPane.showInputDialog("What kind of toppings do you want on your small pizza?\nWe currently have pepperoni and mushroom.\n"+ "Please enter your toppings with spaces in between (ex: pepperoni mushroom)\nFor cheese only, please click OK.");String[] arr = smallToppings.split(" ");for(int j =0;j<arr.length;j++) {String nameToFind = arr[j];int location = -1;for(int i=0;i<toppingsArray.length;i++){} } public void check() {if (nameToFind.equals(toppingsArray)) {} String output = " "; if ((location !=-1) && arr.length>1 && totalAvailableToppings>=arr.length*smallPizza) {location = i;[i]System.out.println(nameToFind + " found at location " +location);break;}JOptionPane.showMessageDialog(null, " Checking " + nameToFind + "topping .....",null,JOptionPane.INFORMATION_MESSAGE);if(numToppingsArray[location]>=smallPizza){} else if((location !=-1) && arr.length==1 && totalAvailableToppings>=smallPizza) {numToppingsArray[location] = numToppingsArray[location]- smallPizza;System.out.println("Enough " + nameToFind + " is avilable for this order");} else {NotEnoughQuantity = true;}JOptionPane.showMessageDialog(null, " Checking " + nameToFind + " topping .....",null,JOptionPane.INFORMATION_MESSAGE);if(numToppingsArray[location]>=smallPizza){} else if(!(totalAvailableToppings >=arr.length*smallPizza)) {numToppingsArray[location] = numToppingsArray[location]- smallPizza;} else {NotEnoughQuantity = true;}NotEnoughQuantity = true;System.out.println(" System crash ");System.out.println("We can't make your pizza.");} if (location != -1) {if (NotEnoughQuantity){} else {JOptionPane.showMessageDialog(null,"We are out of "+ nameToFind +" topping, sorry.");} else {output += "\n Enough " + nameToFind + " topping available for this order";JOptionPane.showMessageDialog(null, output,"Original and Sorted Array",JOptionPane.INFORMATION_MESSAGE);}output += "\n" + nameToFind + " not found in nameArray[]";JOptionPane.showMessageDialog(null, output,"Original and Sorted Array",JOptionPane.INFORMATION_MESSAGE);}for (int i = 0; i < toppingsArray.length; i++) {} public static void main(String[] args) {System.out.println(toppingsArray + " on hand:\t"[i]+ (numToppingsArray[i] - numToppingsOrderedArray));}test pizza = new test();pizza.onHand();pizza.orderedToppings();int checkInv = 0;[i]checkInv = JOptionPane.showConfirmDialog(null,"Would you like to check the inventory?", "Pizza Palace",JOptionPane.YES_NO_OPTION);if (checkInv == JOptionPane.YES_OPTION) {} }pizza.check();} else {System.out.print("Thanks!");}
.
import javax.swing.JOptionPane; public class testingCode { int pepToppings = 0; int mushToppings = 0; int meatballToppings = 0; int totalAvailableToppings = 0; int smallPizza = 0; int pizzaCount = 0; int smallPizzaTotal = 0; String[] toppingsArray = { "pepperoni", "mushroom", "meatball" }; int[] numToppingsArray = { pepToppings, mushToppings, meatballToppings }; int[] numToppingsOrderedArray = { pepToppings, mushToppings, meatballToppings }; //sets number of toppings on hand public void onHand() {//start method onHand for (int i = 0; i < toppingsArray.length; i++) {//start for numToppingsArray[i] = Integer.parseInt (JOptionPane.showInputDialog("Please enter number of " + toppingsArray[i] + " toppings on hand:", "10")); totalAvailableToppings = totalAvailableToppings + numToppingsArray[i]; System.out.println(toppingsArray[i] + " on hand:\t" + numToppingsArray[i]); }//end for }//end method onHand public void order() {//start method order //asks customer how many small pizzas they would like to order smallPizza = Integer.parseInt (JOptionPane.showInputDialog("How many small pizzas would you like to order?", "5")); pizzaCount += smallPizza; smallPizzaTotal = smallPizza + smallPizzaTotal; //asks the customer what kind of toppings they want String smallToppings = JOptionPane.showInputDialog("What kind of toppings do you want on your small pizza?", "pepperoni mushroom"); //splits each toppings into an array String[] arr = smallToppings.split(" "); int smallCount = 0; //counts how many toppings there are (just by words) for(int k = 0; k <arr.length;k++) {//start for smallCount = 0; if(arr[k].equals("")) {//start if smallCount = 0; }//end if else {//start else smallCount++; }//end else //searches for topping in toppingsArray for(int j = 0; j <arr.length;j++) {//start for //sets arr[j] to nameToFind (String to search for) String nameToFind = arr[j]; //sets number of toppings ordered to an array numToppingsOrderedArray[k] = (smallCount * smallPizza); //if found, check to see if there are enough, otherwise we can't make it for(int i = 0; i <toppingsArray.length;i++) {//start for if (nameToFind.equals(toppingsArray[i])) {//start if //total toppings ordered (ie. 5 small pepperoni pizzas, charge them for 5 pepperoni toppings) System.out.println("\nTotal " + toppingsArray[i] + " ordered: " + numToppingsOrderedArray[k]); //doesn't do anything, just text System.out.println("Checking to see if there are enough " + toppingsArray[i] + " left..."); //checks to see if there are enough toppings available if (numToppingsArray[i] > numToppingsOrderedArray[k]) {//start if System.out.println("There are enough " + toppingsArray[i] + " to make your pizza."); //removes number of toppings ordered from those on hand numToppingsArray[i] = numToppingsArray[i] - numToppingsOrderedArray[k]; System.out.println(toppingsArray[i] + " on hand:\t" + (numToppingsArray[i]) + "\n"); }//end if else {//start else System.out.println("We can't make your pizza.\n"); }//end else }//end if }//end for }//end for }//end for }//end method order public void check() {//start method check for( int i = 0; i < toppingsArray.length; i++ ) {//start for System.out.println(toppingsArray[i] + " on hand:\t" + numToppingsArray[i]); }//end for }//end method check public static void main( String[] args ) {//start main testingCode pizza = new testingCode(); pizza.onHand(); pizza.order(); int checkInv = 0; checkInv = JOptionPane.showConfirmDialog(null , "Would you like to check the inventory?" , "Pizza Palace" , JOptionPane.YES_NO_OPTION); if (checkInv == JOptionPane.YES_OPTION) {//start if pizza.check(); }//end if else {//start else System.out.print("Thanks!"); }//end else }//end main }//end class testingcode
| DaniWeb Message | |
| Cancel Changes | |