Docsity

Identifiers and Variables - Assignment | CSC 1760, Assignments of Computer Science

Toggle sidebar
bg1
CSC 1760 Introduction to Programming
Lesson 5: Identifiers and Variables
Due Date: 1/23/2009
1. Textbook: Introduction to Java Programming, Brief Version, Seventh Edition,
Author: Y. Daniel Liang, 2009, Prentice Hall
a. Sections 2.3, 2.4, 2.6, 2.7
2. Overview
Learn how to create identifiers and variables. Identifiers are names of entities in
Java that are used as variables, constants, methods, classes, and packages. Rules
for naming identifiers are:
An identifier is a sequence of characters that consists of letters, digits,
underscores, (_), and dollar signs ($).
An identifier must start with a letter, an underscore, or a dollar sign. It
cannot start with a digit.
An identifier cannot be a reserved word. (See Appendix A, “Java
Keywords.” In the textbook for a list of reserved keywords.)
An identifier cannot be true, false, or null.
An identifier can be of any length.
Java is case sensitive, so identifier x is different that X, or ComputeArea is
different that Computearea.
Use the Java Coding Conventions as a guide to naming different types of
identifiers.
3. Tasks
a. Write, compile, and run a program named Variables.java to declare and
display the following variables:
i. Byte initialized to the smallest value for a byte type.
ii. Byte initialized to the largest value for a byte type.
iii. Short initialized to the smallest value for a short type.
iv. Short initialized to the largest value for a short type.
v. Integer initialized to the smallest value for an integer type.
vi. Integer initialized to the largest value for an integer type.
vii. Float initialized to the smallest value for a float type.
viii. Float initialized to the largest value for a float type.
ix. Double initialized to the smallest value for a double type.
x. Double initialized to the largest value for a double type.
xi. Character initialized to the first printable character from the ASCII
character set.
xii. Character initialized to the last printable character from the ASCII
character set.
xiii. String initialized to the value “This is a string.”
b. Write, compile, and run a program named ConstantValues.java that
declares a constant value for PI with the value 3.14159. Use that constant
pf2

Partial preview of the text

Download Identifiers and Variables - Assignment | CSC 1760 and more Assignments Computer Science in PDF only on Docsity!

CSC 1760 Introduction to Programming

Lesson 5: Identifiers and Variables

Due Date: 1/23/

  1. Textbook: Introduction to Java Programming, Brief Version , Seventh Edition, Author: Y. Daniel Liang, 2009, Prentice Hall a. Sections 2.3, 2.4, 2.6, 2.
  2. Overview Learn how to create identifiers and variables. Identifiers are names of entities in Java that are used as variables, constants, methods, classes, and packages. Rules for naming identifiers are:  An identifier is a sequence of characters that consists of letters, digits, underscores, (_), and dollar signs ($).  An identifier must start with a letter, an underscore, or a dollar sign. It cannot start with a digit.  An identifier cannot be a reserved word. (See Appendix A, “Java Keywords.” In the textbook for a list of reserved keywords.)  An identifier cannot be true, false, or null.  An identifier can be of any length.  Java is case sensitive, so identifier x is different that X, or ComputeArea is different that Computearea.  Use the Java Coding Conventions as a guide to naming different types of identifiers.
  3. Tasks a. Write, compile, and run a program named Variables.java to declare and display the following variables: i. Byte initialized to the smallest value for a byte type. ii. Byte initialized to the largest value for a byte type. iii. Short initialized to the smallest value for a short type. iv. Short initialized to the largest value for a short type. v. Integer initialized to the smallest value for an integer type. vi. Integer initialized to the largest value for an integer type. vii. Float initialized to the smallest value for a float type. viii. Float initialized to the largest value for a float type. ix. Double initialized to the smallest value for a double type. x. Double initialized to the largest value for a double type. xi. Character initialized to the first printable character from the ASCII character set. xii. Character initialized to the last printable character from the ASCII character set. xiii. String initialized to the value “This is a string.” b. Write, compile, and run a program named ConstantValues.java that declares a constant value for PI with the value 3.14159. Use that constant

variable to calculate the volume of a sphere (4/3 * PI * r^3 ) which has a radius of 5. c. Write, compile, and run a program named FeetToMeters.java that converts feet to meters (one foot is 0.305 meters). Initialize the variable used for feet to 5.

  1. Assignment due: a. Variables.java b. ConstantValues.java c. FeetToMeters.java