Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Computer Programming Lab 8.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
LAB 10.
Computer Programming Lab(4).
Computer Programming Lab(5).
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
Programming Methodology (1). import java.util.*; public class FindCost3 { public static void main(String[] args ) { Scanner sc = new Scanner(System.in);
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Chapter 5 Loops.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 6. else-if & switch Copyright © 2012 Pearson Education, Inc.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
More about Java Chapter 2 9/8 & 9/9 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
CSC 1051 M.A. Papalaskari, Villanova University Algorithms Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Switch statement.
Chapter 2 Clarifications
CSC111 Quick Revision.
TemperatureConversion
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Compiling and Running a Java Program
Chapter 6 More Conditionals and Loops
Maha AlSaif Maryam AlQattan
SELECTION STATEMENTS (1)
Something about Java Introduction to Problem Solving and Programming 1.
Java Methods Making Subprograms.
Control Statement Examples
CSS161: Fundamentals of Computing
Computers & Programming Languages
Introduction to Classes and Methods
Java Methods Making Subprograms.
More on Classes and Objects
Java Methods Making Subprograms.
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Differences between Java and JavaScript
Module 3 Selection Structures 2/19/2019 CSE 1321 Module 3.
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Module 3 Selection Structures 4/3/2019 CSE 1321 Module 3.
Module 3 Selection Structures 4/4/2019 CSE 1321 Module 3.
CSE Module 1 A Programming Primer
Object-Oriented Programming and class Design
Object-Oriented Programming and class Design
CSS161: Fundamentals of Computing
CSE Module 1 A Programming Primer
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Module 3 Selection Structures 12/7/2019 CSE 1321 Module 3.
Presentation transcript:

Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3

Pseudocode - IF Statement MAIN Fahrenheit ← 0, Celsius ← 0 PRINT “Enter Celsius temperature: ” READ user input Celsius ← user input Fahrenheit ← 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT “heat warning” ENDIF END MAIN Ps 4/5/2019 CSE 1321 Module 3

Java Example - if Statement import java.util.Scanner; public class CelsiusToFahrenheit { public static void main (String[] args) { double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print (“What is the Celsius temperature? "); celsius = scan.nextDouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println (“The temperature is " + fahrenheit + “ degrees Fahrenheit”); if (fahrenheit >= 90) { System.out.println(“It is really hot out there!”); } 4/5/2019 CSE 1321 Module 3

Pseudocode – IF-ELSE Statement MAIN Fahrenheit ← 0, Celsius ← 0 PRINT “Enter Celsius temperature: ” READ user input Celsius ← user input Fahrenheit ← 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT “heat warning” ELSE PRINT “there is no extreme heat” ENDIF END MAIN Ps 4/5/2019 CSE 1321 Module 3

Java Example – if-else (code snippet) double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print (“What is the Celsius temperature? "); celsius = scan.nextDouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println (“The temperature is " + fahrenheit + “degrees Fahrenheit”); if(fahrenheit >= 90) { System.out.println(“It is really hot out there!”); } else { System.out.println(“There is no extreme heat today.”); 4/5/2019 CSE 1321 Module 3

Pseudocode – IF-ELSE-IF MAIN Fahrenheit ← 0, Celsius ← 0 PRINT “Enter Celsius temperature: ” READ user input Celsius ← user input Fahrenheit ← 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT “heat warning” ELSE IF (Fahrenheit >= 80) THEN PRINT “it is warm, but there is no extreme heat” ELSE IF (Fahrenheit >= 70) THEN PRINT “the temperature is pleasant and suggest a picnic” ELSE PRINT “a suggestion to take a jacket” END IF END MAIN Ps 4/5/2019 CSE 1321 Module 3

Java Example – if-else-if double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print (“What is the Celsius temperature? "); celsius = scan.nextDouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println (“The temperature is " + fahrenheit + “ degrees Fahrenheit”); if (fahrenheit >= 90){ System.out.println(“It is really hot out there!”); } else if (fahrenheit >= 80) { System.out.println(“It is very warm...”); // CONTINUED ON NEXT SLIDE 4/5/2019 CSE 1321 Module 3

Java Example – if-else-if (con’t) else if (fahrenheit >= 70) { System.out.println(“It is very pleasant today!”) } else { System.out.println(“It is cool today. Take a jacket.”); 4/5/2019 CSE 1321 Module 3

Pseudocode – switch Statement // Read user input like before conditions ← compute using Fahrenheit variable / 10 CASE conditions OF 10 : PRINT “stay inside”, BREAK 9 : PRINT “be careful due to heat”, BREAK 8 : PRINT “it is hot, but not extreme”, BREAK 7 : PRINT “pack a picnic”, BREAK DEFAULT : PRINT “take a jacket”, BREAK ENDCASE Ps 4/5/2019 CSE 1321 Module 3

Java switch Example int condition = (int)fahrenheit / 10; System.out.println("It is in the " + condition + ”0's."); switch (condition) { case 10: System.out.println("Stay inside!"); break; case 9: System.out.println("It is really hot out there!"); case 8: System.out.println("It’s warm, but no extreme heat!"); case 7: System.out.println("It is very pleasant today!"); default: System.out.println("Take a jacket!"); } 4/5/2019 CSE 1321 Module 3