Data Types primitive, arrays, objects Java overview Primitive data types in Java

Similar documents
CS112 Lecture: Introduction to Karel J. Robot

Basic Operations jgrasp debugger Writing Programs & Checkstyle

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

In either case, remember to delete each array that you allocate.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 14: OCT. 25TH INSTRUCTOR: JIAYIN WANG

You must bring your ID to the exam.

ASSIGNMENT 4 Classes and Objects

EE 352 Lab 3 The Search Is On

= 3 + (5*4) + (1/2)*(4/2)^2.

CSCI 204 Introduction to Computer Science II

Lecture 6. Instructor: Craig Duckett

Types, Expressions, and States

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CS 170 Java Programming 1. Week 10: Loops and Arrays

Excel. Spreadsheet functions

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

CMSC131. Library Classes

Enumerations. Fundamentals of Computer Science

Barchard Introduction to SPSS Marks

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Express Yourself. The Great Divide

Barchard Introduction to SPSS Marks

Grouping Objects. Primitive Arrays and Iteration. Produced by: Dr. Siobhán Drohan. Department of Computing and Mathematics

9 Working with the Java Class Library

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Computer Science 136 Assignment 2 Mazes Due: Monday, at noon.

Solutions to Problem 1 of Homework 3 (10 (+6) Points)

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

Quiz 1: Functions and Procedures

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Mehran Sahami Handout #7 CS 106A September 24, 2014

Lesson 18-1 Lesson Lesson 18-1 Lesson Lesson 18-2 Lesson 18-2

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Faculty Guide to Blackboard

Program Elements -- Introduction

Student Outcomes. Lesson Notes. Classwork. Example 2 (3 minutes)

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

ASSIGNMENT 3 Classes, Objects and the Robot World

COMP 110 Project 1 Programming Project Warm-Up Exercise

Blackboard for Faculty: Grade Center (631) In this document:

Math 214 Introductory Statistics Summer Class Notes Sections 3.2, : 1-21 odd 3.3: 7-13, Measures of Central Tendency

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

The Maze Runner. Alexander Kirillov

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

Arrays in Java Multi-dimensional Arrays

Datatypes, Variables, and Operations

CS195H Homework 1 Grid homotopies and free groups. Due: February 5, 2015, before class

Microsoft Excel 2007 Lesson 7: Charts and Comments

Critters. Critter #2 Attack.ROAR Attack.POUNCE Attack.SCRATCH. Critter #1

Adding content to your Blackboard 9.1 class

CPSC 217 Assignment 3

Lecture 15. For-Loops

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it

Chapter 2: Data and Expressions

Course contents. Overview: Goodbye, calculator. Lesson 1: Get started. Lesson 2: Use cell references. Lesson 3: Simplify formulas by using functions

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

9/17/2018 Programming Data Structures. Encapsulation and Inheritance

-Using Excel- *The columns are marked by letters, the rows by numbers. For example, A1 designates row A, column 1.

MIT Programming Contest Team Contest 1 Problems 2008

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

CS 251 Intermediate Programming Java Basics

addition + =5+C2 adds 5 to the value in cell C2 multiplication * =F6*0.12 multiplies the value in cell F6 by 0.12

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

PHP. control structures - loops indexed arrays. Recap: PHP files are processed top to bottom in sequence. Starting at the top

Cellular Automata Language (CAL) Language Reference Manual

File I/O Array Basics For-each loop

CS112 Lecture: Extending Classes and Defining Methods

Programming Languages and Techniques (CIS120)

Inheritance and Interfaces

The User Experience Java Programming 3 Lesson 2

Lesson 1. Introduction to Programming OBJECTIVES

QUIZ: What value is stored in a after this

French-Australian Regional Informatics Olympiad Thursday 9th March, 2017

Part 1 Simple Arithmetic

CS150 - Assignment 5 Data For Everyone Due: Wednesday Oct. 16, at the beginning of class

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming

Full file at

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Functional Programming Languages (FPL)

CSE143X: Computer Programming I & II Programming Assignment #9 due: Monday, 11/27/17, 11:00 pm

Ex: If you use a program to record sales, you will want to remember data:

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM

PA Payroll Exercise for Intermediate Excel

Previously. Iteration. Date and time structures. Modularisation.

Repetitive Program Execution

Using Basic Formulas 4

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Computers in Engineering COMP 208. Subprograms. Subroutines. Subroutines Michael A. Hawker

CMPSCI 250: Introduction to Computation. Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014

Transcription:

Data Types primitive, arrays, objects Java overview Primitive data types in Java 46

