90 likes | 193 Views
QMCS 230: Today in Class. Reading numbers from dialogs Converting the last lab to “dialogs” IF Statement. Numeric Conversions. Scanner class has built-in conversions JOptionPane needs to use other conversions Built-in, standard methods: Integer.parseInt(str); Byte.parseByte(str);
E N D
QMCS 230: Today in Class • Reading numbers from dialogs • Converting the last lab to “dialogs” • IF Statement R. Smith - University of St Thomas - Minnesota
Numeric Conversions • Scanner class has built-in conversions • JOptionPane needs to use other conversions • Built-in, standard methods: • Integer.parseInt(str); • Byte.parseByte(str); • Double. same • Float. same • Long. same • Short. same • These work with ANY other variables/methods R. Smith - University of St Thomas - Minnesota
More Examples • Collect some ints, calculate average • Collect some doubles, calculate average R. Smith - University of St Thomas - Minnesota
Lab 4 Part A • Converting lab to use input dialogs • The problem of variables • Option: collect data in separate variables, then combine • Option: combine as you go • 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 R. Smith - University of St Thomas - Minnesota
IF Statements • What’s the idea? Skipping steps • Syntax: if (test) thing-to-do; • If test fails, thing-to-do is skipped • If it succeeds, it’s executed • Relational operators • < and > and <= and >= • == and != R. Smith - University of St Thomas - Minnesota
Examples • Rectangle x and y values • make them the right order to calculate lengths • Collect a value and test for over/under • Overtime calculation • Collect a value and check for “y” R. Smith - University of St Thomas - Minnesota
Lab 4 Part B • Collect weekend hours • Calculate overtime pay for overtime days • Need to check for overtime before doing the arithmetic • The “if” does the checking • Variables • Collect totals as you go – my suggestion R. 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. R. 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. R. Smith - University of St Thomas - Minnesota