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 Reviewing previous workReviewing previous work Using a dialog boxUsing.

Similar presentations


Presentation on theme: "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing."— Presentation transcript:

1 March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing a dialog box Converting the last lab to “dialogs”Converting the last lab to “dialogs” Common Errors/Compiling vs RunningCommon Errors/Compiling vs Running IF StatementIF Statement

2 March 2005 2/18R. Smith - University of St Thomas - Minnesota Reviewing previous work Lab 1Lab 1 –One story, one set of variables –Duplicate the story, reassign the variables –Duplcate stories with renamed variables (the really hard way) Lab 2Lab 2 –Calculating average with all integers – bad idea! Cast something to a double, or use a double literal (3.0)Cast something to a double, or use a double literal (3.0) Lab 3Lab 3 –Same mistake with averaging integers

3 March 2005 3/18R. Smith - University of St Thomas - Minnesota Dialog Boxes “Windows” to display data and collect data“Windows” to display data and collect data JOptionPane objectsJOptionPane objects –import javax.swing.JOptionPane; –Runs a separate “thread” to handle the dialogs –Name “JOptionPane” is class name; it selects the methods Methods to useMethods to use –JOptionPane.showMessageDialog(null, “Hello world!”); –JOptionPane.showInputDialog(“Type in your name”); –System.exit(0); // required with JOptionPane

4 March 2005 4/18R. Smith - University of St Thomas - Minnesota Examples Take out your book, look for a “Model” to useTake out your book, look for a “Model” to use Hello WorldHello World Collect strings and print them outCollect strings and print them out –Name, hometown –Change order –Print out to System.out

5 March 2005 5/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

6 March 2005 6/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

7 March 2005 7/18R. Smith - University of St Thomas - Minnesota Compiling vs Execution Errors Compiler catches all the errors it canCompiler catches all the errors it can –Can’t catch them all –You’ll learn which are caught, which aren’t. Execution errors usually based on the dataExecution errors usually based on the data

8 March 2005 8/18R. Smith - University of St Thomas - Minnesota Common Errors, Page 97-8 Which are compile time vs execution errors?Which are compile time vs execution errors? Which have you encountered this month?Which have you encountered this month?

9 March 2005 9/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 !=

10 March 2005 10/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”

11 March 2005 11/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 Reviewing previous workReviewing previous work Using a dialog boxUsing."

Similar presentations


Ads by Google