Introduction to Java using NetBeans
Section 3 - Working with Numeric Data (some more) and GUI's
What we are Learning how to.......
- numeric types
What I'm Looking For......
Programming Concepts and Skills
Designing Modular Programs
Note: These examples are taken from a source that does not use the naming conventions that we do. Always remember to name your variables correctly
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
Tutorial 3.1 - 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. Hey Sam !!!!!!No upgrades are required.
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.
Add a Selection of Toppings
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
For these assignments post the following:
1. Insert the Drive Folder
4. Output Screenshots
Copy the Rubric to your Google Drive and add a link on your website