Introduction to Java using NetBeans

Section 3 - Working with Numeric Data (some more) and GUI's

 

Learning Goals

What we are Learning how to.......

- numeric types
- numeric calculations
- combo boxes, selection boxe

 

Success Criteria

What I'm Looking For......

- bug free java applications that efficiently solve the problems presented
- problem solving skills (try before you ask)
- efficient algorithm implementation
-modular programs
- formated and documented code
- organized website with code and executables
- neat, organized, GUI that is user friendly

Curriculum Expectations

Programming Concepts and Skills
- demonstrate the ability to use different data types and expressions
- use proper code maintenance techniques when creating computer programs.

Software Development
- manage the software development process effectively

Designing Modular Programs
- apply modular design concepts

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
Converts a String to a Double value.

The Integer.parseInt() Method
Converts a String to an Integer value

Example Icon Example

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

    The code below shows how to read length and width to calculate the area of a rectangle. Complete the form using text boxes for input of both length and width. .

This is code that runs when the Calculate button is pressed.

Getting Integers and Double values from Strings

intnumber =Integer.parseInt(strnum); // Where strnum is an integer value entered as a string
doublenumber = Double.parseDouble(strnum); /// Where strnum is a decimal value entered as a string

Create GUI Programs for the Following Assignments. Hey Sam !!!!!!No upgrades are required.

Assignment 3.1 - Pizza Anyone!

This is an image of a pizza shop.

The cost of making pizza at a local shop is as follows:

  • Labour cost is $1.00 per pizza, regardless of size.
  • Store cost is $1.50 per pizza, regardless of size.
  • Materials is $0.05 * diameter* diameter(diameter is measured in inches).

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.

The application output should look similar to:


Enter the number of burgers: 2

Enter the number of fries: 5

Enter the number of soft drinks: 5

Total before taxes: $19.38

Tax: $2.52

Final total: $21.90

This image is a cartoon of a hamburger, fries, and drink. Each item has legs and is running.

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
Change:                                            $2.91

 

 

 

 


For these assignments post the following:

1. Insert the Drive Folder
2. Insert a Folder with jar files
3. The code for the JFrame Form
(Use http://www.planetb.ca/syntax-highlight-word to keep the code in the proper format)

4. Output Screenshots

Copy the Rubric to your Google Drive and add a link on your website