Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computing Concepts Note Set 11. Other ways of interacting with Java programs There are: ▫ GUI programs ▫ Web-based applets (GUI programs.

Similar presentations


Presentation on theme: "Introduction to Computing Concepts Note Set 11. Other ways of interacting with Java programs There are: ▫ GUI programs ▫ Web-based applets (GUI programs."— Presentation transcript:

1 Introduction to Computing Concepts Note Set 11

2 Other ways of interacting with Java programs There are: ▫ GUI programs ▫ Web-based applets (GUI programs that run in a browser) ▫ Command line interface programs  Windows Based: Run in command prompt/Dos prompt  From a RUN dialog, type ‘cmd’ and hit enter  Macs or Linux: Run in a Terminal Window  Mac: Look in Utilities in applications  Linux: depends on distro – look under accessories on “main menu”

3 On Windows http://blogs.oreilly.com/digitalmedia/uploads/2008/04/unix 4mac-terminal.png Windows Command Prompt Mac OS X Terminal

4 System.out.println(…) Used in CLI program Can be used in gui program for debugging purposes Accepts a String argument and will print it Prints the argument then goes to the next line (new line) Examples: System.out.println (“Hello World”); System.out.println(“What” + “ is “ + “ your name?”); System.out.println(“Hello” + 123); Hello World What is your name? Hello123 Hello World What is your name? Hello123

5 System.out.println() We’ll use this to do some quick testing in Java Can be used to write fully-operational complex pieces of software In Netbeans, output will appear in the Terminal Output Window at the bottom

6 System.out.println(…) – some notes System.out.println(“Hello “ + “world.”); System.out.println(“Grade:” + 97);

7 On Slides: To Save Space on Slides: print (…); means System.out.println(…);

8 Back to ifs… What’s the difference between… this… if ( grade >= 90 ) print(“A”); if ( grade >= 80 ) print (“B”); if (grade >= 70 ) print (“C”); and this… if ( grade >= 90 ) print(“A”); else if ( grade >= 80 ) print (“B”); else if (grade >= 70 ) print (“C”);

9 Nesting Control Statements Nested – ifs ▫ having one if statement inside another if (a > b) { if (b < c) { print(“cool”); } print (“awesome”); } Will be executed if b Will be executed if a > b regardless of truth of b < c

10 Nesting Control Statements if (a > b) { if (b < c) { print(“cool”); } print (“awesome”); } Assume: a = 3, b = 2, c = 25. Output: _____________________________ a = 4, b = 6, c = 8. Output: ______________________________ a = 4, b = -2, c = -9. Output: ______________________________

11 Decimal Format Some contexts have floating point values but only with a certain amt of precision ▫ MONEY!!!!!! Use a DecimalFormat object to help format how FP data is displayed double wages = 3.44567651; DecimalFormat dollars = new DecimalFormat(“$0.00”); myJLabel.setText(dollars.format(wages));

12 Constants Store a constant value. Uses keyword final to declare final int PI = 3.1415; If an attempt is made to change the value, compiler will indicate an error Makes reading source code easier. If constant changes, only have to change in one place. ▫ Think sales tax rate or commission rate for a job. ▫ Could use many places but when changes, only change in one place

13 Wage Calculator: Example Application Requirements A company needs an application that calculates the gross wages per week for each of its employees. Each employee’s weekly salary is based on the employee’s number of hours worked and hourly wage. A standard work week is 40 hours. Any time worked over 40 hours in a week is considered “overtime,” and employees earn time-and-a-half for the extra hours. Create an application that accepts one employee’s number of hours worked and hourly wage, and calculates the employee’s total (gross) wages for the week.

14 private void calcualteJButtonActionPerformed(ActionEvent event) { //Get Data from text fields

15 //Declare constant and determine over time using ifs

16 //Format and display data

17


Download ppt "Introduction to Computing Concepts Note Set 11. Other ways of interacting with Java programs There are: ▫ GUI programs ▫ Web-based applets (GUI programs."

Similar presentations


Ads by Google