Catie Welsh February 2, 2011 1.  Program 1 Due Today by 11:59pm today  Program 2 Assigned Today  Lab 2 Due Friday by 1:00pm 2.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Programming
Computer Programming Lab(7).
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.
CSCI S-1 Section 7. Coming Soon Problem Set Three, Part B – Tuesday, July 14, 17:00 EST Problem Set Four (72 + 5/15 points) – Friday, July 17, 17:00 EST.
Chapter 6 Horstmann Programs that make decisions: the IF command.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
COMP 110 More Loops and Strings Tabitha Peck M.S. February 18, 2008 MWF 3-3:50 pm Philips
COMP 110 Primitive Types, Strings, and Console I/O Tabitha Peck M.S. January 23, 2008 MWF 3-3:50 pm Philips
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
If statements Chapter 3. Selection Want to be able to do a statement sometimes, but not others if it is raining, wear a raincoat. Start first with how.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
COMP More About Classes Yi Hong May 22, 2015.
Conditional If Week 3. Lecture outcomes Boolean operators – == (equal ) – OR (||) – AND (&&) If statements User input vs command line arguments.
Catie Welsh January 12, 2011 MWF 1-1:50 pm Sitterson
CSE 131 Computer Science 1 Module 1: (basics of Java)
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
COMP Mid-Term Review Yi Hong May 27, 2015.
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
The String Class A String is an object. An object is defined by a class. In general, we instantiate a class like this: String myString = new String(“Crazy.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
CS1101: Programming Methodology Aaron Tan.
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Catie Welsh February 7,  Grades ◦ Lab 2, Project 1 Grades are now on Blackboard 2.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Java Review if Online Time For loop Quiz on Thursday.
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Catie Welsh February 14,  Program 2 Due Tonight by 11:59pm  Program 3 Assigned 2.
1 Simple Input Interactive Input - The Class Scanner n Command-Line Arguments.
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.
Catie Welsh March 4,  Midterm on Monday, March 14th ◦ Closed books, no notes, no computer  No office hours during Spring Break ◦ However, I will.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
(Dreaded) Quiz 2 Next Monday.
CSE 110 Midterm Review Hans and Carmine. If Statements If statements use decision logic In order to properly use if statements relational operators must.
Key Words / Reserved Words
Chapter 2 Clarifications
Crash course in the Java Programming Language
Chapter 5: Control Structures II
Computer Programming Methodology Introduction to Java
Computer Programming Methodology Input and While Loop
SELECTION STATEMENTS (1)
Topic 11 Scanner object, conditional execution
BIT115: Introduction to Programming
Control Statement Examples
Michele Weigle - COMP 14 - Spr 04
SELECTION STATEMENTS (2)
Java so far Week 7.
Know for Quiz Everything through Last Week and Lab 7
AP Java Review If else.
Programming 2 Decision-Making.
Self study.
Building Java Programs
Announcements Lab 6 was due today Lab 7 assigned this Friday
AP Java Review If else.
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 14, 2011
Building Java Programs
Building Java Programs
Presentation transcript:

Catie Welsh February 2,

 Program 1 Due Today by 11:59pm today  Program 2 Assigned Today  Lab 2 Due Friday by 1:00pm 2

3

4  Formatting decimals  Review Worksheet  If/Else statements  Boolean Expressions

 import java.text.*;  DecimalFormat df = new DecimalFormat("0.00");  df.format(myVariable);  Example code on class website 5

public class MyProgram { public static void main(String[] args) { String myString = “This is a string”; int len = myString.length(); System.out.print(“the length is “ + len); String shortString = myString.substring(10); } 6

 Double myDouble = (1 / 2) * 5.0;  int i = 1 / 2; 0.5 O 7

 Suppose that mary is an object of class Person, and suppose that increaseAge is a method of class Person that uses one argument, an integer. Write the invocation of the method increaseAge for the object mary using the argument 5. mary.increaseAge(5); Person mary = new Person; 8

9

Check time; if (time < 7am) { take bus; } else //time >= 7am { take subway; } Reach school; 10

import java.util.*; public class FlowChart { public static void main(String[] args) { System.out.println("Give me an integer:"); Scanner keyboard = new Scanner(System.in); int inputInt = keyboard.nextInt(); if( inputInt > 5) { System.out.println("Big number"); } else { System.out.println("Small number"); } } } 11 Start Prompt User for int Is user input greater than 5? Print: “small number” Print: “big number” YES NO

==Equal to !=Not equal to >Greater than >=Greater than or equal to <Less than <=Less than or equal to 12

 True of False  Example expressions ◦ 5 == 3; ◦ Variable <= 6; ◦ myInt != temp;  if (boolean expression) {statements } 13

 What if you need multiple expressions to be true  (expression) && (expression) && … ◦ Expressions go in ( )  Will only be true if ALL statements are true 14

 What if you need ONE expression to be true out of many expressions  (expression) || (expression) || … ◦ Expressions go in ( )  Will be true if ONE expression is true 15

 FIGURE 3.7 The Effect of the Boolean Operators && (and), || (or), and ! (not) on Boolean values

 var1 = var2 (assignment statement) ◦ Error!!!!!!!  var1 == var2 (boolean expression)  Do NOT use == to compare Strings ◦ string1 == string2 //BAD ◦ string1.equals(string2); //GOOD 17

 Syntax String.equals(Other_String) String.equalsIgnoreCase(Other_String)

 You can use just an if statement  if (boolean expression) { (statements) } the rest of your code 19

if (boolean expression) { if (boolean expression) { stuff goes here } else { more stuff } } else 20

Start Prompt User for int What is the integer? Print: “hello” Print: “how may I help you” inputInt > 1 inputInt == 0 Print: “how are you” inputInt == 1 21

import java.util.*; public class FlowChart { public static void main(String[] args) { System.out.println("Give me an integer:"); Scanner keyboard = new Scanner(System.in); int inputInt = keyboard.nextInt(); if ( inputInt == 0) System.out.println(”hello"); else if ( inputInt == 1) System.out.println(”how are you"); else System.out.println(”how may I help you"); } } 22

 Recitation  Bring Laptop  Bring Book 23