Movie Ticket Sale Java Application

The following Java application program is a Movie Ticket Sale. This sample designs and implementation a program that prompts the user to input the movie name, adult ticket price, child ticket price, number of child ticket sold, amd percentage of the gross amount to be donated to the charity. . I will be using the JCreator IDE in developing the program. To start in this tutorial, first open the JCreator IDE, click new and paste the following code.
  1. import javax.swing.JOptionPane;
  2.  
  3. public class MovieTicket
  4.  
  5. {
  6. public static void main (String[] args )
  7. {
  8. String movieName;
  9. String inputStr;
  10. String outputStr;
  11. double adultTicketPrice;
  12. double childTicketPrice;
  13. int noOfAdultTicketsSold;
  14. int noOfChildTicketsSold;
  15. double percentDonation;
  16. double amountDonated;
  17. double netSaleAmount;
  18. double grossAmount;
  19.  
  20. movieName = JOptionPane.showInputDialog("Enter the movie name: ");
  21.  
  22. inputStr = JOptionPane.showInputDialog
  23. ("Enter the price of an adult ticket: ");
  24. adultTicketPrice = Double.parseDouble(inputStr);
  25.  
  26. inputStr = JOptionPane.showInputDialog
  27. ("Enter the price of an child ticket: ");
  28. childTicketPrice = Double.parseDouble(inputStr);
  29.  
  30. inputStr = JOptionPane.showInputDialog
  31. ("Enter the number of an adult ticket sold : ");
  32. noOfAdultTicketsSold = Integer.parseInt(inputStr);
  33.  
  34. inputStr = JOptionPane.showInputDialog
  35. ("Enter the number of an child ticket sold : ");
  36. noOfChildTicketsSold = Integer.parseInt(inputStr);
  37.  
  38. inputStr = JOptionPane.showInputDialog
  39. ("Enter the percentage of the donation : ");
  40. percentDonation = Double.parseDouble(inputStr);
  41.  
  42. grossAmount = adultTicketPrice * noOfAdultTicketsSold + childTicketPrice * noOfChildTicketsSold;
  43.  
  44. amountDonated = grossAmount * percentDonation / 100;
  45.  
  46. netSaleAmount = grossAmount - amountDonated;
  47.  
  48. outputStr = " Movie Name: " + movieName + "\n"
  49. + "Number of Ticket Sold: "
  50. + (noOfAdultTicketsSold + noOfChildTicketsSold) + "\n"
  51. + " Gross Amount: $"
  52. + String.format("%.2f", grossAmount) + "\n"
  53. + " Percentage of the Gross Amount Donated: "
  54. + String.format("%.2f%%", percentDonation) + "\n"
  55. + "Amount Donated: $"
  56. + String.format("%.2f", amountDonated) + "\n"
  57. + "Net Sale: $"
  58. + String.format("%.2f", netSaleAmount);
  59.  
  60. JOptionPane.showMessageDialog(null, outputStr,
  61. "Theater Sales Data",
  62. JOptionPane.INFORMATION_MESSAGE);
  63. }
  64. }
Sample run: The following are the algorithm: 1. Get the movie name 2. Get the price of an adult ticket. 3. Get the price of a child ticket. 4. Get the number of adult ticket sold. 5. Get the number of child ticket sold. 6. Get the percentage of the gross amount donated to charity. 7. Calculate the gross amount using the following formula:  grossAmount = adultTicketPrice * noOfAdultTicketsSold + childTicketPrice * noOfChildTicketsSold 8. Calculate the amount donated to charity using the formula: = grossAmount * percentDonation / 100; 9. Calculate the net sale amount:  netSaleAmount = grossAmount - amountDonated;

Comments

Add new comment