Recap Day 2! Lessons Learned:! Sample run vs. pseudocode! Java program structure: set-up, then real statements, decent correspondence between pseudo & java, precision is important! Solution design with subroutines! Suppose you had to make a schedule for this course, much like the one posted. How would you go about setting it up? 47

Programming approaches! Can apply top-down or bottom-up staging to either design or coding.! Don t have to do both the same.! Top-down often works best when designing a solution.! Bottom-up coding can be easier to test as you go along. 48

Subroutine summary! Problem decomposition! Should be reusable! Usually need some data! passed as parameters! [later we'll see: available in the class]! May return a value! functions return values! procedures do not! Called "methods" in Java 49

Data Types! How many different types of data can you name on which a program might need to operate? Consider both primitive types of data that represent only one value and complex ones that are used to store multiple values at once.! Discuss with your neighbors, write down your ideas in a plain text or Word document called datatypes. (You ll submit this to Blackboard later.) 50

More data, more methods! Suppose you need to compute some statistics on a set of values: Average(mean), StdDev, Median - what increasingly complex computation and data storage does each of these subroutines require?! Again, discuss with your neighbors, especially if you don t know how these things are computed. Add some ideas to your datatypes file. 51

Algorithm 5 Numerical Average! Set sum to 0! Set howmany to 0! Prompt for the numbers! While there is more data! Read a number! Add number to sum! Add 1 to howmany! Divide sum by howmany! Return/display sum (now the average) 52

Algorithm 6 Standard Deviation! Let s assume data is input and stored in an array! Stddev(array):! Set average to average(array) [call subroutine]! Set sum to 0! For every value in array:! Set value to value average [subtract average from value]! Set value to value * value [square it]! Add value to sum! Divide sum by length of array! Return squareroot of sum 53

Algorithm 7 Median! Median(array):! Sort(array) [let s hope that this subroutine exists]! Get length of the array! If length is odd! Return middle value! Otherwise! Return average of the two middle values 54

Mazes! What would we want a program that handles mazes to do for us?! How do we solve a maze, from cell 0,0 to the bottom right corner (ending cell)?! How can we represent/store a maze in a plain text format?! Write down a few possible solutions in your datatypes file. 55

Mazes! What would we want a program that handles mazes to do for us?! solve a maze! create a maze! read a maze! store a maze! How do we solve a maze, from cell 0,0 to the bottom right corner (ending cell)?! move to a neighbor of the current cell where there isn't a wall! try to solve from the neighbor to the ending cell! if can't solve, back up and try from a different neighbor! this is a "recursive" method 56

Maze representations unsolved 4 5 1001 1010 1100 1011 1100 0101 1011 0010 1000 0110 0101 1001 1000 0110 1101 0011 0110 0011 1010 0110 text file solved 57

Maze Data Object Oriented! Maze is a 2D array of Cells, along with the row and column dimensions! Each Cell contains data (number or something else), and details that tell us which walls it has (north, south, east, west)! Even a Wall can be consider an object with 2 adjoining Cells and an orientation (horizontal or vertical)! We can represent the cell wall data textually in many ways: 1101 for example might mean there are north, east and west walls, but no south wall 58

Overview - data! simple (primitive) variable types: whole numbers, real numbers, characters, booleans! collections of similar data! strings! lists (1D array)! tables (2D array)! objects user defined types! can hold multiple data attributes! data of varying types 60

Overview - processing! Structured programming: input some data, process it, produce output (sequence, decisions, loops)! Procedural programming: pass data, process it, return value(s) functions call each other or themselves! Object-oriented programming: define data attributes & methods that operate on them, creating powerful new data types 61

Java Program Structure! Class file! Data (optional)! Method definitions! Executable statements! Variable declarations! Method calls! Assignment statements! Decision statements! Loops Program class files must have special main method where execution always begins. 62

JAVA Language Elements! Comments! Not executed documentation only! // single line or /* */ block style! Reserved words! Symbols (operators, punctuation)! Identifiers! Used for names of: classes, methods, variables! Contain: letters, $, _, digits but not as first character! Literal values: numbers, characters, strings! Case sensitive! White space 63

JAVA Applications Programming Interface (API)! Collection of pre-existing Java software! Organized into useful class files! Related class files are in common Packages (folders)! Sometimes they need to be explicitly included in order to be used in your program: import java.packagename.classname;! java.lang.* classes are always implicitly included! The JAVA website contains a full list & documentation 64

Java example1: average.java! Download the code (from course schedule)! Open jgrasp! Let's review the posted code and identify the various statement types! Compile & run 65

Wrap-up! Submit your datatypes notes files with answers to the exercises we did today on Blackboard as c01 in Classwork Submission.! Submission will stay open until tomorrow evening for students who just added the course. 66