Introduction to Java using NetBeans
Section 3 : Capturing and Displaying Numeric Data
Input of Numeric Data
Applications often require that users fill out forms that contain both text and numeric data. Text fields will only accept String data. It is therefore necessary to read in numeric data as a String and then convert it to a numeric data type.
Java provides methods that you can use to convert data from a string to a number. Below are a couple of those methods.
The Double.parseDouble() Method
The Integer.parseInt() Method
int num1, num2;
num1 = Double.parseDouble("5.5"); // puts a numeric value of 5.5 in the num1 variable
num2 = Integer.parseInt("3"); // puts a numeric value of 3 in the num2 variable
Sample Program – RectangleArea
Getting Integers and Double values from Strings
intnumber =Integer.parseInt(strnum); // Where
strnum is an integer value entered as a string
Create GUI Programs for the Following Assignments. You must add upgrades to these programs.
Assignment 3.1 - Pizza Anyone!
Create a Java application that prompts the user for the size of a pizza and then displays the cost of making the pizza.
The application should look similar to the image below. Notice that the output is formatted to 2 decimal places with a dollar sign in front. Remember that this can be accomplished using DecimalFormat as seen in previous activities.
Assignment 3.2 - Fast Food
A fast food restaurant charges $2.49 for burgers, $1.89 for fries, and $0.99 for soft drinks.
Create an order application that provides the employee with input fields to enter the number of burgers, fries, and soft drinks that a customer orders.
The program is to display the total (before tax), the tax amount @ 13% (HST=13%), and the final cost.
Modify the program to include another input field that the employee uses to enter the amount s/he received from the customer. This is called the amount tendered. Create a button. The button should be grayed out (not enabled) until the first button has been pressed.
A message is then to be displayed indicating the correct amount of change.
Enter amount tendered: $25.00
Assignment 3.3 - Add Coins
Create an Add Coins application that prompts the user for the number of quaters, dimes nickels, and pennies and then displays the total dollar amount.
For these assignments post the following:
1. Insert the Drive Folder
Copy the Rubric to your Google Drive and add a link on your website