Lesson Plan Course Title: Computer Programming Session Title: Variables and Data Types Lesson Duration: 3-4 hours Performance Objective: Upon completion of this assignment, the student will be able to use primitive data types in a simple program. Specific Objectives: Identify data types based on keywords and values Develop requirements and specifications for variables Differentiate between different data types and variables based on their characteristics Preparation TEKS Correlations: 130.276(c) 4.B – identify input and output requirements 4.D – develop software requirements and specifications 7.A – differentiate among concepts of data Instructor/Trainer References: • Content Developer Knowledge • Java Software Solutions for AP Computer Science by Lewis, Loftus, & Cocking, copyright 2004 Pearson Education, Inc. • Introduction to Computer Science using Java, by Liberty, Quirk & Weiss, copyright 2005, Glencoe McGraw-Hill Instructional Aids: • Presentation: ‘Intro to Variables and Data Types’ • Handout & KEY: ‘Guided Notes: Intro to Variables and Data Types’ • Handout & Lab File & KEY: ‘Observing Variables’ & ‘ObservingVariables.java’ • Lab File: ‘VariablePractice.java’ • Lab File: ‘UsingVariables.java’ • Handout & KEY: ‘Variable Review’ • Handout & KEY: ‘Variable Quiz A, B, & C’ • Handout : ‘Variable Poster’ Materials Needed: • The teacher’s intro demonstration uses about 5 envelopes and 50 3x5 cards • Copies of instructional aides IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 1 • Pencil or pen Equipment Needed: Each student will need access to a computer with Java installed. Learner The learner should have understanding of simple Java code, including system output. Introduction MI Introduction (LSI Quadrant I): The instructor begins the group discussion with a demonstration using envelopes. Label the outside of an envelope with the letter ‘x’. Show the envelope to the class and ask what they think is inside the envelope. Open the envelope to show them that it is empty. Then write a number on a 3x5 card. Show it to the class and put it in the envelope. Discuss the difference between the name of the envelope (x) and the value it contains (whatever is written on the 3x5). Change the label on the envelope so that it reads “int x”, and tell the group that only integers are allowed in the envelope, and it can only contain one integer at a time -and the name of that integer will be ‘x’. Label another envelope “float y”, explaining to the group that ‘float’ means a number with a decimal, and that whatever value is in the envelope will be referred to as ‘y’. Label another envelope “String z”, and explain to the class that this envelope can only contain ‘Strings’, which are words, letters, or symbols that are enclosed in double quotes. Pass out 3x5 cards to class members and invite them to write a value on the card that is a String, an integer, or a float. Pass the envelopes around and invite class members to put values in the appropriate envelopes, making sure to remove the previous value first. When the exercise is over, check the envelopes to see what the final value is in each one. Have the class discuss whether the correct type of data is in the envelope, and how the values were changed as the envelopes were passed around. Discussion should take 5-10 minutes. Outline MI Outline (LSI Quadrant II): Instructor Notes: IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 2 The instructor presents the ‘Intro to Variables and Data Types’ Presentation. Students follow along using the ‘Intro to Variables and Data Types Guided Notes.’ The instructor can pause at any point to expand the discussion or clarify concepts. The Presentation and guided notes can also be used by students who were absent and trying to catch up. It can also be used as a review. Terms & Concepts presented: • The advantage of using named variables, such as ease and flexibility of referring to something with an unknown or changing value, and writing code that is more understandable The guided notes may be graded using the KEY to check student understanding. • Clarification of the difference between a variable name and its value • Characteristics and limitations of a variable’s name • The meaning of a variable’s data type • Variables can change value, except those that are declared with the keyword ‘final’, meaning that they cannot change value • Variables that are final should be named in all capital letters • Variables of the same data type can be declared in the same line • The difference between intrinsic and reference data types • The 8 different intrinsic data types and the kind of information they hold • How to choose a data type based on the type and size of information to be stored • Reference data types (the same as ‘class’ data types) are more complex than primitive data types, and are only briefly explained here. There are millions of Reference data types, the same way there are millions of books and magazines. Any data type that is Reference should begin with a capital letter. More information will be given about this data type when students are introduced to classes. Students who do not complete the guided notes during the presentation may need to review the Presentation on their own time. The Presentation, discussion, and notes should take 15 – 20 minutes. Application MI Guided Practice (LSI Quadrant III): IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 3 Handout & Lab File: ‘Observing Methods’ The teacher could begin this lab by showing it to the students on the overhead projector and discussing different parts of the code. The teacher might even guide the class through the first few questions to get them started. Students should then be able to complete the lab individually or in pairs. The student’s basic goal is to observe, analyze, and report what happens as they follow the various instructions that are in the lab. The student uses numbered questions in the handout that correspond to numbered segments in the lab file that have instructions. The student follows the numbered instructions in the code and answers questions about the code and about the output when the lab file is run. This lab reinforces terminology, and the basics of variables and data types. Encourage students to look at the entire lab file before running the lab or answering questions. One of the benefits of this lab is that the student learns to identify parts of the variable declaration, using the terminology given in the Presentation. This lab could be completed in 10-15 minutes. There is a KEY to assess student understanding. MI Independent Practice (LSI Quadrant III): Lab File: ‘VariablePractice.java’ In this lab exercise, students follow numbered instructions that are imbedded in the code. The first two of the instructions are already completed in the code as an example for the students. Students may refer to the ‘observation’ lab for code examples. The lab is assessed by looking at the code and having the student run the completed lab to check the output statements. This lab takes 10-15 minutes. Summary MI Review (LSI Quadrants I and IV): Handout & KEY: ‘Variable Review’ Students can use their notes and the Presentation to answer questions about examples of variable naming, definition, and use. Teachers may allow students to grade their own self-evaluation, but should hold them accountable for correcting any errors by writing explanations for any question that they miss. This self-evaluation takes 10-15 minutes. Evaluation MI Informal Assessment (LSI Quadrant III): Lab File: ‘UsingVariables.java’ In this lab there are 6 numbered instructions imbedded in the code. Students complete the lab by writing a few lines of code to follow each instruction. The teacher IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 4 evaluates the lab by looking at the student’s code additions in each section and by observing the output. Students can use examples from previous labs to complete the instructions. This lab takes 20-30 minutes. MI Formal Assessment (LSI Quadrant III, IV): Handouts & KEYs: ‘Methods Quiz A, B, & C’ These quizzes are used as formal assessment of students’ understanding of variable and data type terminology and concepts. Each one contains similar material that is rearranged. The ‘C’ version is modified with fewer questions. The quiz takes 10-15minutes to complete. Extension MI Extension/Enrichment (LSI Quadrant IV): Handout : ‘Variable Poster’ This exercise challenges students to consolidate and utilize their understanding of variables and data types by creating a poster to teach others about primitive data types, giving examples and explaining related keywords. Icon MI Teaching Strategies Personal Development Strategies Verbal/ Linguistic Lecture, discussion, journal writing, cooperative learning, word origins Reading, highlighting, outlining, teaching others, reciting information Logical/ Mathematical Problem solving, number games, critical thinking, classifying and organizing, Socratic questioning Organizing material logically, explaining things sequentially, finding patterns, developing systems, outlining, charting, graphing, analyzing information IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 5 Visual/Spatial Musical/ Rhythmic Bodily/ Kinesthetic Intrapersonal Interpersonal Naturalist Existentialist Mind-mapping, reflective time, graphic organizers, color-coding systems, drawings, designs, video, DVD, charts, maps Use music, compose songs or raps, use musical language or metaphors Use manipulatives, hand signals, pantomime, real life situations, puzzles and board games, activities, roleplaying, action problems Reflective teaching, interviews, reflective listening, KWL charts Cooperative learning, roleplaying, group brainstorming, cross-cultural interactions Natural objects as manipulatives and as background for learning Socratic questions, real life situations, global problems/questions Developing graphic organizers, mindmapping, charting, graphing, organizing with color, mental imagery (drawing in the mind’s eye) Creating rhythms out of words, creating rhythms with instruments, playing an instrument, putting words to existing songs Moving while learning, pacing while reciting, acting out scripts of material, designing games, moving fingers under words while reading Reflecting on personal meaning of information, studying in quiet settings, imagining experiments, visualizing information, journaling Studying in a group, discussing information, using flash cards with other, teaching others Connecting with nature, forming study groups with like-minded people Considering personal relationship to larger context IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 6 Name: ____________________ Date: _________________ Period: _______ Guided Notes: Variables and Data Types Objective: To reinforce concepts and syntax learned in the Variables lab as you follow the presentation, and to introduce intrinsic data types. Instructions: Wait for the presentation to fill out the notes below 1. The name of a variable is a location [in Java / in memory ] that holds a value. 2. Circle the variable’s name in the following statement. int height = 7; 3. Circle the part that declares the variable’s name and type. int height = 7; 4. Circle the part that declares the variable’s value. int height = 7; 5. When the variable is [ declared / deleted / initialized ] the location is reserved. 6. When the variable is [ declared / deleted / initialized ] , a value is placed in the location. 7. Rewrite the statement int height = 7; so that the variable is declared in one statement and initialized in a second statement. ______________________; 8. Rewrite the statement int height = 7; so that the variable is a constant. Remember the naming convention for such a variable. _______________________; 9. Rewrite the following statements in a single statement. a. int fingers = 10; b. int eyes = 2; c. int teeth; d. ______________________________________; 10. The two main data types are a. P___________, also called ____________ b. R___________, also called ____________ 11. To store a character, use the ________ primitive data type. 12. To store an extremely large whole number, use the ________ primitive data type. 13. To store a small decimal number, use the ___________ primitive data type. 14. Which one requires more memory? [ byte / short ] Conclusions: Use what you know to answer the following questions. 15. By naming convention, which of the following variables cannot be changed? [ mud / MUD / Mud ]. 16. Circle the correct declaration a. int things = ‘7’; b. int THINGS = 7; c. int things = 7; IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 7 Name: ____________________ Date: _________________ Period: _______ Guided Notes: Variables and Data Types KEY Objective: To reinforce concepts and syntax learned in the Variables lab as you follow the presentation, and to introduce intrinsic data types. Instructions: Wait for the presentation to fill out the notes below. 1. The name of a variable is a location [in Java / in memory ] that holds a value. 2. Circle the variable’s name in the following statement. int height = 7; 3. Circle the part that declares the variable’s name and type. int height = 7; 4. Circle the part that declares the variable’s value. int height = 7; 5. When the variable is [ declared / deleted / initialized ] the location is reserved. 6. When the variable is [ declared / deleted / initialized ] , a value is placed in the location. 7. Rewrite the statement int height = 7; so that the variable is declared in one statement and initialized in a second statement. int height; height = 7; 8. Rewrite the statement int height = 7; so that the variable is a constant. Remember the naming convention for such a variable. final int HEIGHT = 7; 9. Rewrite the following statements in a single statement. a. int fingers = 10; b. int eyes = 2; c. int teeth; d. int fingers = 10, eyes = 2, teeth; 10. The two main data types are a. Primitive, also called intrinsic b. Reference, also called class 11. To store a character, use the char primitive data type. 12. To store an extremely large whole number, use the long primitive data type. 13. To store a small decimal number, use the float primitive data type. 14. Which one requires more memory? [ byte / short ] Conclusions: Use what you know to answer the following questions. 15. By naming convention, which of the following variables cannot be changed? [ mud / MUD / Mud ] 16. Circle the correct declaration a. int things = ‘7’; b. int THINGS = 7; c. int things = 7; IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 8 Name: ____________________ Date: _________________ Period: _______ Enrichment Activity: Creating a Variables Poster Objective: TLW demonstrate understanding of variable syntax and concepts Instructions: Create a poster that explains variable keywords, syntax, and naming conventions, using the following criteria: Primitive Data Types 1. List each of the primitive variables (short, float, long, Boolean, int, double, byte, char). 2. Group the primitive data types by the kind of data they hold, and set them in relative order according to how much data they hold. 3. Show an example of declaring and initializing each of the data types. Test your examples with a compiler to make sure your syntax is correct. Syntax Examples 4. Diagram a statement that declares and initializes a variable. Label the value, data type, and name of the variable. 5. Show an example of declaring and initializing a variable in a single line. 6. Show an example of declaring a variable in one line, and initializing it in a second line. 7. Show an example of declaring a variable that cannot be changed. IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 9 Name: ____________________ Date: _________________ Period: _______ Variable Review Objective: Demonstrate understanding and use of variables and data types Instructions: Answer questions below using words from the Word Bank bit byte decimal int char String text double Boolean 1. The _______________ data type holds true or false. long class short 2. The _______________ data type holds a single character. 3. The _______________ data type stores the smallest integers. 4. The _______________ data type stores the largest decimal numbers. 5. The _______________ data type stores the largest whole numbers. Circle the best answers for the questions below about the statement: int x = 7; 6. What is the value of the variable? [ int / x / 7 ] 7. What is the name of the variable? [ int / x / 7 ] 8. What is the data type of the variable? [ int / x / 7 ] 9. Is the variable initialized? [ yes / no ] 10. Can the value be changed? [ yes / no ] Think about a variable that holds a single character which cannot be changed, and circle the correct answers below. 11. The best name would be…[ myChar / MyChar / MYCHAR ]. 12. The first keyword would be… [ final / int / Boolean / char ]. Complete the following per instructions. 13. Declare and initialize a variable named x which holds the value true;______________________; 14. Declare an integer variable named q, but do not initialize it. ______________________; 15. Declare and initialize a variable named pi, which can hold a very large decimal number and can never change. Give it the value 3.147 ______________________; IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 10 Name: ____________________ Date: _________________ Period: _______ Variable Review KEY Objective: Demonstrate understanding and use of variables and data types Instructions: Answer questions below using words from the Word Bank bit byte decimal long int char String class ext double Boolean short 1. The Boolean data type holds true or false. 2. The char data type holds a single character. 3. The byte data type stores the smallest integers. 4. The double data type stores the largest decimal numbers. 5. The long data type stores the largest whole numbers. Circle the best answers for the questions below about the statement: int x = 7; 6. What is the value of the variable? [ int / x / 7 ] 7. What is the name of the variable? [ int / x / 7 ] 8. What is the data type of the variable? [ int / x / 7 ] 9. Is the variable initialized? [ yes / no ] 10. Can the value be changed? [ yes / no ] Think about a variable that holds a single character which cannot be changed, circle the correct answers below. 11. The best name would be…[ myChar / MyChar / MYCHAR ] 12. The first keyword would be… [ final / int / Boolean / char ] Complete the following per instructions. 13. Declare and initialize a variable named x which holds the value true; Boolean x = true; 14. Declare an integer variable named q, but do not initialize it. int q; 15. Declare and initialize a variable named pi, which can hold a very large decimal number and can never change. Give it the value 3.147 final double PI = 3.147; Name: ____________________ Date: _________________ Period: _______ IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 11 Variable Quiz A Objective: Demonstrate understanding and use of variables and data types Instructions: Complete the questions below Use the following statement for the questions below: int gallons = 43; 1. Has the variable been declared? [ yes / no ] 2. Has the variable been initialized? [ yes / no ] 3. Can the value be changed? [ yes / no ] 4. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: final int Beans; 5. Has the variable been declared? [ yes / no ] 6. Has the variable been initialized? [ yes / no ] 7. Can the value be changed? [ yes / no ] 8. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: int percent = 3.1; 9. What would you change to fix a problem? [ nothing / the name / the value ] 10. If your suggested changes were made, what would you add to make sure the value could not change? [ nothing / constant / final / a comment ] Use your understanding of data types and naming conventions for the following: 11. Rewrite the statement int height = 7; so that the variable is declared in one statement and initialized in a second statement. ________________________ 12. Which data type stores whole numbers? [ Boolean / char / byte ] 13. Which data type stores decimal numbers? [ long / double / short ] 14. Which data type stores extremely large whole numbers? [ byte / double / long ] 15. Can an integer (int) be a negative number? [ yes / no ] 16. Which of the following is constant? [ THING / Thing / thing ] IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 12 Name: ____________________ Date: _________________ Period: _______ Variable Quiz A KEY Objective: Demonstrate understanding and use of variables and data types Instructions: Complete the questions below Use the following statement for the questions below: int gallons = 43; 1. Has the variable been declared? [ yes / no ] 2. Has the variable been initialized? [ yes / no ] 3. Can the value be changed? [ yes / no ] 4. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: final int Beans; 5. Has the variable been declared? [ yes / no ] 6. Has the variable been initialized? [ yes / no ] 7. Can the value be changed? [ yes / no ] 8. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: int percent = 3.1; 9. What would you change to fix a problem? [ nothing / the name / the value ] 10. If your suggested changes were made, what would you add to make sure the value could not change? [ nothing / constant / final / a comment ] Use your understanding of data types and naming conventions for the following: 11. Rewrite the statement int height = 7; so that the variable is declared in one statement and initialized in a second statement. int height; height = 7; 12. Which data type stores whole numbers? [ Boolean / char / byte ] 13. Which data type stores decimal numbers? [ long / double / short ] 14. Which data type stores extremely large whole numbers? [ byte / double / long ] 15. Can an integer (int) be a negative number? [ yes / no ] 16. Which of the following is constant? [ THING / Thing / thing ] IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 13 Name: ____________________ Date: _________________ Period: _______ Variable Quiz B Objective: Demonstrate understanding and use of variables and data types. Instructions: Complete the questions below Use the following statement for the questions below: final double Change; 1. Can the value be changed? [ yes / no ] 2. Has the variable been declared? [ yes / no ] 3. Has the variable been initialized? [ yes / no ] 4. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: int size = 3.1; 5. If your suggested changes were made, what would you add to make sure the value could not change? [ nothing / constant / final / a comment ] 6. What would you change to fix a problem? [ nothing / the name / the value ] Use the following statement for the questions below: int dollars = 43; 7. Can the value be changed? [ yes / no ] 8. Does it follow the correct naming convention? [yes / no ] 9. Has the variable been declared? [ yes / no ] 10. Has the variable been initialized? [ yes / no ] Use your understanding of data types and naming conventions for the following: 11. Which data type stores decimal numbers? [ long / double / short ] 12. Which data type stores extremely large whole numbers? [ byte / double / long ] 13. Can an integer (int) be a negative number? [ yes / no ] 14. Which of the following is constant? [ THING / Thing / thing ] 15. Rewrite the statement String word = “abc”; so that the variable is declared in one statement and initialized in a second statement. ______________________; 16. Which data type stores whole numbers? [ Boolean / char / byte ] IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 14 Name: ____________________ Date: _________________ Period: _______ Variable Quiz B KEY Objective: Demonstrate understanding and use of variables and data types. Instructions: Complete the questions below Use the following statement for the questions below: final double Change; 1. Can the value be changed? [ yes / no ] 2. Has the variable been declared? [ yes / no ] 3. Has the variable been initialized? [ yes / no ] 4. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: int size = 3.1; 5. If your suggested changes were made, what would you add to make sure the value could not change? [ nothing / constant / final / a comment ] 6. What would you change to fix a problem? [ nothing / the name / the value ] Use the following statement for the questions below: int dollars = 43; 7. Can the value be changed? [ yes / no ] 8. Does it follow the correct naming convention? [yes / no ] 9. Has the variable been declared? [ yes / no ] 10. Has the variable been initialized? [ yes / no ] Use your understanding of data types and naming conventions for the following: 11. Which data type stores decimal numbers? [ long / double / short ] 12. Which data type stores extremely large whole numbers? [ byte / double / long ] 13. Can an integer (int) be a negative number? [ yes / no ] 14. Which of the following is constant? [ THING / Thing / thing ] 15. Rewrite the statement String word = “abc”; so that the variable is declared in one statement and initialized in a second statement. String word; word = “abc”; 16. Which data type stores whole numbers? [ Boolean / char / byte ] IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 15 Name: ____________________ Date: _________________ Period: _______ Variable Quiz C Objective: Demonstrate understanding and use of variables and data types. Instructions: Complete the questions below Use your understanding of data types and naming conventions for the following: 1. Rewrite the statement int gallons = 43; so that the variable is declared in one statement and initialized in a second statement. _______________________; 2. Which data type stores whole numbers? [ Boolean / char / byte ] 3. Which data type stores decimal numbers? [ long / double / short ] 4. Which data type stores extremely large whole numbers? [ byte / double / long ] 5. Can an integer (int) be a negative number? [ yes / no ] 6. Which of the following is constant? [ THING / Thing / thing ] Use the following statement for the questions below: int beans = 7; 7. Has the variable been declared? [ yes / no ] 8. Has the variable been initialized? [ yes / no ] 9. Can the value be changed? [ yes / no ] 10. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: final char Glyph; 11. Has the variable been initialized? [ yes / no ] 12. Can the value be changed? [ yes / no ] 13. Does it follow the correct naming convention? [yes / no ] 14. Has the variable been declared? [ yes / no ] Use the following statement for the questions below: int depth = 4.5; 15. What would you change to fix a problem? [ the name / the value ] IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 16 Name: ____________________ Date: _________________ Period: _______ Variable Quiz C KEY Objective: Demonstrate understanding and use of variables and data types. Instructions: Complete the questions below Use your understanding of data types and naming conventions for the following: 1. Rewrite the statement int gallons = 43; so that the variable is declared in one statement and initialized in a second statement. int gallons; gallons = 43; 2. Which data type stores whole numbers? [ Boolean / char / byte ] 3. Which data type stores decimal numbers? [ long / double / short ] 4. Which data type stores extremely large whole numbers? [ byte / double / long ] 5. Can an integer (int) be a negative number? [ yes / no ] 6. Which of the following is constant? [ THING / Thing / thing ] Use the following statement for the questions below: int beans = 7; 7. Has the variable been declared? [ yes / no ] 8. Has the variable been initialized? [ yes / no ] 9. Can the value be changed? [ yes / no ] 10. Does it follow the correct naming convention? [yes / no ] Use the following statement for the questions below: final char Glyph; 11. Has the variable been initialized? [ yes / no ] 12. Can the value be changed? [ yes / no ] 13. Does it follow the correct naming convention? [yes / no ] 14. Has the variable been declared? [ yes / no ] Use the following statement for the questions below: int depth = 4.5; 15. What would you change to fix a problem? [ the name / the value ] IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 17
© Copyright 2026 Paperzz