Guest User

Untitled

a guest
Feb 1st, 2022
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.text.DecimalFormat;
  3. import java.util.Random;
  4. /**
  5. * This program accepts coded ticket information.
  6. * Project 3
  7. * Zach Tinsley - COMP 1210 - 003
  8. * 01/31/2022
  9. */
  10. public class BasketballTicket {
  11. /**
  12. * Accepts coded ticket information as input that includes price, time, etc.
  13. * @param args - Standard Command line arguments
  14. */
  15. public static void main(String[] args) {
  16. Scanner userInput = new Scanner(System.in);
  17. Random generator = new Random();
  18. DecimalFormat formatPrice = new DecimalFormat("$#,##0.00");
  19. DecimalFormat formatDiscount = new DecimalFormat("#%");
  20. DecimalFormat formatPrize = new DecimalFormat("000000");
  21. int tempPrize = generator.nextInt(1000000) + 1;
  22.  
  23. String prize = formatPrize.format(tempPrize);
  24. System.out.print("Enter ticket code: ");
  25. String ticketCode = userInput.nextLine();
  26. ticketCode = ticketCode.trim();
  27. if (ticketCode.length() >= 28) {
  28. String time = ticketCode.substring(8, 12);
  29. String section = ticketCode.substring(20, 23);
  30. String row = ticketCode.substring(23, 25);
  31. String seat = ticketCode.substring(25, 27);
  32.  
  33. int i = ticketCode.length() - 28;
  34. String game = ticketCode.substring(i + 9);
  35.  
  36. String tempPrice = ticketCode.substring(0, 4);
  37. String tempDiscount = ticketCode.substring(6, 8);
  38. double price = Double.parseDouble(tempPrice);
  39. double discount = Double.parseDouble(tempDiscount);
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. String date = ticketCode.substring(12, 20);
  50. String month = date.substring(0, 2);
  51. String day = date.substring(2, 4);
  52. String year = date.substring(4);
  53.  
  54. String leftTime = time.substring(0, 2);
  55. String rightTime = time.substring(2);
  56.  
  57. double cost = price * (discount / 100);
  58.  
  59. System.out.println("\nTicket: " + game);
  60. System.out.print("Date: " + month + "/" + day + "/" + year);
  61. System.out.println(" Time: " + leftTime + ":" + rightTime);
  62. System.out.print("Section: " + section);
  63. System.out.print(" Row: " + row);
  64. System.out.println(" Seat: " + seat);
  65. System.out.print("Price: " + formatPrice.format(price));
  66. System.out.print(" Discount: " + formatDiscount.format(discount));
  67. System.out.println(" Cost: " + formatPrice.format(cost));
  68. System.out.print("Prize Number: " + formatPrize.format(tempPrize));
  69. }
  70. else {
  71. System.out.println("*** Invalid Ticket Code ***");
  72. System.out.print("Ticket code must have at least 28 characters.");
  73. }
  74.  
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment