Java Reference
In-Depth Information
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 tickets sold.
5. Get the number of child tickets sold.
6. Get the percentage of the gross amount donated to the charity.
7. Calculate the gross amount using the following formula:
3
grossAmount = adultTicketPrice * noOfAdultTicketsSold
+ childTicketPrice * noOfChildTicketsSold;
8. Calculate the amount donated to the charity using the following formula:
amountDonated = grossAmount * percentDonation / 100;
9. Calculate the net sale amount using the following formula:
netSaleAmount = grossAmount - amountDonated;
From the preceding discussion, it follows that you need variables to store the movie
name, adult ticket price, child ticket price, number of adult tickets sold, number of
child tickets sold, percentage of the gross amount donated to the charity, gross
amount, amount donated, and net sale amount. You also need a variable to get the
string containing the sales data and a string to format the output. Therefore, the
following variables are needed:
String movieName;
String inputStr;
String outputStr;
VARIABLES
double adultTicketPrice;
double childTicketPrice;
int noOfAdultTicketsSold;
int noOfChildTicketsSold;
double percentDonation;
double grossAmount;
double amountDonated;
double netSaleAmount;
To show the desired output, you first create the string consisting of the strings and
the values required. The following string accomplishes this:
FORMATTING
THE
OUTPUT
outputStr = "Movie Name: " + movieName + "\n"
+ "Number of Tickets Sold: "
+ (noOfAdultTicketsSold +
Search WWH ::




Custom Search