Fall 2012, The College of Saint Rose

Lecture 8: Conditional Execution; JOptionPane
Date: Thursday, September 20, 2012

Agenda

• Announcements
• Lab 3: Mad Libs continues
• Lecture assignment 7 recap
• Programming Project 1: Fractions discussion/demo
• More conditional execution
• Using JOptionPane for input and output
• In-class exercise

You may do this by yourself or with a partner.

Your task is to compute and displays the final cost, including sales tax, for the purchase of a single article of clothing. In New York State, clothing is taxable only if it costs \$110.00 or more.

Your input is the price of a single article of clothing (which you would specify in dollars and cents form like "25.99"). If the cost is under \$110.00, the output would be "No tax on that!". But if it is \$110.00 or more, you will need to compute the sales tax and output a message such as "With sales tax of \$16.00, that will cost you \$216.00." (assuming a purchase of \$200.00 and a tax rate of 8%).

Write a Java program in a class called ClothingTax that solves the above problem. You are encouraged to develop a Visual Logic flowchart first, but you need not turn that in. You may assume a sales tax rate of 8% and the tax threshold of \$110.00, but each of these should be specified only in a named constant at the top of your main method. You must use only JOptionPane dialogs for input and output - no Scanner or System.out.print[ln] allowed for this.

To convert the String that will be returned to your program by the JOptionPane.showInputDialog into a double, you should use the Double.parseDouble method, which works just like the Integer.parseInt we saw in the class example, except that it expects to be given a String that can be converted to a double and returns a double.

You need not worry just yet about making sure you have exactly 2 digits after the decimal point in your output. We'll learn how to deal with that soon.

For this exercise, I will not be picky about your documentation, but your submission must include a comment at the top that has your name and that of your partner if applicable. Be sure to use meaningful names for your variables.

You can download a BlueJ project (minus the Java file) from here: ClothingTax if you'd like to try out my solution.

Submit just the ClothingTax.java file in Blackboard under the "Lecture Assignment Submissions" category to the "Lecture 8 In-Class Exercise" item. This will earn you 8 lecture assignment points.

No New Lecture Assignment

Examples