Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

WARM-UP: MON, APR 7 What are loops used for in programming? What are at least 2 different kinds of loops?
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Computer Science 1620 Loops.
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
CS150 Introduction to Computer Science 1
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
Loop variations do-while and for loops. Do-while loops Slight variation of while loops Instead of testing condition, then performing loop body, the loop.
Control structures: if-else statements and switch statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction.
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
Chapter 3 Control Statements F Selection Statements –Using if and if...else –Nested if Statements –Using switch Statements –Conditional Operator F Repetition.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
JOptionPane class. Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input. A variety of dialog boxes.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
Chapter 5 Loops.
习 题 4.23 编写一个 applet ,读取一个矩形的边长,然后 用在 paint 方法中使用 drawString 方法画出用星组成 的空心矩形。程序应能画出边长从 1 到 20 的任何矩 形。
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
9/20: The while Repetition Structure last time’s program repetition structures: what they are the while repetition structure homework due on Thursday program.
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
Chapter 4: Control Structures II
Chapter 5: Control Structures II
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
Dialog Boxes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java iteration statements ● Iteration statements are statements which appear in the source code only once, but it execute many times. ● Such kind of statements.
2/18: Assignment Operators About Average2.java –while loop use –explicit casting –twoDigits object Assignment Operators Increment & Decrement Operators.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
The for loop.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
Computer Programming1 Computer Science 1 Computer Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
1 Chapter 5 Control Statements. 2 Objectives F To understand the flow of control in selection and loop statements. F To use Boolean expressions to control.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
CS 201 Lecture 7: John Hurley Summer 2012 Cal State LA.
2.5 Another Java Application: Adding Integers
Chapter 5: Control Structures II
TK1114 Computer Programming
Control Statements Loops.
Control Statements Loops.
Repetition Statements
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
JOptionPane class.
F II 2. Simple Java Programs Objectives
Presentation transcript:

Introduction to Computing Concepts Note Set 15

JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used to give helpful messages, errors, or warnings.

Example import javax.swing.JOptionPane; public class Tester { public static void main (String [] args) { JOptionPane.showMessageDialog(null, "Hello There!!!"); }

JOptionPane.showInputDialog Pops up a dialog and allows the user to enter a string Method returns a string Can be used to ask for strings or numbers. ▫ Must convert string version of number to numerical type

Example import javax.swing.JOptionPane; public class Tester { public static void main (String [] args) { String data; data = JOptionPane.showInputDialog(null, "Please input your name."); System.out.println("Hello“ + data); }

Use JOptionPane to get 5 numbers from the user then display to the screen. public static void main(String [] args) {

Breakout 1

do…while Loop do //some Java Statement while (expression); do { //some //statements //can go here } while (expression); single statement no braces multiple statements need braces

Two Types of Loops do { //some //statements //can go here } while (expression); VS: while(expression) { //do something //here }

What is Displayed int x = 1; while (x < 0) System.out.println(x); do System.out.println(x); while (x < 0);

What is Displayed? int c = 10; do { System.out.println(“hello”); c++; } while (c < 4);

What is Displayed? int v = 0; do { v++; System.out.println(v); } while (v < 4);

What is Displayed? int count = 0; int funny = 1; int serious = 0; int limit = 4; do { funny ++; serious = serious + 2; count = count + 1; } while (count < limit); System.out.println(funny + “ “ + serious + “ “ + count );

QuickCode Write a snippet of code that asks the user to enter integers until the sum of the numbers entered is greater than 300. Use a do…while loop

Nested Loops It is possible to have one looping structure inside another int first = 0; int second = 0; while (first < 3) { do { System.out.print(“*”); //doesn’t go to next line second += 1; }while (second < 4); System.out.println(); first += 1; second = 0; }

Breakout 2

17 For Loop Ideal for situations that require a counter Has built in expressions that initialize and update variables

18 For Loop for (initialization; test; update) statement; for (initialization; test; update) { statement; //Place as many here as needed }

19 For Loop for (initialization; test; update) statement; Used to set up counter variable

20 For Loop for (initialization; test; update) statement; Controls execution of loop

21 For Loop for (initialization; test; update) statement; Updates (increments) counter variable

22 For Loop for (int num=0; num<4; num++) System.out.println(num + “\t” + num*num); 1. Perform initialization of counter

23 for (int num=0; num<4; num++) System.out.println(num + “\t” + num*num); For Loop 1.Perform initialization of counter 2.Evaluate test if num < 4, go to step 3 else terminate loop

24 for (int num=0; num<4; num++) System.out.println(num + “\t” + num*num); For Loop 1.Perform initialization of counter 2.Evaluate test 3.Execute statement

25 for (int num=0; num<4; num++) System.out.println(num + “\t” + num*num); For Loop 1.Perform initialization of counter 2.Evaluate test 3.Execute statement 4.Perform update – go back to step 2