Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.DecimalFormat;
- import java.util.Random;
- /**
- * This program accepts coded ticket information.
- * Project 3
- * Zach Tinsley - COMP 1210 - 003
- * 01/31/2022
- */
- public class BasketballTicket {
- /**
- * Accepts coded ticket information as input that includes price, time, etc.
- * @param args - Standard Command line arguments
- */
- public static void main(String[] args) {
- Scanner userInput = new Scanner(System.in);
- Random generator = new Random();
- DecimalFormat formatPrice = new DecimalFormat("$#,##0.00");
- DecimalFormat formatDiscount = new DecimalFormat("#%");
- DecimalFormat formatPrize = new DecimalFormat("000000");
- int tempPrize = generator.nextInt(1000000) + 1;
- String prize = formatPrize.format(tempPrize);
- System.out.print("Enter ticket code: ");
- String ticketCode = userInput.nextLine();
- ticketCode = ticketCode.trim();
- if (ticketCode.length() >= 28) {
- String time = ticketCode.substring(8, 12);
- String section = ticketCode.substring(20, 23);
- String row = ticketCode.substring(23, 25);
- String seat = ticketCode.substring(25, 27);
- int i = ticketCode.length() - 28;
- String game = ticketCode.substring(i + 9);
- String tempPrice = ticketCode.substring(0, 4);
- String tempDiscount = ticketCode.substring(6, 8);
- double price = Double.parseDouble(tempPrice);
- double discount = Double.parseDouble(tempDiscount);
- String date = ticketCode.substring(12, 20);
- String month = date.substring(0, 2);
- String day = date.substring(2, 4);
- String year = date.substring(4);
- String leftTime = time.substring(0, 2);
- String rightTime = time.substring(2);
- double cost = price * (discount / 100);
- System.out.println("\nTicket: " + game);
- System.out.print("Date: " + month + "/" + day + "/" + year);
- System.out.println(" Time: " + leftTime + ":" + rightTime);
- System.out.print("Section: " + section);
- System.out.print(" Row: " + row);
- System.out.println(" Seat: " + seat);
- System.out.print("Price: " + formatPrice.format(price));
- System.out.print(" Discount: " + formatDiscount.format(discount));
- System.out.println(" Cost: " + formatPrice.format(cost));
- System.out.print("Prize Number: " + formatPrize.format(tempPrize));
- }
- else {
- System.out.println("*** Invalid Ticket Code ***");
- System.out.print("Ticket code must have at least 28 characters.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment