Quick Quiz 1 1. A data item is constant when it cannot be changed while a program is running. A data item is when it might change.
Answer: variable 2. Answer: data type 3. True or False: A variable declaration is a statement that reserves a named memory location. Answer: True 4. The types are all variations of the integer type. Answer: byte, short, and long 5. Using the boolean Data Type 1. Introduce the concept of a boolean variable, which can have one of two values: true or false.
Using Table , describe the relational operators available in Java. Note that the result of each comparison is a boolean value. Discuss that these concepts will be very important in later chapters. Define floating-point numbers. Describe the type of numbers that floating-point values represent. Using Table , introduce the two floating-point data types: double and float. Make sure that students understand the concept of significant digits. Reiterate the concept of precision.
Double variables are more precise than float variables. Demonstrate how to create several floating-point types. As shown on page 72, discuss why you need to type the letter F after the number in float declarations and instantiations. Using the char Data Type 1. Explain the use of the char data type to hold a single character. A constant character value is placed between single quotation marks. Describe the Unicode system as holding all symbols for all languages on the planet.
Unicode helps Java be useful around the world. Some Unicode values are listed in Table ; the entire table can be found at Unicode. Demonstrate how to store Unicode values in the char data type. Introduce the built-in Java type String. Describe the purpose of an escape sequence. Using Table , describe common escape sequences. Discuss the differences between Figures and Students should follow the steps in the book on page 77 to create a Java application that declares and uses a char variable.
Define the Scanner class. Discuss why it is much better than traditional character-bycharacter input. Demonstrate how to use the Scanner class to capture keyboard input from the standard input device keyboard represented by System. Reiterate the importance of the prompt. Selected methods of the Scanner class are listed in Table on page Discuss the importance of echoing the input. Demonstrate what happens if the user types a string into a nextInt prompt.
If desired, you can demonstrate how to correctly input data into Strings, and then convert the Strings to the proper data type. This is covered a little later in the chapter. Illustrate the problems that may occur when using the nextLine method after one of the other Scanner class input methods. Use the code samples in Figures and to aid the discussion. Make sure that students are familiar with the concept of the keyboard buffer. Remind students about using the JOptionPane class to create dialog boxes.
Introduce an input dialog box and a confirm dialog box. Using Input Dialog Boxes 1. Review the code in Figure , which produces the output shown in Figures and Using the code above Figure , demonstrate how the input boxes can be modified with different titles and icons.
Describe how to convert a String into a primitive class using the type-wrapper classes: Integer, Float, and Double. Figure illustrates how to convert a String class into double and int variables. Define the term parse. Its literal meaning is to break an object into component parts. It can be roughly defined as reading the contents of an object.
Using Confirm Dialog Boxes 1. Review the AirlineDialog class in Figure Using the code above Figure , demonstrate how confirm dialog boxes can be modified with different titles and icons. Performing Arithmetic 1. Using Table , show that Java provides all of the standard arithmetic operators. Remind students that the rules of operator precedence apply in a program just as they do in math.
Define operand and binary operators. Identify them in a simple math expression. Differentiate between integer division and floating-point division. Use examples for each. Make sure that students understand that in integer division, any fractional portion of a division result will be lost when both operators are of an integer data type.
The term parse means to break into component parts. You can create a confirm dialog box with five arguments. Once a variable has been declared and initialized, new values may not be assigned to the variable.
Chapter Using Data 7. Even if a statement occupies multiple lines, the statement is not complete until the semicolon is reached. You are limited to declaring a maximum of three variables in a single statement.
The byte and short data types occupy less memory and can hold only smaller values. A data item is when it cannot be changed while a program is running. A is a named memory location that you can use to store a value. Chapter Using Data Primitive types serve as the building blocks for more complex data types, called a.
Associativity b. Initialization c. Declaration d. In Java, you use variables of type a. A n variable can hold only one of two values: true or false. The term refers to the mathematical accuracy of a value. A data type can hold 14 or 15 significant digits of accuracy. You use the a. Chapter Using Data c. In Java, a. Escape c. Type d. Character c 1 You can store any character, including nonprinting characters such as a backspace or a tab, in a n a.
The characters a. In Java, when a numeric variable is concatenated to a String using the String. You use operators to perform calculations with values in your programs. Data modeling b. Type cast c. Integer division d. Unlike assignment. The percent sign is the operator. Updated Programming Exercises and a wealth of case problems help you build skills critical for ongoing programming success.
You can find additional tools to strengthen your Java programming success with the optional CourseMate that includes a wealth of interactive teaching and learning tools and unique Video Quizzes created by the book's author. Creating Java Programs 2. Using Data 3. Using Methods, Classes, and Objects 4. More Object Concepts 5.
This popular text takes a unique, language-independent approach to programming with a distinctive emphasis on modern conventions. The book's clear, concise writing style eliminates highly technical jargon while introducing universal programming concepts and encouraging a strong programming style and logical thinking.
Clear revised explanations utilize flowcharts, pseudocode, and diagrams to ensure even readers with no prior programming experience fully understand modern
0コメント