Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class 1: OrderingSystem
- import java.awt.*;
- import java.util.Scanner;
- import java.text.DecimalFormat;
- /**
- * Class to manage the pizza order.
- * @author up835351
- */
- public class OrderingSystem
- {
- private Canvas canvas;
- private double Price;
- private String Topping1;
- private String Topping2;
- private String Sauce;
- private String Size;
- private String Crust;
- private double BaseArea;
- private int numberToppings;
- private int numberPizza;
- /**
- * Constructor for the ordering system.
- */
- public OrderingSystem()
- {
- canvas = new Canvas("Pizza Ordering", 900, 650);
- }
- /**
- * Method to draw the outline of the order screen.
- */
- public void drawOrderScreen()
- {
- canvas.setForegroundColor(Color.BLACK);
- // vertical dividers
- canvas.drawLine(300, 0, 300, 600);
- canvas.drawLine(600, 0, 600, 600);
- // halfway divider
- canvas.drawLine(0, 300, 900, 300);
- canvas.drawLine(0, 600, 900, 600);
- canvas.setForegroundColor(Color.BLACK);
- canvas.setFontSize(25);
- DecimalFormat df = new DecimalFormat("#.00");
- String StrPrice = df.format(this.getPrice());
- canvas.drawString("Total Price of the Order:" + StrPrice, 10, 640);
- }
- // Selecting the Sauce
- static String setSauce(){
- System.out.print("what Sauce would you like, BBQ or tomato ?: ");
- Scanner saucescanner = new Scanner(System.in);
- String Sauce = saucescanner.nextLine();
- if (Sauce.equals("BBQ")){
- System.out.print( "BBQ sauce selected ! ");
- }
- else if (Sauce.equals("Tomato")){
- System.out.print( "Tomato selected !" );
- }
- else {
- saucescanner.reset();
- System.out.print("Invalid Sauce! ");
- Sauce = setSauce();
- }
- return Sauce;
- }
- /*
- * quantity of toppings
- */
- public int startToppings()
- {
- Boolean badNumber = true;
- Scanner scanner = new Scanner(System.in);
- System.out.print("How many toppings would you like ? 1 or 2 ?: ");
- int numberToppings = scanner.nextInt();
- while (badNumber){
- if(numberToppings >=3 && numberToppings <=0){
- System.out.print('\u000C');
- System.out.print("invalid number, please try again: ");
- scanner.reset();
- Scanner tryAgain = new Scanner(System.in);
- System.out.print("How many toppings would you like ? 1 or 2 ?: ");
- numberToppings = tryAgain.nextInt();
- }
- else {
- System.out.print(numberToppings + "Topping(s) selected ");
- badNumber=false;
- }
- }
- return numberToppings;
- }
- public int numberOfPizza(){
- Boolean LoopNum = true;
- Scanner scanner = new Scanner(System.in);
- System.out.print("How many pizza's would you like ( Max. 6): ");
- int numberPizza = scanner.nextInt();
- while (LoopNum){
- if(numberPizza >0 && numberPizza <=6){
- System.out.print('\u000C');
- System.out.print("invalid number, please try again: ");
- scanner.reset();
- Scanner tryAgain = new Scanner(System.in);
- System.out.print("How many pizza's would you like ( Max. 6): ");
- numberPizza = tryAgain.nextInt();
- }
- else {
- System.out.print(numberPizza + "Pizza(s) selected ");
- LoopNum=false;
- }
- }
- return numberPizza;
- }
- /*
- * choise of toppings
- */
- static String setTopping1()
- {
- System.out.print("what would you like for your first topping, Mushroom or Peperoni ? ");
- Scanner scanner1 = new Scanner(System.in);
- String Topping1 = scanner1.nextLine();
- if (Topping1.equals("Peperoni")){
- System.out.print( "Peperoni selected ! ");
- }
- else if (Topping1.equals("Mushroom")){
- System.out.print( "Mushroom selected ! ");
- }
- else {
- scanner1.reset();
- System.out.print("Invalid Topping! ");
- Topping1=setTopping1();
- }
- return Topping1;
- }
- static String setTopping2()
- {
- System.out.print("what would you like for your second topping, Mushroom or Peperoni ? ");
- Scanner scanner2 = new Scanner(System.in);
- String Topping2 = scanner2.nextLine();
- if (Topping2.equals("Peperoni")){
- System.out.print( "Peperoni selected ! ");
- }
- else if (Topping2.equals("Mushroom")){
- System.out.print( "Mushroom selected !" );
- }
- else {
- scanner2.reset();
- System.out.print("Invalid Topping! ");
- Topping2=setTopping2();
- }
- return Topping2;
- }
- public String setSize(){
- System.out.print("What size would you like: Large, Medium or Small? : ");
- Scanner sizescanner = new Scanner(System.in);
- String Size = sizescanner.nextLine();
- if (Size.equals("Large")){
- System.out.print( "Large selected ! ");
- this.Size = Size;
- }
- else if (Size.equals("Medium")){
- System.out.print( "Medium selected !" );
- this.Size = Size;
- }
- else if (Size.equals("Small")){
- System.out.print( "Small selected !" );
- this.Size = Size;
- }
- else {
- sizescanner.reset();
- System.out.print("Invalid Size! ");
- setSize();
- }
- return Size;
- }
- public double baseArea(String Size){
- BaseArea=0;
- if (Size.equals("Large")){
- BaseArea = 153.94;
- }
- else if (Size.equals("Medium")){
- BaseArea = 113.0976;
- }
- else if (Size.equals("Small")){
- BaseArea = 78.54;
- }
- return BaseArea;
- }
- public double getPrice(){
- return Price;
- }
- public String Crust(){
- System.out.print("What crust would you like: Deep Pan, Thin Crust or Stuffed Crust? : ");
- Scanner crustscanner = new Scanner(System.in);
- String Crust = crustscanner.nextLine();
- if (Crust.equals("Deep Pan")){
- System.out.print( "Deep Pan selected ! ");
- this.Crust = Crust;
- }
- else if (Crust.equals("Thin Crust")){
- System.out.print( "Thin Crust selected !" );
- this.Crust = Crust;
- }
- else if (Crust.equals("Stuffed Crust")){
- System.out.print( "Stuffed Crust selected !" );
- this.Crust = Crust;
- }
- else {
- crustscanner.reset();
- System.out.print("Invalid crust! ");
- Crust();
- }
- return Crust;
- }
- public void calculatePrice(String Topping1, String Topping2, double Price, String Crust, double baseArea, Canvas canvas){
- Price = 0;
- // Topping price
- if (Topping1.equals("Mushroom")){
- Price += (0.05*5);
- }
- else {
- Price += (0.04*5);
- }
- if (numberToppings == 2){
- if (Topping2.equals("Mushroom")){
- Price += (0.05*4);
- }
- else {
- Price += (0.04*4);
- }
- }
- // Sauce price
- if (Sauce.equals("BBQ")){
- Price+= 0.50;
- }
- //Crust Price
- if (Crust.equals("Deep Pan")){
- Price += (0.11*baseArea);
- }
- if (Crust.equals("Thin Crust")){
- Price += (0.08*baseArea);
- }
- if (Crust.equals("Stuffed Crust")){
- Price += (0.14*baseArea);
- }
- System.out.print ("current price" + Price);
- this.setPrice(Price);
- }
- public void setPrice(double newPrice){
- this.Price= newPrice;
- }
- /**
- * Method to manage the ordering of the pizzas (once completed).
- */
- public void startOrdering()
- {
- Size=this.setSize();
- BaseArea = this.baseArea(Size);
- Crust= this.Crust();
- numberToppings = this.startToppings();
- Sauce = this.setSauce();
- Topping1 = this.setTopping1();
- if (numberToppings==2){
- Topping2 = this.setTopping2();
- }
- calculatePrice(Topping1,Topping2,Price,Crust,BaseArea,canvas);
- Pizza pizza1 = new Pizza(canvas, 0, 0,Topping1,Topping2, Sauce,numberToppings, Crust);
- pizza1.displayPizza();
- Pizza pizza2 = new Pizza(canvas, 300, 0,Topping1,Topping2, Sauce,numberToppings, Crust);
- pizza2.displayPizza();
- Pizza pizza3 = new Pizza(canvas, 600, 0,Topping1,Topping2, Sauce,numberToppings, Crust);
- pizza3.displayPizza();
- Pizza pizza4 = new Pizza(canvas, 0, 300,Topping1,Topping2, Sauce,numberToppings, Crust);
- pizza4.displayPizza();
- Pizza pizza5 = new Pizza(canvas, 0, 300,Topping1,Topping2, Sauce,numberToppings, Crust);
- pizza4.displayPizza();
- Pizza pizza6 = new Pizza(canvas, 0, 300,Topping1,Topping2, Sauce,numberToppings, Crust);
- pizza4.displayPizza();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement