SHARE
TWEET

Untitled

a guest Nov 16th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * A program that simulates an online order/purchase of pizza(s)
  3.  * by receiving user input and displaying a receipt.
  4.  *
  5.  * @author Tyler Wargo
  6.  * @version 1.0
  7.  */
  8.  
  9. //Imports Scanner Library
  10. import java.util.Scanner;
  11. public class OrderPizza
  12. {
  13.     public static void main(String[] args)
  14.     {
  15.         //Creates Scanner Object
  16.         Scanner in = new Scanner(System.in);
  17.        
  18.         //Display E-Shop Header
  19.         System.out.println("=============================================");
  20.         System.out.println("\t\tE - S L I C E");
  21.         System.out.println("=============================================\n");
  22.        
  23.         //Get first and last name
  24.         System.out.print("Please enter your first and last name: ");
  25.         String firstName = in.next();
  26.         String lastName = in.next();
  27.        
  28.         //Get current date (To be reformatted)
  29.         System.out.print("Please enter today's date (MM/DD/YYYY): ");
  30.         String str_currentDate = in.next();
  31.        
  32.         //Get number of pizzas
  33.         System.out.print("Please enter the type of pizza: ");
  34.         String pizzaType = in.next();
  35.        
  36.         //Get price of pizza type (To be parsed)
  37.         System.out.print("Please enter the price of the selected type of pizza: ");
  38.         String str_perPizzaPrice = in.next();
  39.        
  40.         //Get number of pizzas
  41.         System.out.print("Please enter the number of pizzas: ");
  42.         String str_numPizzas = in.next();
  43.        
  44.         //Get debit card number
  45.         System.out.print("Please enter your debit card number (#####-###-####): ");
  46.         String str_debitCardNum = in.next();
  47.        
  48.         //Get pin number
  49.         System.out.print("Please enter your pin number (#####): ");
  50.         String str_pinNum = in.next();
  51.        
  52.         //Parse, convert, and calculate variables from input to be used in receipt
  53.         String currentDate = str_currentDate.substring(0,2) + "-" + str_currentDate.substring(3,5) + "-" + str_currentDate.substring(6,10); //Reformat date through substrings
  54.         String firstNameInitial = firstName.substring(0,1); //Get initial of first name
  55.         String hiddenCardNum = "#####-###-" + str_debitCardNum.substring(10,14); //Get last 4 digits of card number and add them to hidden numbers (#)
  56.         int numPizzas = Integer.parseInt(str_numPizzas); //Parse (string) number of pizzas as an integer (numPizzas) for total cost calc
  57.         double perPizzaPrice = Double.parseDouble(str_perPizzaPrice); //Parse (string) per pizza price as an integer (perPizzaPrice) for total cost calc
  58.         double totalCost = numPizzas*perPizzaPrice; //Calculate total cost of order
  59.        
  60.         //Display Receipt Header
  61.         System.out.println("\n=============================================");
  62.         System.out.println("\t\tR E C E I P T");
  63.         System.out.println("=============================================\n");
  64.        
  65.         //Display Order Receipt Information (Output)
  66.         System.out.println("Date: " + currentDate);
  67.         System.out.println("Order Number: 0152\n");
  68.         System.out.println("\tName: " + firstNameInitial + ". " + lastName);
  69.         System.out.println("\tAccount: " + hiddenCardNum);
  70.         System.out.println("\tType of Pizza: " + pizzaType);
  71.         System.out.println("\tNumber of Pizzas: " + numPizzas);
  72.         System.out.println("\tPer Pizza Price: " + perPizzaPrice);
  73.         System.out.println("\tTotal Cost: $" + totalCost);
  74.         System.out.println("\nThank you for using E-Slice. \nYour pizza(s) should be available shortly.");
  75.     }
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top