Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting.

Similar presentations


Presentation on theme: "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting."— Presentation transcript:

1 March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting the last lab to “dialogs”Converting the last lab to “dialogs” IF StatementIF Statement

2 March 2005 2/18R. Smith - University of St Thomas - Minnesota Numeric Conversions Scanner class has built-in conversionsScanner class has built-in conversions JOptionPane needs to use other conversionsJOptionPane needs to use other conversions Built-in, standard methods:Built-in, standard methods: –Integer.parseInt(str); –Byte.parseByte(str); –Double. same –Float. same –Long. same –Short. same These work with ANY other variables/methodsThese work with ANY other variables/methods

3 March 2005 3/18R. Smith - University of St Thomas - Minnesota More Examples Collect some ints, calculate averageCollect some ints, calculate average Collect some doubles, calculate averageCollect some doubles, calculate average

4 March 2005 4/18R. Smith - University of St Thomas - Minnesota Lab 4 Part A Converting lab to use input dialogsConverting lab to use input dialogs The problem of variablesThe problem of variables –Option: collect data in separate variables, then combine –Option: combine as you go How do you chose?How do you chose? –Look at the problem: do the separate values help you any? –If so, keep them –If not, don’t bother with them

5 March 2005 5/18R. Smith - University of St Thomas - Minnesota IF Statements What’s the idea? Skipping stepsWhat’s the idea? Skipping steps Syntax: if (test) thing-to-do;Syntax: if (test) thing-to-do; –If test fails, thing-to-do is skipped –If it succeeds, it’s executed Relational operatorsRelational operators – and = –== and !=

6 March 2005 6/18R. Smith - University of St Thomas - Minnesota Examples Rectangle x and y valuesRectangle x and y values –make them the right order to calculate lengths Collect a value and test for over/underCollect a value and test for over/under –Overtime calculation Collect a value and check for “y”Collect a value and check for “y”

7 March 2005 7/18R. Smith - University of St Thomas - Minnesota Lab 4 Part B Collect weekend hoursCollect weekend hours Calculate overtime pay for overtime daysCalculate overtime pay for overtime days –Need to check for overtime before doing the arithmetic –The “if” does the checking VariablesVariables –Collect totals as you go – my suggestion

8 March 2005 8/18R. Smith - University of St Thomas - Minnesota Lab 4 Part B Write a program that uses showInputDialog to collect an employee's "long weekend" hours, that is, for working Friday, Saturday, and Sunday. The employees make $16 an hour. If the number of hours worked in a day is greater than 8, calculate regular pay for 8 hours and 1.5x pay for hours beyond 8. Once you have collected the information for all 3 days, display a message dialog box that reports the employee's hours and gross pay.

9 March 2005 9/18R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting."

Similar presentations


Ads by Google