Week 3 - Friday COMP 1600.

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

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Primitives, References and Wrappers Java has the following types defined as part of the java language; int float double byte char boolean long short These.
Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Java Programming Strings Chapter 7.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Chapter 10 Review. Write a method that returns true is s1 and s2 end with the same character; otherwise return false. Sample Answer: public boolean lastChar(String.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Programming 2 CS112- Lab 2 Java
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Introduction to Computers and Programming Lecture 7:
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9: Characters * Character primitives * Character Wrapper class.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Comparing Data Comparing More than Numbers. Comparing Data When comparing data using boolean expressions, it's important to understand the nuances of.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Fundamental Programming Structures in Java: Strings.
ECE122 L8: More Conditional Statements February 7, 2007 ECE 122 Engineering Problem Solving with Java Lecture 8 More Conditional Statements.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Week 3 - Wednesday.  What did we talk about last time?  Math methods  Lab 2.
VARIABLES Introduction to Computer Science 1- COMP 1005, 1405 Instructor : Behnam Hajian
1 Data Comparisons and Switch Data Comparisons Switch Reading for this class: L&L 5.3,
© 2004 Pearson Addison-Wesley. All rights reserved February 17, 2006 The ‘while’ Statement ComS 207: Programming I (in Java) Iowa State University, SPRING.
Chapter 2 Elementary Programming
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
CS177 Week2: Recitation Primitive data types and Strings with code examples.
Introduction to Java Java Translation Program Structure
COM S 207 Method Instructor: Ying Cai Department of Computer Science Iowa State University
Chapter 7: Characters, Strings, and the StringBuilder.
1 CS 177 Week 3 Recitation Slides Basic Math Operations, Booleans, and Character Operations.
1 Textual Data Many computer applications manipulate textual data word processors web browsers online dictionaries.
String Processing Word processing term papers, writing memoirs, sending messages, responding to surveys, placing online orders and registering products.
Strings Mr. Smith AP Computer Science A. What are Strings? Name some of the characteristics of strings: A string is a sequence of characters, such as.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 The switch Statement The switch statement provides another way.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/29 The switch Statement The switch statement provides another way.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
3 - 1 Text Processing In Java: Characters and Strings Reading:Downey: Chapter 7 Problem Set:Assignment #1 due Tuesday, Feburary 13 Wellesley College CS230.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Java String Methods - Codehs
Week 2 - Wednesday CS 121.
Week 3 - Wednesday CS 121.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
Week 4 - Monday CS 121.
Primitive Types Vs. Reference Types, Strings, Enumerations
Week 3: Basic Operations
CS 177 Week 3 Recitation Slides
Decision Structures, String Comparison, Nested Structures
Chapter 7: Strings and Characters
MSIS 655 Advanced Business Applications Programming
Unit-2 Objects and Classes
Decision Structures, String Comparison, Nested Structures
Exposure Java 2015 Pre-AP®CS Edition Chapter 12 Slides String Methods
Building Java Programs
The Data Element.
The Data Element.
Welcome back! October 11, 2018.
Boolean in C++ CSCE 121.
Presentation transcript:

Week 3 - Friday COMP 1600

Last time What did we talk about last time? Operations on char values Operations on String values Concatenate (+) equals() compareTo() length() charAt() substring()

Questions?

Project 1

Wrapper Classes

Classes and objects are useful There are certain things that are difficult to do with the operations we've shown you For example, how do you turn a String representation of a number like "847" into the actual int 847? Wrapper classes!

Wrapper classes Each primitive data type in Java has a wrapper class We will focus on 3: Integer Double Character

Integer class The main uses of the Integer class are converting ints to and from Strings To convert a String to an int, use the parseInt() method To convert an int to a String, use the toString() method (or just concatenate) String number = "345"; int value = Integer.parseInt(number); int value = 543; String number = Integer.toString(value);

Double class The Double class is much like the Integer class To convert a String to a double, use the parseDouble() method To convert a double to a String, use the toString() method (or just concatenate) String number = "-0.4581"; double value = Double.parseDouble(number); double value = 6.02e23; String number = Double.toString(value);

Character class The Character class is mostly useful for getting information about a particular char For example, you can find out whether a char is a digit, is a letter, is uppercase, or is lowercase by calling the isDigit(), isLetter(), isUpperCase(), or isLowerCase() methods, respectively char c = '8'; boolean value = Character.isDigit(c); //true

Examples Write a program that reads in an alphabetic character and tells you what position in the alphabet it has Write a program that reads three String values and prints them out in reverse order Write a program that reads in an int value and says how many digits it contains

Conditional Execution

Conditional execution So far we have only considered Java programs that do one thing after another, in sequence Our programs have not had the ability to choose between different possibilities Now, they will!

Behold! The if-statement: x is small will only print out if x is less than 5 In this case, we know that it is, but x could come from user input or a file or elsewhere int x = 4; if( x < 5 ) System.out.println("x is small!");

if( condition ) statement; Anatomy of an if Any boolean expression The if part if( condition ) statement; Any single executable statement

The idea of an if A very natural if-then sort of relationship If the condition is true, then do something For example: If I win a million dollars, Then I’ll yodel like an insane Swiss monkey

Example using if Write a program that prompts the user for the secret password If they enter the word "eggplant", congratulate them for knowing the password

Upcoming

Next time… More on if statements else statements Conditions

Reminders Read Chapter 4 of the textbook Keep working on Project 1 Due next Friday