Java Reference
In-Depth Information
noOfChildTicketsSold) + "\n"
+ "Gross Amount: $"
+ String.format("%.2f", grossAmount) + "\n"
+ "Percentage of Gross Amount Donated: "
+ String.format("%.2f%%", percentDonation) + "\n"
+ "Amount Donated: $"
+ String.format("%.2f", amountDonated) + "\n"
+ "Net Sale: $"
+ String.format("%.2f", netSaleAmount);
Notice that we have used the method format of the class String to output
decimal numbers to two decimal places.
In the preceding sections, we analyzed the problem and determined the formulas to do
the calculations. We also determined the necessary variables and the output string. We
can now expand the algorithm given in the section Problem Analysis and Algorithm
Design to solve the problem given at the beginning of this programming example.
1. Declare the variables.
2. Display the input dialog box to enter a movie name and retrieve the
movie name.
3. Display the input dialog box to enter the price of an adult ticket.
4. Retrieve the price of an adult ticket.
5. Display the input dialog box to enter the price of a child ticket.
6. Retrieve the price of a child ticket.
7. Display the input dialog box to enter the number of adult tickets
sold.
8. Retrieve the number of adult tickets sold.
9. Display the input dialog box to enter the number of child tickets
sold.
10. Retrieve the number of child tickets sold.
11. Display the input dialog box to enter the percentage of the gross
amount donated.
12. Retrieve the percentage of the gross amount donated.
13. Calculate the gross amount.
14. Calculate the amount donated.
15. Calculate the net sale amount.
16. Format the output string.
17. Display the message dialog box to show the output.
18. Terminate the program.
MAIN
ALGORITHM
 
Search WWH ::




Custom Search