Activity 3: Data Types

Similar documents
Activity 1: Introduction

Activity 1: Introduction

An Introduction to Processing

Computational Expression

Activity 6: Loops. Content Learning Objectives. Process Skill Goals

Programming with Java

Activity 6: Loops. Content Learning Objectives. Process Skill Goals

Activity 9: Object-Oriented

Activity 9: Object-Oriented

TOPICS TO COVER:-- Array declaration and use.

Activity 4: Methods. Content Learning Objectives. Process Skill Goals

Full file at

Activity 7: Arrays. Content Learning Objectives. Process Skill Goals

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

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

Activity 4: Boolean Logic

Peer Instruction 1. Elementary Programming

ECE 122 Engineering Problem Solving with Java

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

ECE 122. Engineering Problem Solving with Java

Fundamentals of Programming Data Types & Methods

C# MOCK TEST C# MOCK TEST I

Computer Science 145 Midterm 1 Fall 2016

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

Controls Structure for Repetition

Full file at

Using Methods. Writing your own methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics

I. Variables and Data Type week 3

CS110: PROGRAMMING LANGUAGE I

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 4: Control structures. Repetition

Java Basic Datatypees

Java Classes: Math, Integer A C S L E C T U R E 8

Full file at

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

AP Computer Science A

Chapter 4: Control structures

VARIABLES AND TYPES CITS1001

Program Elements -- Introduction

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Datatypes, Variables, and Operations

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

Declaration and Memory

What can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Visual C# Instructor s Manual Table of Contents

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Variables. Store information needed by the program

Array. Prepared By - Rifat Shahriyar

Introduction to Programming Using Java (98-388)

Loops. CSE 114, Computer Science 1 Stony Brook University

Data types Expressions Variables Assignment. COMP1400 Week 2

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Using Java Classes Fall 2018 Margaret Reid-Miller

Values, Variables, Types & Arithmetic Expressions. Agenda

What did we talk about last time? Examples switch statements

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

Object-Oriented Programming

Ticket Machine Project(s)

CS 1302 Chapter 9 (Review) Object & Classes

Chapter 2. Elementary Programming

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Introduction to Programming EC-105. Lecture 2

Section 2.2 Your First Program in Java: Printing a Line of Text

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Software Practice 1 Basic Grammar

Handout 4 Conditionals. Boolean Expressions.

Chapter 02: Using Data

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Basics of Java Programming

Methods and Functions

Object Oriented Programming. Java-Lecture 6 - Arrays

Anatomy of a Java Program: Comments

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

Problem Solving With Loops

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Values and Variables 1 / 30

Programming Projects: 2.1, 2.3, 2.4, 2.7, 2.8, 2.13

Introduction. For instance, if we need to store three whole numbers we can create two integer (int) variables called N1, N2 and tot. tot.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

13 th Windsor Regional Secondary School Computer Programming Competition

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

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

LAB 13: ARRAYS (ONE DIMINSION)

Lexical Structure (Chapter 3, JLS)

Identifiers and Variables

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Activity 11: Designing Classes

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

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

CompSci 125 Lecture 11

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Example: Monte Carlo Simulation 1

Computational Expression

Transcription:

Activity 3: Data Types Java supports two main types of data: primitive types like int and double that represent a single value, and reference types like String and Scanner that represent more complex information. Content Learning Objectives After completing this activity, students should be able to: Explain how using roles improves the team s success. Name Java s primitive data types and give examples of each one. Identify illegal assignment statements, and explain why they are illegal. Describe what it means for variables to store a reference to an object. Process Skill Goals During the activity, students should make progress toward: Providing feedback on how well other team members are working. (Teamwork) Copyright 2017 Chris Mayfield and Stoney Jackson. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Model 1 Team Disruptions Common disruptions to learning in teams include: talking about topics that are off-task, teammates answering questions on their own, entire teams working alone, limited or no communication between teammates, arguing or being disrespectful, rushing to complete the activity, not being an active teammate, not coming to a consensus about an answer, writing incomplete answers or explanations, ignoring ideas from one or more teammates. Questions (10 min) Start time: 1. Pick four of the disruptions listed above. For each one, find something from the role cards that could help improve the team s success. Use a different role for each disruption. a) Manager: b) Presenter: c) Recorder: d) Reflector: Dilbert by Scott Adams. Andrews McMeel Syndication. http://dilbert.com/strip/2010-08-15

Model 2 Primitive Types Keyword Size Min Value Max Value Example byte 1 byte 128 127 (byte) 123 short 2 bytes 32, 768 32, 767 (short) 12345 int 4 bytes 2 31 2 31 1 1234567890 long 8 bytes 2 63 2 63 1 123456789012345L float 4 bytes 3.4 10 38 3.4 10 38 3.14159F double 8 bytes 1.8 10 308 1.8 10 308 3.141592653589793 boolean 1 byte N/A N/A true char 2 bytes 0 65,535 'A' Note that 1 byte is 8 bits, i.e., eight ones and zeros in computer memory. Since there are only two options for each bit, you can represent 2 8 = 256 possible values with 1 byte. Questions (15 min) Start time: 2. Which of the primitive types are integers? Which are floating-point? 3. Why do primitive types have ranges of values? What determines the range of the data type? 4. Why can t computers represent every possible number in mathematics? Will they ever be able to do so? 5. Since a byte can represent 256 different numbers, why is its max value 127 and not 128?

6. What is the data type for each of the following values? 1.14159 0-1.0F 123 7.2E-4 0.0-13L 'H' -128 '0' false true 7. Based on the examples below, when does Java allow you to assign one type of primitive variable to another? int int_ = 3; long long_ = 3L; float float_ = 3.0F; double double_ = 3.0; float_ = int_; float_ = long_; float_ = float_; float_ = double_; int_ = int_; int_ = long_; int_ = float_; int_ = double_; double_ = int_; double_ = long_; double_ = float_; double_ = double_; long_ = int_; long_ = long_; long_ = float_; long_ = double_; int_ = '0'; int_ = false; double_ = '0'; double_ = false; 8. Given the following variable declarations, which of the assignments are not allowed? byte miles; short minutes; int checking; long days; float total; double sum; boolean flag; char letter; checking = 56000; total = 0; sum = total; total = sum; checking = miles; sum = checking; flag = minutes; days = '0';

Model 3 Reference Types int count; double price; String name; Scanner in; count = 0; price = 1.99; name = "Beyonce"; in = new Scanner(System.in); Java has eight primitive types (see Model 2). All other types of data are called reference types, because their value is a memory address. When drawing memory diagrams, use an arrow to reference other memory locations (rather than make up integer values for the actual addresses). Questions (20 min) Start time: 9. What are the reference types in the example above? 10. By convention, what is the difference between primitive and reference type names? 11. Variables in Java can use at most eight bytes of memory. Explain why the values "Beyonce" and System.in cannot be stored directly in the memory locations for name and in. 12. What is the value of the variable count? What is the value of the variable price?

13. What is the value of the variable name? What is the value of the variable in? 14. Carefully explain what it means to assign one variable to another. For example, what does the statement price = count; do in terms of memory? 15. Draw a memory diagram for the following code. Make sure your answer is consistent with what you wrote for #14. int width; double score; Scanner input; String first; String other; width = 20; score = 0.94; input = new Scanner(System.in); first = "Taylor"; score = width; other = first; 16. What is the output of the following statements after running the code above? Explain your answer using the diagram. first = "Swift"; System.out.println(other);