CompSci 100e Program Design and Analysis II January 18, 2011 Prof. Rodger CompSci 100e, Spring20111.

Slides:



Advertisements
Similar presentations
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Advertisements

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.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
C++ Data Type String A string is a sequence of characters enclosed in double quotes. Examples of strings: “Hello” “CIS 260” “Students” The empty string.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
CS31: Introduction to Computer Science I Discussion 1A 5/7/2010 Sungwon Yang
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Datalogi A 3: 26/9. Java Concepts chapter 4 Fundamental Data Types int (long and short) double (and float) boolean char String.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Strings Reading for this Lecture, L&L, 3.2. Strings String is basically just a collection of characters. Thus, the string “Martyn” could be thought of.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
28-Jun-15 String and StringBuilder Part I: String.
CS 180 Recitation 8 / {30, 31} / Announcements Project 1 is out –Due 10:00pm –Start early! –Use the newsgroup for your questions –LWSN B146.
Active Server Pages Points of Interest Chapters 1-4.
CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.
Getting Started with Java Recitation – 1/23/2009 CS 180 Department of Computer Science, Purdue University.
1 CSC 221: Computer Programming I Spring 2008 ArrayLists and arrays  example: letter frequencies  autoboxing/unboxing  ArrayLists vs. arrays  example:
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
From C++ to Java A whirlwind tour of Java for C++ programmers.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
COMP String and Console I/O Yi Hong May 18, 2015.
EXAM 1 REVIEW. days until the AP Computer Science test.
String Manipulation. Java String class  The String class represents character strings “Tammy Bailey”  All strings (arrays of characters) in Java programs.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
COP 3530 Data Structures & Algorithms Discussion Session 3.
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
CompSci 6 Programming Design and Analysis January 17, 2006 Prof. Rodger.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
String and Scanner CS 21a: Introduction to Computing I First Semester,
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
17-Feb-16 String and StringBuilder Part I: String.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
Chapter 9 Introduction to Arrays Fundamentals of Java.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
2-1 Types of data  Java has two types of data  primitive types that store one value char boolean byte int long float double  reference types to store.
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Strings Chapter 7 CSCI CSCI 1302 – Strings2 Outline Introduction The String class –Constructing a String –Immutable and Canonical Strings –String.
Introduction to Computer Science and Object-Oriented Programming
CompSci 4 Java 1 Apr 2, 2009 Prof. Susan Rodger. Announcements Assignment 7 questions? –Beware having two events that kick in at the same time! –Beware.
Foundations of Programming: Java
Strings CSE 1310 – Introduction to Computers and Programming
String class.
Methods Chapter 4: Methods Asserting Java ©Rick Mercer.
Engineering Innovation Center
CompSci 101 Introduction to Computer Science
Chapter 7: Strings and Characters
CompSci 101 Introduction to Computer Science
Lecture 10 Strings CSE /26/2018.
Object-Oriented Programming
String methods 26-Apr-19.
Strings CSE 1310 – Introduction to Computers and Programming
Strings in Java.
More on iterations using
Strings in Java Strings in Java are also a reference type.
Presentation transcript:

CompSci 100e Program Design and Analysis II January 18, 2011 Prof. Rodger CompSci 100e, Spring20111

Announcements Lab 0 was to get Eclipse/Ambient running Lab 1 (Jan 21/24) – APTs APT Assignment out (do 7 APTs) – 2 done in class, 2 in lab, 3 on your own – Submit all 7 together one Java Project by Jan 25 Consulting hours starting soon….. CompSci 100e, Spring20112

Visualizing Text Text Cloud aka Tag Cloud? – Number of occurrences/emphasis indicated by size of word – Great visual/statistic: – What information is stored in the URL of the NYTimes site above?

Lab 0: Text Clouds Point – To install Eclipse, Ambient, Java Text clouds: A simple yet powerful idea – Visualization of most frequently occurring words within some body of text – Color or font size indicates word frequency What is involved with generating text clouds? – Steps? Issues? – See SimpleWordCount.java and SimpleCloudMaker.java

Problem Solving and Programming How many words are in a file? – What’s a word? – What’s a file? – How do we solve this: simply, quickly, …? What’s the best we can do? Constraints? How many different/unique words are in a file? – How is this related to previous task? How many words do two files have in common? – Spell-checking, stemming, Did you mean..? How many codons does DNA have in common?

Java - for loop

Array Declare and initialize an array of integers Set it to these values: Access item in slot 6 in the array Array is fixed size. The size is:

Example for (int k=0; k<values.length; k++) { values[k] = values[k] + values[k-1]; } What does this do? Is it correct?

Classwork SimpleWordCount.java CompSci 100e, Spring20119

Reading from Files import java.io.File; Declare a file File fileOfCats = new File( “ cats.txt ” ); Use file – pass it as an argument to a Scanner Scanner in = new Scanner(fileOfCats);

Using Scanner class to read Import java.util.Scanner; Declare Scanner and bind it to a file (last slide) Make sure there is input still to read while (in.hasNext()) Read next line String line = in.nextLine(); Read next word/token String word = in.next(); Read next integer String word = in.nextInt();

What will we use Eclipse for in CompSci 100e? Use to write complete java programs – Access libraries Use as an editor to write text files – README – gives info about the program Use to write simple methods, then test with APT

APT – Algorithmic Program Testing Not a complete java program – No main method Focus on and solve one small problem Rich set of data for testing Use Eclipse editor for APT, but cannot run program! Why? Goal: all green

Solve APT DNAreverse CompSci 100e, Spring201114

Strings String – a sequence of characters – objects of the String class String constants: "Hello, World!" All Strings are constants don’t use “new” w/ String String variables: String message = "Hello, World!"; String length: int n = message.length(); Empty string: ""

String CompSci 100e, Spring Concatenating Strings – Use the + operator: String name = "Dave"; String message = "Hello, " + name; Automatic type conversion String a = "Agent00"; int n = 7; String bond = a + n; // bond is "Agent007"

What can you do with strings? Look at API int length() – Returns length of string String substring(int beginIndex) – Returns substring from beginIndex to end of string String substring(int beginIndex, int endIndex) – Returns substring from beginIndex to endIndex -1

Example String one = “ ferriswheel ” ; String two = one.substring(5); String three = one.substring(4,6); What are two and three?

Finding substrings in strings int indexOf(String str) – Returns first position of str in the string – First position in a string is 0 int indexOf(String str, int fromIndex) – Returns first position of str starting at fromIndex

Example String one = “ Cotton Candy ” ; String two = one.substring(indexOf( “ Can ” ), indexOf( “ Can ” )+4); What is two?

Strings String word = “ CompSci 100e ” ; word.length() – returns length of string word.toCharArray() – returns string as an array of characters word.charAt(5) – returns character at position 5 Loop over characters in a string for (char ch: word.toCharArray()) { }

Solve APT ClassScores CompSci 100e, Spring201122