1 / 9

QMCS 230: Today in Class

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);

india
Download Presentation

QMCS 230: Today in Class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. More Examples • Collect some ints, calculate average • Collect some doubles, calculate average R. Smith - University of St Thomas - Minnesota

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

More Related