Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A program that simulates an online order/purchase of pizza(s)
- * by receiving user input and displaying a receipt.
- *
- * @author Tyler Wargo
- * @version 1.0
- */
- //Imports Scanner Library
- import java.util.Scanner;
- public class OrderPizza
- {
- public static void main(String[] args)
- {
- //Creates Scanner Object
- Scanner in = new Scanner(System.in);
- //Display E-Shop Header
- System.out.println("=============================================");
- System.out.println("\t\tE - S L I C E");
- System.out.println("=============================================\n");
- //Get first and last name
- System.out.print("Please enter your first and last name: ");
- String firstName = in.next();
- String lastName = in.next();
- //Get current date (To be reformatted)
- System.out.print("Please enter today's date (MM/DD/YYYY): ");
- String str_currentDate = in.next();
- //Get number of pizzas
- System.out.print("Please enter the type of pizza: ");
- String pizzaType = in.next();
- //Get price of pizza type (To be parsed)
- System.out.print("Please enter the price of the selected type of pizza: ");
- String str_perPizzaPrice = in.next();
- //Get number of pizzas
- System.out.print("Please enter the number of pizzas: ");
- String str_numPizzas = in.next();
- //Get debit card number
- System.out.print("Please enter your debit card number (#####-###-####): ");
- String str_debitCardNum = in.next();
- //Get pin number
- System.out.print("Please enter your pin number (#####): ");
- String str_pinNum = in.next();
- //Parse, convert, and calculate variables from input to be used in receipt
- String currentDate = str_currentDate.substring(0,2) + "-" + str_currentDate.substring(3,5) + "-" + str_currentDate.substring(6,10); //Reformat date through substrings
- String firstNameInitial = firstName.substring(0,1); //Get initial of first name
- String hiddenCardNum = "#####-###-" + str_debitCardNum.substring(10,14); //Get last 4 digits of card number and add them to hidden numbers (#)
- int numPizzas = Integer.parseInt(str_numPizzas); //Parse (string) number of pizzas as an integer (numPizzas) for total cost calc
- double perPizzaPrice = Double.parseDouble(str_perPizzaPrice); //Parse (string) per pizza price as an integer (perPizzaPrice) for total cost calc
- double totalCost = numPizzas*perPizzaPrice; //Calculate total cost of order
- //Display Receipt Header
- System.out.println("\n=============================================");
- System.out.println("\t\tR E C E I P T");
- System.out.println("=============================================\n");
- //Display Order Receipt Information (Output)
- System.out.println("Date: " + currentDate);
- System.out.println("Order Number: 0152\n");
- System.out.println("\tName: " + firstNameInitial + ". " + lastName);
- System.out.println("\tAccount: " + hiddenCardNum);
- System.out.println("\tType of Pizza: " + pizzaType);
- System.out.println("\tNumber of Pizzas: " + numPizzas);
- System.out.println("\tPer Pizza Price: " + perPizzaPrice);
- System.out.println("\tTotal Cost: $" + totalCost);
- System.out.println("\nThank you for using E-Slice. \nYour pizza(s) should be available shortly.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement