Chapter 2: Using Data

Similar documents
Chapter 2: Using Data

Chapter 02: Using Data

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

Full file at

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Visual C# Instructor s Manual Table of Contents

Course PJL. Arithmetic Operations

Introduction to Programming Using Java (98-388)

CS313D: ADVANCED PROGRAMMING LANGUAGE

ECE 122 Engineering Problem Solving with Java

Chapter 2: Using Data

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

4. Inputting data or messages to a function is called passing data to the function.

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

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

Full file at

Introduction to C# Applications

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Operators. Java operators are classified into three categories:

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

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Chapter 2 Elementary Programming

CIS 110: Introduction to Computer Programming

Declaration and Memory

Primitive Data Types: Intro

4 WORKING WITH DATA TYPES AND OPERATIONS

CSC Java Programming, Fall Java Data Types and Control Constructs

Operators and Expressions

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

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Chapter 2: Basic Elements of C++

Basics of Java Programming

Chapter 2 ELEMENTARY PROGRAMMING

Language Reference Manual simplicity

CMPT 125: Lecture 3 Data and Expressions

Computational Expression

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.

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Chapter 2: Data and Expressions

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Chapter 6 Primitive types

Values and Variables 1 / 30

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

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

The Arithmetic Operators

Java Primer 1: Types, Classes and Operators

JAVA OPERATORS GENERAL

CSC Web Programming. Introduction to JavaScript

1.3b Type Conversion

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

Java Overview An introduction to the Java Programming Language

JAVA Programming Fundamentals

BASIC ELEMENTS OF A COMPUTER PROGRAM

Java Notes. 10th ICSE. Saravanan Ganesh

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Lexical Considerations

CS112 Lecture: Primitive Types, Operators, Strings

The Warhol Language Reference Manual

Expressions and Casting

IT 374 C# and Applications/ IT695 C# Data Structures

GraphQuil Language Reference Manual COMS W4115

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

SECTION II: LANGUAGE BASICS

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

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

More about JOptionPane Dialog Boxes

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Elementary Programming

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

ARG! Language Reference Manual

C Programming

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Zheng-Liang Lu Java Programming 45 / 79

CS 106 Introduction to Computer Science I

Values, Variables, Types & Arithmetic Expressions. Agenda

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

Lexical Considerations

2 nd Week Lecture Notes

Programming Lecture 3

L-System Fractal Generator: Language Reference Manual

Program Elements -- Introduction

Data Types and Variables in C language

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

Chapter 2 Working with Data Types and Operators

Objectives. In this chapter, you will:

Reserved Words and Identifiers

Getting started with Java

Variables, Constants, and Data Types

Object-Oriented Programming in Java

LECTURE 3 C++ Basics Part 2

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Transcription:

Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that you can store in four bytes of memory, which is the size of an int variable. T PTS: 1 REF: 57 3. Multiplication, division, and remainder always take place after addition or subtraction in an expression. F PTS: 1 REF: 70 4. The term parse means to break into component parts. T PTS: 1 REF: 84 5. You can create a confirm dialog box with five arguments. T PTS: 1 REF: 86 MULTIPLE CHOICE 1. A data item is when it cannot be changed while a program is running. a. variable c. primitive b. constant d. literal B PTS: 1 REF: 52 2. A(n) is a named memory location that you can use to store a value. a. cast c. reference b. variable d. primitive B PTS: 1 REF: 52 3. Primitive types serve as the building blocks for more complex data types, called types. a. integer c. reference b. literal d. data C PTS: 1 REF: 52 4. refers to the order in which values are used with operators. a. Associativity c. Declaration b. Initialization d. Floating A PTS: 1 REF: 53-54 5. In Java, you use variables of type to store integers, or whole numbers.

a. num c. var b. double d. int D PTS: 1 REF: 57 6. A(n) variable can hold only one of two values: true or false. a. integer c. true b. boolean d. comparison B PTS: 1 REF: 59 7. The term refers to the mathematical accuracy of a value. a. float data c. significant digits b. real integers d. single-precision floating-point number C PTS: 1 REF: 61 8. A data type can hold 14 or 15 significant digits of accuracy. a. double c. char b. float d. boolean A PTS: 1 REF: 61 9. You use the data type to hold any single character. a. single c. byte b. char d. float B PTS: 1 REF: 62 10. In Java, is a built-in class that provides you with the means for storing and manipulating character strings. a. Escape c. String b. Type d. Character C PTS: 1 REF: 64 11. You can store any character, including nonprinting characters such as a backspace or a tab in a(n) variable. a. int c. boolean b. char d. set B PTS: 1 REF: 65 12. The characters move the cursor to the next line when used within a println() statement. a. /n c..+ b. \n d. $ B PTS: 1 REF: 65 13. In Java, when a numeric variable is concatenated to a String using the, the entire expression becomes a String. a. plus sign c. concatenate statement b. equal sign d. string statement A PTS: 1 REF: 67 14. You use operators to perform calculations with values in your programs.

a. calculation c. integer b. arithmetic d. precedence B PTS: 1 REF: 69 15. occurs when both of the operands are integers. a. Data modeling c. Integer division b. Type cast d. Unlike assignment C PTS: 1 REF: 70 16. The percent sign is the operator. a. remainder c. percentage b. remaining d. integer division A PTS: 1 REF: 70 17. What is the value of result after the following statement is executed? int result = 2 + 3 * 4; a. 9 c. 14 b. 10 d. 20 C PTS: 1 REF: 70 18. The is the type to which all operands in an expression are converted so that they are compatible with each other. a. unifying type c. numbered b. data type d. primitive A PTS: 1 REF: 73 19. A(n) dialog box asks a question and provides a text field in which the user can enter a response. a. question c. confirm b. JOptPane d. input D PTS: 1 REF: 81 20. Each primitive type in Java has a corresponding class contained in the java.lang package. These classes are called classes. a. case c. type-wrapper b. primitive d. show C PTS: 1 REF: 83 21. A(n) dialog box displays the options Yes, No, and Cancel. a. confirm c. message b. input d. answer A PTS: 1 REF: 85 COMPLETION 1. A(n) is a simple data type. primitive type

