Created
May 17, 2021 16:40
-
-
Save kshitijvarshne1/97b2b4323f6cda5ab6160a9667b3d873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 16-May-21 | |
* Time: 5:11 PM | |
* File: Pizza.java | |
*/ | |
package May.may16_21; | |
public class Pizza { | |
public final static float SMALL_PRICE = 5.50f; | |
public final static float MEDIUM_PRICE = 9.10f; | |
public final static float LARGE_PRICE = 13.70f; | |
private String size; | |
private String crust; | |
private Toppings toppings; | |
private float price; | |
public Pizza(String size, String crust, Toppings toppings) { | |
this.size = size; | |
this.crust = crust; | |
this.toppings = toppings; | |
this.price = 0.0f; | |
} | |
public String getSize() { | |
return size; | |
} | |
public void setSize(String size) { | |
this.size = size; | |
} | |
public String getCrust() { | |
return crust; | |
} | |
public void setCrust(String crust) { | |
this.crust = crust; | |
} | |
public Toppings getToppings() { | |
return toppings; | |
} | |
public void setToppings(Toppings toppings) { | |
this.toppings = toppings; | |
} | |
public void calculatePrice() { | |
if (this.size.equalsIgnoreCase("small")) { | |
this.price += SMALL_PRICE; | |
} else if (this.size.equalsIgnoreCase("medium")) { | |
this.price += MEDIUM_PRICE; | |
} else { | |
this.price += LARGE_PRICE; | |
} | |
if (this.crust.equalsIgnoreCase("thick")) { | |
this.price += 2.20f; | |
} | |
if (this.toppings.getSauceOrBarbequeFlavouredSauce().equalsIgnoreCase("tomato-paste sauce")) { | |
this.price += 1.00f; | |
} else { | |
this.price += 1.80f; | |
} | |
for (int i = 0; i < this.toppings.getMeatAndSeaFood().length; i++) { | |
this.price += this.toppings.findPrice(this.toppings.getMeatAndSeaFood()[i]); | |
} | |
for (int i = 0; i < this.toppings.getOtherTopings().length; i++) { | |
this.price += this.toppings.findPrice(this.toppings.getOtherTopings()[i]); | |
} | |
} | |
public String toString() { | |
calculatePrice(); | |
String result = this.size + " "; | |
result += this.crust + "-crust pizza, with " + this.toppings.getSauceOrBarbequeFlavouredSauce() + " "; | |
String top = ""; | |
for (int i = 0; i < this.toppings.getMeatAndSeaFood().length; i++) { | |
top += this.toppings.getMeatAndSeaFood()[i] + " ,"; | |
} | |
for (int i = 0; i < this.toppings.getOtherTopings().length; i++) { | |
top += this.toppings.getOtherTopings()[i] + " ,"; | |
} | |
top += " pirce: $" + this.price; | |
result += top; | |
return result; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 16-May-21 | |
* Time: 6:29 PM | |
* File: Shop.java | |
*/ | |
package May.may16_21; | |
import java.util.Scanner; | |
public class Shop { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("==== Welcome ===="); | |
System.out.println("You have atmost select 3 types of pizzas"); | |
System.out.println("If you not add the pizza then press 1 or else 0"); | |
for (int i = 0; i < 3; i++) { | |
int check = sc.nextInt(); | |
if (check == 0) { | |
System.out.println("Thanks for using me"); | |
System.exit(0); | |
} else if (check == 1) { | |
sc.nextLine(); | |
System.out.println("It is tomato-paste sauce or BarbequeFlavouredSauce type pizza"); | |
String sauce = sc.nextLine(); | |
showSizeType(); | |
String sizeType = sc.nextLine(); | |
showCrustType(); | |
String crust = sc.nextLine(); | |
showMeatToppings(); | |
int sizeMeat = sc.nextInt(); | |
sc.nextLine(); | |
String[] meatToppings = null; | |
if (sizeMeat != 0) { | |
meatToppings = new String[sizeMeat]; | |
for (int j = 0; j < sizeMeat; j++) { | |
int k = j + 1; | |
System.out.println("Enter the " + k + " st toppings"); | |
meatToppings[j] = sc.nextLine(); | |
} | |
} | |
int restToppings = 8 - sizeMeat; | |
System.out.println("you have to select " + restToppings + " toppings"); | |
System.out.println("Enter the number of toppings not greater than " + restToppings); | |
int other = sc.nextInt(); | |
showOtherToppings(); | |
String[] topp = null; | |
sc.nextLine(); | |
if (other != 0) { | |
topp = new String[other]; | |
for (int i1 = 0; i1 < other; i1++) { | |
int k = i1 + 1; | |
System.out.println("Enter the " + k + " st toppings"); | |
topp[i1] = sc.nextLine(); | |
} | |
} | |
Pizza pizza = new Pizza(sizeType, crust, new Toppings(sauce, meatToppings, topp)); | |
System.out.println(pizza); | |
System.out.println("If you not add more pizza then press 1 or else 0"); | |
} else { | |
System.out.println("Invalid input"); | |
} | |
} | |
} | |
public static void showSizeType() { | |
System.out.println("Here is the size of pizzas"); | |
System.out.println("1. small , 2. medium , 3.large"); | |
} | |
public static void showCrustType() { | |
System.out.println("Here is the curst types"); | |
System.out.println("1. thin , 2. thick"); | |
} | |
public static void showMeatToppings() { | |
System.out.println("Here is toppings list"); | |
System.out.println("1. ham , 2. salami , 3. bacon , 3. chicken , 4.shrimp"); | |
System.out.println("You have select at most 3 toppings from this category"); | |
System.out.println("How many you want to select? -> 0 or 1 or 2 or 3"); | |
} | |
public static void showOtherToppings() { | |
System.out.println("Here is the rest toppings list"); | |
System.out.println("1. capsicum , 2. onion , 3. tomatoes , 4. mushrooms , 5.pineapple , " + | |
"6. egg , 7. olives , 8. garlic , 9. cheese , 10. pumpkin"); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 16-May-21 | |
* Time: 5:20 PM | |
* File: Toppings.java | |
*/ | |
package May.may16_21; | |
import java.util.HashMap; | |
public class Toppings { | |
private String sauceOrBarbequeFlavouredSauce; | |
private String[] meatAndSeaFood; | |
private String[] otherTopings; | |
public HashMap<String, Float> toppingsPrice; | |
public Toppings(String sauceOrBarbequeFlavouredSauce, String[] meatAndSeaFood, String[] otherTopings) { | |
this.sauceOrBarbequeFlavouredSauce = sauceOrBarbequeFlavouredSauce; | |
this.meatAndSeaFood = meatAndSeaFood; | |
this.otherTopings = otherTopings; | |
toppingsPrice = new HashMap<>(); | |
addALlPrice(); | |
} | |
public String getSauceOrBarbequeFlavouredSauce() { | |
return sauceOrBarbequeFlavouredSauce; | |
} | |
public void setSauceOrBarbequeFlavouredSauce(String sauceOrBarbequeFlavouredSauce) { | |
this.sauceOrBarbequeFlavouredSauce = sauceOrBarbequeFlavouredSauce; | |
} | |
public String[] getMeatAndSeaFood() { | |
return meatAndSeaFood; | |
} | |
public void setMeatAndSeaFood(String[] meatAndSeaFood) { | |
this.meatAndSeaFood = meatAndSeaFood; | |
} | |
public String[] getOtherTopings() { | |
return otherTopings; | |
} | |
public void setOtherTopings(String[] otherTopings) { | |
this.otherTopings = otherTopings; | |
} | |
public void addALlPrice() { | |
toppingsPrice.put("tomato-paste sauce", 1.00f); | |
toppingsPrice.put("barbeque-flavoured", 1.80f); | |
toppingsPrice.put("ham", 0.50f); | |
toppingsPrice.put("salami", 0.50f); | |
toppingsPrice.put("bacon", 0.90f); | |
toppingsPrice.put("chicken", 2.00f); | |
toppingsPrice.put("shrimp", 1.40f); | |
toppingsPrice.put("capsicum", 0.30f); | |
toppingsPrice.put("onion", 0.20f); | |
toppingsPrice.put("tomatoes", 0.40f); | |
toppingsPrice.put("mushrooms", 0.45f); | |
toppingsPrice.put("pineapple", 0.45f); | |
toppingsPrice.put("egg", 0.25f); | |
toppingsPrice.put("olives", 0.35f); | |
toppingsPrice.put("garlic", 0.30f); | |
toppingsPrice.put("cheese", 0.20f); | |
toppingsPrice.put("pumpkin", 0.50f); | |
} | |
public float findPrice(String topping) { | |
if (toppingsPrice.get(topping.toLowerCase()) == null) { | |
return 0.0f; | |
} | |
return toppingsPrice.get(topping.toLowerCase()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment