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

Similar documents
Programming with Java

Oct Decision Structures cont d

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

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review

ECE 122. Engineering Problem Solving with Java

Conditionals. For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations:

Java Programming Language. 0 A history

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Decisions in Java IF Statements

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

APCS Semester #1 Final Exam Practice Problems

LECTURE 3 C++ Basics Part 2

Java Basic Programming Constructs

Midterms Save the Dates!

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Lecture 3 Operators MIT AITI

Midterm Review Topics Java Basics and Structure Variables Branching Loops Methods Arrays. Midterm Review Kage Weiss Lab 001 TA, SPR 17

CS313D: ADVANCED PROGRAMMING LANGUAGE

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Zheng-Liang Lu Java Programming 45 / 79

Chapter 4: Control Structures I

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

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Review for Test 1 (Chapter 1-5)

Accelerating Information Technology Innovation

Control Structures in Java if-else and switch

AP Computer Science A

COMP Primitive and Class Types. Yi Hong May 14, 2015

1007 Imperative Programming Part II

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Program Fundamentals

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII

Building Java Programs

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Prof. Navrati Saxena TA: Rochak Sachan

CS171:Introduction to Computer Science II

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

Chapter 3: Operators, Expressions and Type Conversion

JAVA OPERATORS GENERAL

Building Java Programs

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

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

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Object-Oriented Programming

Basics of Java Programming

STUDENT LESSON A12 Iterations

Computer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters

CIS 110: Introduction to Computer Programming

Fall 2017 CISC124 9/16/2017

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Operators. Java operators are classified into three categories:

CEN 414 Java Programming

Chapter 2: Basic Elements of Java

CS 251L Review Quiz Key

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

4 Programming Fundamentals. Introduction to Programming 1 1

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Iteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times

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

DATA TYPES AND EXPRESSIONS

Operators. Lecture 3 COP 3014 Spring January 16, 2018

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

COMPUTER APPLICATIONS

Declaration and Memory

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Chapter 3: Program Statements

A variable is a name for a location in memory A variable must be declared

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Strings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Controls Structure for Repetition

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Building Java Programs

CMPT 125: Lecture 3 Data and Expressions

Principles of Computer Science

Loops. CSE 114, Computer Science 1 Stony Brook University

CS111: PROGRAMMING LANGUAGE II

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Program Elements -- Introduction

More Programming Constructs -- Introduction

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

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

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

CS171:Introduction to Computer Science II

Chapter 2: Using Data

Computational Expression

Getting started with Java

Topics. Chapter 5. Equality Operators

1. An operation in which an overall value is computed incrementally, often using a loop.

CS 206 Introduction to Computer Science II

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Values, Variables, Types & Arithmetic Expressions. Agenda

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Full file at

Transcription:

Chapter 2 Objects and Primitive Data - AP Chapter Objectives Define the difference between primitive data and objects. Declare and use variables. Perform mathematical computations. Create objects and use them. Explore the difference between a Java application and a Java applet. Create graphical programs that draw shapes. Chapter Overview: During this chapter you should begin to feel comfortable with the declaration of variables, and discuss what happens at each point in declaring an object, creating an instance of that object, assigning vs. changing the state of the object and how that differs from what happens with primitive data. You will begin to do mathematical calculations and should come to understand both the mathematical operators and their precedence. Concept and syntax of enumerated data types is introduced which is an important AP topic. Multiple Choice: 2.1 2.10 True False: 2.1 2.8 Short Answer: 2.1 2.7, 2.9 2.14 AP Multiple Choice: 2.1 2.3 Worksheets: Data Type Identifiers, Precedence, String Methods Programming Projects: 2.1, 2.3, 2.4, 2.7, 2.8, 2.13

PRIMITIVE DATA TYPES IDENTIFIERS IN JAVA 1. State whether the following are legal identifiers in Java. If they are not legal, indicate why. a. number b. 5number c. thisnumber d. that_number e. big number f. char g. character 2. State whether the following are legal declarations and initializations of identifiers. If they are not legal, indicate how to correct them. a. int num1 = 8; b. int num2 = 7.6; c. float num3 = 5; d. float num4 = 5.9; e. float num5 = 4.34e5; f. char ch1 = v ; g. char ch2 = 84; h. double num6 = 78456; i. double num7 = 23,567; j. double num8 = $123.68; k. long num9 = 28; 3. Use the Unicode chart on page 576 find the output of the following code: char letter1 = 'J'; char letter2 = 'a'; char letter3 = 'v'; char letter4 = 'a'; System.out.print("The letters of the word "); System.out.print(letter1); System.out.print(letter2); System.out.print(letter3); System.out.println(letter4); System.out.print("have Unicode values: "); System.out.print((int)letter1 + ", "); System.out.print((int)letter2 + ", "); System.out.print((int)letter3 + " and "); System.out.println((int)letter4);

4. Determine the exact output to the following code segment: int sum1 = 10+5; double sum2 = 10+5.0; int quotient1 = 15/4; double quotient2 = 15/4; double quotient3 = 15/4.0; int remainder1 = 15 % 4; double remainder2 = 17.84 % 2.3; System.out.println("10+5 is " + sum1); System.out.println("10+5.0 is " + sum2); System.out.println("15/4 is " + quotient1); System.out.println("15/4 is " + quotient2); System.out.println("15/4.0 is " + quotient3); System.out.println("15 % 4 is " + remainder1); System.out.println("17.84 % 2.3 is " + remainder2); 5. As discussed in chapter 1, integers are stored as binary values. The base 10 numbers 27 and 21 (using short ints) are stored as 0000000000011011 and 0000000000010101 respectively. Add these two binary numbers together and convert the sum back to base 10. Did you get 48?

Precedence and Assignment Operators Using precedence rules, determine the correct answer to the following expressions: 1. 8 + 3 * 6 / 5 % 6-9 5. 12 * 3 % 8 / 2 2. (8 * 3) / 9 + 2 * 5 6. (12 * 3) % (8 / 2) 3. (double) 9 / 4 7. 17.5 / 3.75 + 2 4. (int) 17.5 / 3 8. 12.5 % 3

Translate each of the following statements into Java code. 9. Increment number by 10. a. longer version b. using assignment operator 10. Increment count by 1. a. longer version b. using increment operator 11. Multiply base by 2. a. longer version b. using assignment operator 12. What is the most important reason for using constants in a program?

Find the output to the following code segments: String Class ( if-else preview) 1. String state = "Mississippi"; int len = state.length(); char ch = state.charat(8); String stub = "ssip"; int index1 = state.indexof(stub); int index2 = state.indexof('s'); System.out.println("The length of " + state + " is " + len + " characters"); System.out.println("The character at index 8 is " + ch); System.out.println("The beginning index of " + stub + " is " + index1); System.out.println("The first index value of s is "+ index2); 2. String state = "Washington"; String abbrev = state.substring(0,2); System.out.println(abbrev.toUpperCase() + " ships " + state.substring(7) + "s of apples"); 3. String state = "California"; if (state.equals(state.tolowercase())) System.out.println("I guess caps don't really matter."); else System.out.println("Picky, picky!"); if (state.equalsignorecase(state.tolowercase())) System.out.println("That gives us some flexibility."); else System.out.println("Are you sure?");