PTS: 1 REF: 52 2. A(n) operator compares two items and the result has a Boolean value. relational comparison PTS: 1 REF: 59 3. A(n) number contains decimal positions. floating-point float double PTS: 1 REF: 61 4. forces a value of one data type to be used as a value of another type. Type casting Casting PTS: 1 REF: 74 5. When you write programs that accept, there is a risk that the user will enter the wrong type of data. user input PTS: 1 REF: 81 MATCHING Match each term with the correct statement below. a. operand f. primitive b. cast operator g. float c. assignment h. boolean d. operator precedence i. escape sequence e. garbage 1. true or false 2. Operator is represented by an equal sign (=) 3. Programming term for an unknown value 4. Java consistently specifies their size and format 5. Value which can be used on either side of an operator 6. Rules for the order in which parts of a mathematical expression are evaluated 7. Floating-point data type 8. Created by placing the desired result type in parentheses 9. Begins with a backslash followed by a character

1. H PTS: 1 REF: 59 2. C PTS: 1 REF: 53 3. E PTS: 1 REF: 54 4. F PTS: 1 REF: 58 5. A PTS: 1 REF: 69 6. D PTS: 1 REF: 70 7. G PTS: 1 REF: 61 8. B PTS: 1 REF: 74 9. I PTS: 1 REF: 65 SHORT ANSWER 1. A variable declaration is a statement that reserves a named memory location. It includes what four elements? A data type that identifies the type of data that the variable will store An identifier that is the variable s name An optional assignment operator and assigned value, if you want a variable to contain an initial value An ending semicolon PTS: 1 REF: 53 2. Describe variation types byte, short, and long of the integer type. The types byte, short, and long are all variations of the integer type. The byte and short types occupy less memory and can hold only smaller values; the long type occupies more memory and can hold larger values. PTS: 1 REF: 57 3. Describe how to assign values based on the result of comparisons to Boolean variables. Java supports six relational operators that are used to make comparisons. A relational operator compares two items; an expression that contains a relational operator has a Boolean value. When you use any of the operators that have two symbols (==, <=, >=, or!=), you cannot place any whitespace between the two symbols. You also cannot reverse the order of the symbols. That is, =<, =>, and =! are all invalid operators. PTS: 1 REF: 59-60 4. What is the difference between the float data type and the double data type? Java supports two floating-point data types: float and double. A float data type can hold floating-point values of up to six or seven significant digits of accuracy. A double data type requires more memory than a float, and can hold 14 or 15 significant digits of accuracy. The term significant digits refers to the mathematical accuracy of a value. For example, a float given the value 0.324616777 displays as 0.324617 because the value is accurate only to the sixth decimal position.

PTS: 1 REF: 61 5. What is an escape sequence and why would a Java programmer use it to store a character? You can store any character including nonprinting characters such as a backspace or a tab in a char variable. To store these characters, you can use an escape sequence, which always begins with a backslash followed by a character the pair represents a single character. PTS: 1 REF: 65 6. Describe and give an example of operator precedence. Operator precedence refers to the rules for the order in which parts of a mathematical expression are evaluated. The multiplication, division, and remainder operators have the same precedence. Their precedence is higher than that for the addition and subtraction operators. Addition and subtraction have the same precedence. In other words, multiplication, division, and remainder always take place from left to right prior to addition or subtraction in an expression. For example, the following statement assigns 14 to result: int result = 2 + 3 * 4; PTS: 1 REF: 70 7. In Java, how is it possible to perform mathematical operations on operands with unlike types? When you perform arithmetic operations with operands of unlike types, Java chooses a unifying type for the result. The unifying type is the type to which all operands in an expression are converted so that they are compatible with each other. Java performs an implicit conversion; that is, it automatically converts nonconforming operands to the unifying type. PTS: 1 REF: 73 8. Explain how you can override a unifying type imposed by Java. You can explicitly (or purposely) override the unifying type imposed by Java by performing a type cast. Type casting forces a value of one data type to be used as a value of another type. To perform a type cast, you use a cast operator, which is created by placing the desired result type in parentheses. Using a cast operator is an explicit conversion. The cast operator is followed by the variable or constant to be cast. PTS: 1 REF: 74 9. How can you create and use an input dialog box in Java? You can create an input dialog box using the showinputdialog() method. Six overloaded versions of this method are available, but the simplest version uses a single argument that is the prompt you want to display within the dialog box. The showinputdialog() method returns a String that represents a user s response; this means that you can assign the showinputdialog() method to a String variable and the variable will hold the value that the user enters.

PTS: 1 REF: 81 10. How would you ask the user to confirm an action using a dialog box? A confirm dialog box displays the options Yes, No, and Cancel; you can create one using the showconfirmdialog() method in the JOptionPane class. Four overloaded versions of the method are available; the simplest requires a parent component (which can be null) and the String prompt that is displayed in the box. The showconfirmdialog() method returns an integer containing one of three possible values: JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, or JOptionPane.CANCEL_OPTION. PTS: 1 REF: 85