Java Reference
In-Depth Information
rate = getRate(hours);
tuition = calcTuition(hours, rate);
fees = calcFees(tuition);
displayTotal(tuition + fees);
8. Code the corresponding methods:
• Type public static void displayWelcome() and then, within that
method block, code the statements to display a welcome message.
• Type public static int getHours() and then, within that method
block, declare strHours as a String and hours as an int, setting hours to an
initial value of zero. Display a prompt that allows the user to enter a string
value, strHours, for the total number of hours. Parse that value into the
integer, hours. The getHours() method also should include a try and catch
statement for non-integer input. This method will return the int, hours, to
main.
• Type public static double getRate(int hours) and then, within
that method block, include an if...else statement for hours greater than 15,
which will calculate a rate per credit hour. This method will return the
double value, rate, to main() method.
• Type public static double calcTuition(int hours, double
rate) and then, within that method block, code the statements to accept
two values, multiply them, and return a double value, tuition, to main.
• Type public static double calcFees(double tuition) and then,
within that method block, code the statements to accept the double value,
tuition, multiply it by .08, and then return a double value, fees, to the main
method.
• Type public static void displayTotal(double total) and then,
within that method, construct a DecimalFormat pattern for currency. Use
the System.out.println method to display the value passed by adding
tuition and fees, along with a closing message.
9. Compile the program. If necessary, fix any errors in the TextPad window,
save, and then recompile.
10. Run the program. Test the program by entering values both less than and
greater than 15. Check your answers.
11. Print a copy of the source code for your instructor.
4 User Decisions
CandleLine is a business that sells designer candles and personal gifts. They cater
to customers who want to send gifts for birthdays, holidays, and other special
occasions. CandleLine's e-commerce site is an interactive Web site that uses a
shopping cart to allow customers to purchase items. As customers choose the
candles and gifts they wish to purchase, the items are added to an electronic
shopping cart. Approximately 300 people per day are accessing CandleLine's Web
site, but many customers have complained that the shipping charges become a
hidden cost when they are placing an order. In order to improve customer rela-
tions, the company would like to give its customers a choice in shipping methods
and would like to create a way for customers to calculate their shipping costs
before finalizing their order.
(continued)
Search WWH ::




Custom Search