Observing Class Basics

30
IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013 1 Lesson Plan Course Title: Computer Programming Session Title: Class Basics Lesson Duration: 3-4 hours Performance Objective: Upon completion of this assignment, the student will be able to create and use classes, including their methods and fields. Specific Objectives: Define and articulate object-oriented terms and concepts Use object oriented techniques to pass and process data Differentiate between procedural and object-oriented design Create an object with methods and fields Preparation TEKS Correlations: 130.276(c) 6.A articulate the principles of object-oriented processes 6.C – use data structure concepts 7.A – differentiate between procedural and object-oriented concepts 7.C – produce an object-oriented program 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 Class Basics Handout & KEY: Guided Notes: Intro to Class Basics Handout & Lab File & KEY: Observing Classes & ObservingClasses.java Lab File: ClassPractice.java Lab File: UsingClasses.java Handout & KEY: Class Basics Review Handout & KEY: Class Basics Quiz A, B, & C Lab File: MyClass.java Materials Needed: Copies of Instructional aides

Transcript of Observing Class Basics

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

1

Lesson Plan Course Title: Computer Programming

Session Title: Class Basics

Lesson Duration: 3-4 hours

Performance Objective: Upon completion of this assignment, the student will be able to create and use classes, including their methods and fields. Specific Objectives: Define and articulate object-oriented terms and concepts Use object oriented techniques to pass and process data Differentiate between procedural and object-oriented design Create an object with methods and fields

Preparation TEKS Correlations: 130.276(c) 6.A – articulate the principles of object-oriented processes 6.C – use data structure concepts 7.A – differentiate between procedural and object-oriented concepts 7.C – produce an object-oriented program 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 Class Basics • Handout & KEY: Guided Notes: Intro to Class Basics • Handout & Lab File & KEY: Observing Classes & ObservingClasses.java • Lab File: ClassPractice.java • Lab File: UsingClasses.java • Handout & KEY: Class Basics Review • Handout & KEY: Class Basics Quiz A, B, & C • Lab File: MyClass.java

Materials Needed: • Copies of Instructional aides

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

2

• 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, data types, and methods.

Introduction

MI Introduction (LSI Quadrant I):

Begin the presentation with a group discussion about common things, such as pencils. Point out that most things can be defined by describing two basic categories they possess: 1) the characteristics they have; and 2) the actions they perform.

In the case of a pencil, some of the characteristics noted might be length, color, lead type, etc. Some of the actions noted could be writing and erasing. Have the group list different things, along with their characteristics and actions. Point out that a general definition of pencils would include actions and characteristics, but that each individual pencil has its own color and its own length that is unique to the particular pencil. Help the group to see that this is an effective way to define something, by listing what it can do and what characteristics it has. This leads into the programming concept of a class (a generic definition of something, like pencils, including its characteristics and actions) and objects (specific instances of the class, like a particular pencil). In the early days of programming all code was ‘procedural’ in that programs included data and processes mixed together. Programs tended to be long and difficult to read because of complex interaction in the code. Programmers noticed that they often duplicated very similar code throughout a single program and again in other program. After many years, programmers began to think of ways to modularize programs so that they could shorten it, make it more understandable, and more usable. One way to do this is to define a program as something with characteristics and actions; this is essentially object-oriented programming. Discussion should take 5-10 minutes.

Outline

MI Outline (LSI Quadrant II): Instructor Notes:

The instructor presents the Intro to Class Basics Presentation. Students follow along using the Intro to Class Basics Guided Notes. The instructor can pause at any point to expand the discussion or clarify concepts. Terms & Concepts presented: • The difference between ‘procedural’ and ‘object-

oriented’ programming • The naming convention for class files • The definition of methods and fields • How constructors are used to create classes • How instance names are used to access

methods and fields • Local variables are those that are declared

inside of a particular method, and their name is only recognized inside of that method.

• Class or instance variables are those that are declared inside of the class, but not inside of any method. Their names are recognized throughout the entire class.

• Class variables and local variables can have the same name, but do not share the same value.

• The keyword ‘this’ works as a substitute for the name of a calling instance. It also identifies instance variables.

• The keyword ‘this’ is typically used in non-static methods when the program needs to refer to the name of the instance that called the method.

• Anonymous instances and anonymous objects mean the same thing. They are used when the name of an object does not need to be used in the code. Typically, this is when a method requires an object as an argument, but that object is not used in any other place in the code. Creating an anonymous object saves the step in code of creating an object with a name, then passing that name to a method.

The Presentation, discussion, and notes should take 15 – 20 minutes.

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. The guided notes may be graded using the KEY to check student understanding. Students who do not complete the guided notes during the presentation may need to review the Presentation on their own time.

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

4

Application

MI Guided Practice (LSI Quadrant III):

Handout & Lab File: Observing Classes

The teacher can 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 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 class terminology and concepts, including methods, fields, and constructors. 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 instances and method calls, using the terminology given in the Presentation. This lab can be completed in 10-15 minutes. There is a KEY to assess student understanding.

MI Independent Practice (LSI Quadrant III):

Lab File: ClassPractice.java In this lab exercise, students follow numbered instructions that are imbedded in the code. Instruction #0 is already completed in the code as an example for the students. Students may refer to the ‘observation’ lab for code examples. The teacher assesses the lab 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: ‘Class Basics Review’ Students can use their notes and the Presentation to answer questions about class terms, concepts, and code segments. 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: UsingClasses.java In this lab there are 8 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

5

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: Class Basics Quiz A, B, & C

These Quizzes are used as formal assessment of students’ understanding of class 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):

Lab : MyClass.java

This exercise challenges students to apply their understanding of class terminology and concepts by creating a class for themselves. Students rename ‘MyClass.java’ to be their own name, such as ‘Jennifer.java’. They must create at least two fields, two methods, and a constructor. In addition, the main method must create at least two instances and use them to access instance fields and methods. Student instructions are in the file. Labs are assessed by looking at the code and the output. Encourage the students to have fun with the lab and to show each other their output. This lab takes from 20 – 40 minutes depending on student enthusiasm.

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

6

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

Visual/Spatial

Mind-mapping, reflective time, graphic organizers, color-coding systems, drawings, designs, video, DVD, charts, maps

Developing graphic organizers, mind-mapping, charting, graphing, organizing with color, mental imagery (drawing in the mind’s eye)

Musical/ Rhythmic

Use music, compose songs or raps, use musical language or metaphors

Creating rhythms out of words, creating rhythms with instruments, playing an instrument, putting words to existing songs

Bodily/ Kinesthetic

Use manipulatives, hand signals, pantomime, real life situations, puzzles and board games, activities, role-playing, action problems

Moving while learning, pacing while reciting, acting out scripts of material, designing games, moving fingers under words while reading

Intrapersonal

Reflective teaching, interviews, reflective listening, KWL charts

Reflecting on personal meaning of information, studying in quiet settings, imagining experiments, visualizing information, journaling

Interpersonal

Cooperative learning, role-playing, group brainstorming, cross-cultural interactions

Studying in a group, discussing information, using flash cards with other, teaching others

Naturalist

Natural objects as manipulatives and as background for learning

Connecting with nature, forming study groups with like minded people

Existentialist

Socratic questions, real life situations, global problems/questions

Considering personal relationship to larger context

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

7

Name: ________________________ Date: _____________ Period: __________

Guided Notes: Intro to Class Basics Objective: Understand terminology and concepts related to classes Instructions: Answer questions and complete statements as you follow the Presentation: Intro to Classes. Intro to Classes:

1. The name of the class is the same as the _________ name.

2. An object is a specific ____________ of a class.

3. As Class is to Object, Recipe is to [ Pizza / Eat ]

4. A Class only contains two things: _________ and _________.

5. Methods and fields are members of the [ file / class / constructor ]

6. Which class member is a definition of something a class can do? [ method / field ]

7. In the Car class, trunk would be considered a [ method / field ]

8. In the example, the Class definition of Car that has two fields, the name of the fields are ___________ and ___________.

9. In the example, the Class definition of Car that has one method, the name of the method

is ____________. Creating an Object

10. The thing that is used to create a new instance is called a ____________. 11. Every class has a constructor. [ True / False ]

12. Constructors always have the same name as the [ field / class ] .

13. In the example, the name of the first instance that is created is ________.

14. The definition of a constructor [ does / does NOT ] show a return data type.

15. A constructor always returns what data type? [ int / String / the data type of the class /

void ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

8

Using Methods and Fields

16. Two different instances [ can / can NOT ] have different values for the same field. 17. In the expression c1.color, which one is the field name? [ c1 / color ]

18. In the expression c1.honk(), which one is the instance name? [ c1 / honk() ]

19. In the expression c1.getColor(), is an argument passed to the method? [ Yes / No ]

20. Does the definition of the method getColor, contain the name of an instance? [ Yes /

No ] This

21. If a method is called using an instance name, the method needs to use the instance name when it refers to the instance variables. [ T / F ]

22. The expression this.age refers to the [ local / instance ] variable.

Anonymous Objects

23. Which method call uses an anonymous object? a. explodeObject(b); b. explodeObject(new Bomb(“tnt”);

Review

24. If there was a class named Toad, the name of the constructor would be _____________.

25. Write a line that calls a constructor to create an instance of Toad called t1.

__________________________;

26. Assume there is an instance of the Toad class named t1, with a field called ‘skin’. Write a line of code that sets t1’s skin field to “brown”. __________________________________;

27. Assume the Toad class has a method named ‘jump()’, that takes no arguments. Write a

line that calls this method for the instance t1. ___________________;

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

9

Name: ________________________ Date: _____________ Period: __________ Guided Notes: Intro to Class Basics KEY Objective: Understand terminology and concepts related to classes Instructions: Answer questions and complete statements as you follow the Presentation: Intro to Classes. Intro to Classes:

1. The name of the class is the same as the file name.

2. An object is a specific instance of a class.

3. As Class is to Object, Recipe is to [ Pizza / Eat ]

4. A Class only contains two things: methods and fields.

5. Methods and fields are members of the [ file / class / constructor ]

6. Which class member is a definition of something a class can do? [ method / field ]

7. In the Car class, trunk would be considered a [ method / field ]

8. In the example, the Class definition of Car that has two fields, the name of the fields are color and weight.

9. In the example, the Class definition of Car that has one method, the name of the method

is honk. Creating an Object

10. The thing that is used to create a new instance is called a constructor. 11. Every class has a constructor. [ True / False ]

12. Constructors always have the same name as the [ field / class ] .

13. In the example, the name of the first instance that is created is c1.

14. The definition of a constructor [ does / does NOT ] show a return data type.

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

10

15. A constructor always returns what data type? [ int / String / the data type of the class / void ]

Using Methods and Fields

16. Two different instances [ can / can NOT ] have different values for the same field. 17. In the expression c1.color, which one is the field name? [ c1 / color ]

18. In the expression c1.honk(), which one is the instance name? [ c1 / honk() ]

19. In the expression c1.getColor(), is an argument passed to the method? [ Yes / No ]

20. Does the definition of the method getColor, contain the name of an instance? [ Yes /

No ] This

21. If a method is called using an instance name, the method needs to use the instance name when it refers to the instance variables. [ T / F ]

22. The expression this.age refers to the [ local / instance ] variable.

Anonymous Objects

23. Which method call uses an anonymous object? a. explodeObject(b); b. explodeObject(new Bomb(“tnt”);

Review

24. If there was a class named Toad, the name of the constructor would be Toad.

25. Write a line that calls a constructor to create an instance of Toad called t1. Toad t1 = new Toad();

26. Assume there is an instance of the Toad class named t1, with a field called ‘skin’. Write a line of code that sets t1’s skin field to “brown”. t1.skin = “brown”;

27. Assume the Toad class has a method named ‘jump()’, that takes no arguments. Write a line that calls this method for the instance t1. t1.jump();

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

11

Name: ________________________ Date: _____________ Period: __________

Observing Class Basics Objective: Observe and analyze class basics. Instructions: Compile and run the file ObservingClasses.java as you follow instructions and answer the questions below.

1. In segment #0(the entire class) give the names of the following: a. The class - _____________________ b. The constructor - _________________________ c. Other than the main method, name the other 2 methods - _____________,

__________________.

2. In #0, what are the names of the 2 fields (variables)? __________, __________

3. In #1, what are the names of the 2 instances that are created? _______, _______

4. In #1, after the constructor is called to create a new instance, what is the value of co1’s size? ______.

5. In #2, what is the name of the method that is called by both instances? ______________

6. In #2, is the same value printed by two calls to the same method? [ Yes / No ]

7. In segment #3, there are two print statements that print the same value. Which one does

it by calling a method that returns the value of size? [ first / second ]

8. In segment #3, does it appear that an instance can get the value of its own fields without calling a method? [ Yes / No ]

9. In segment #4, does it appear that an instance can change the value of its own fields

by accessing them directly? [ Yes / No ]

10. In segment #5, Can you access a field in the main method without using the name of an instance? Uncomment the lines in #5 to find out? [ Yes / No ]

11. In segment #6, can you access a field in other methods without using the name of an

instance? [ Yes / No ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

12

Name: ________________________ Date: _____________ Period: __________

Observing Class Basics KEY Objective: Observe and analyze class basics. Instructions: Compile and run the file ObservingClasses.java as you follow instructions and answer the questions below.

1. In segment #0(the entire class) give the names of the following: a. The class - ObservingClasses b. The constructor - ObservingClasses c. Other than the main method, name the other 2 methods - printName, getSize .

2. In #0, what are the names of the 2 fields (variables)? name, size

3. In #1, what are the names of the 2 instances that are created? co1, co2,

4. In #1, after the constructor is called to create a new instance, what is the value of co1’s

size? 5 .

5. In #2, what is the name of the method that is called by both instances? printName

6. In #2, is the same value printed by two calls to the same method? [ Yes / No ]

7. In segment #3, there are two print statements that print the same value. Which one does it by calling a method that returns the value of size? [ first / second ]

8. In segment #3, does it appear that an instance can get the value of its own fields

without calling a method? [ Yes / No ]

9. In segment #4, does it appear that an instance can change the value of its own fields by accessing them directly? [ Yes / No ]

10. In segment #5, Can you access a field in the main method without using the name of

an instance? Uncomment the lines in #5 to find out? [ Yes / No ]

11. In segment #6, can you access a field in other methods without using the name of an instance? [ Yes / No ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

13

Name: ________________________ Date: _____________ Period: __________

Class Basics Review Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. The name of the file is always the same as the name of the [ variable / method /

class / field ].

2. A [ variable / method / constructor ] is used to create a specific instance of a class.

3. A cook follows a recipe to create a hamburger. Which is more like a class? [ the hamburger / the recipe / the actions of frying and burger flipping ]

4. Not all classes have a constructor. [ True / False ]

5. Fields and methods are known as [ members / instances / objects ] of a class.

6. In the Bird class, fly would be considered a [ method / field ]

7. In the Bird class, featherColor would be a [ method / field ] .

SnowMan frosty = new SnowMan(3); frosty.hat = “blue”; frosty.melt(2);

8. In the code above, the instance name is [ SnowMan / frosty / hat ]

9. In the code above, hat is a(n) [ argument / constructor / method / field ]

10. In the code above, melt is a(n) [ argument / constructor / method / field ]

11. In the code above, the call to the constructor returns what data type? [ int / String / SnowMan / frosty ]

12. Consider the code above; assume that the class has a field named ‘buttons’; for the

instance in the code above, write a line of code that will set the buttons field to the value of 3. _______________________

13. Consider the code above; assume that a second instance was also created; could that

instance also have a ‘buttons’ field? [ Yes / No ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

14

14. Write a line of code that creates a new instance named s of the Squid class, by calling a constructor without arguments. ________________

15. Assume there is an instance of the Squid class named s, with a field called ‘size’. Write a

line of code that sets s’s size field to 12.2. ___________________ Student s1 = new Student(“bob”); graduate(s1);

16. Choose the line below that rewrites the code above to call the graduate method using an anonymous instance.

a. s1.graduate(“bob”); b. graduate(s1); c. graduate(Student); d. graduate(new Student(“bob”)); e. Student.graduate(“bob”); f. Student = new(graduate.s1);

17. Which of the following is the local variable?

a. x.length b. this.length c. length

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

15

Name: ________________________ Date: _____________ Period: __________

Class Basics Review KEY Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. The name of the file is always the same as the name of the [ variable / method /

class / field ].

2. A [ variable / method / constructor ] is used to create a specific instance of a class.

3. A cook follows a recipe to create a hamburger. Which is more like a class? [ the hamburger / the recipe / the actions of frying and burger flipping ]

4. Not all classes have a constructor. [ True / False ]

5. Fields and methods are known as [ members / instances / objects ] of a class.

6. In the Bird class, fly would be considered a [ method / field ]

7. In the Bird class, featherColor would be a [ method / field ] .

SnowMan frosty = new SnowMan(3); frosty.hat = “blue”; frosty.melt(2);

8. In the code above, the instance name is [ SnowMan / frosty / hat ]

9. In the code above, hat is a(n) [ argument / constructor / method / field ]

10. In the code above, melt is a(n) [ argument / constructor / method / field ]

11. In the code above, the call to the constructor returns what data type? [ int / String / SnowMan / frosty ]

12. Consider the code above; assume that the class has a field named ‘buttons’, for the

instance in the code above; write a line of code that will set the buttons field to the value of 3. __frosty.buttons = 3; ___

13. Consider the code above; assume that a second instance was also created; could that

instance also have a ‘buttons’ field? [ Yes / No ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

16

14. Write a line of code that creates a new instance named s of the Squid class, by calling a constructor without arguments. Squid s = new Squid();

15. Assume there is an instance of the Squid class named s, with a field called ‘size’. Write a line of code that sets s’s size field to 12.2. s.size = 12.2;

Student s1 = new Student(“bob”); graduate(s1);

16. Choose the line below that rewrites the code above to call the graduate method using an anonymous instance.

a. s1.gradutae(“bob”); b. graduate(s1); c. graduate(Student); d. graduate(new Student(“bob”)); e. Student.graduate(“bob”); f. Student = new(graduate.s1);

17. Which of the following is the local variable?

a. x.length b. this.length c. length

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

17

Name: ________________________ Date: _____________ Period: __________

Quiz A: Class Basics Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. The name of the class is the same as the name of the [ variable / method / file / field ].

2. An object is a specific [ variable / instance / method / constructor ] of a class.

3. As Class is to Object, a Blueprint is to a [ house / board / homebuyer ]

4. All classes have a constructor. [ True / False ]

5. A [ field / method ] is a definition of something a class can do.

6. A field is a member of a class [ True / False ]

7. In the Vampire class, bite would be considered a [ method / field ]

8. In the Student class, eyeColor would be a [ method / field ] .

Robot r1 = new Robot(“robby”);

9. In the code above, r1 is the [ class / constructor / instance / argument ]

10. In the code above, robby is the [ class / constructor / instance / argument ]

11. A constructor returns what data type? [ void / int / the data type of the class ]

12. Two different instances [ can / can NOT ] have different values for the same field. 13. In the expression r1.color, which one is the field name? [ r1 / color ]

14. In the expression r1.explode(), which one is the instance name? [ r1 / explode() ]

15. Write a line of code that creates a new instance named t1 of the Tree class, by calling a

constructor without arguments. _______________

16. Assume there is an instance of the Squid class named s1, with a field called ‘arms’. Write a line of code that sets s1’s arms field to 10. _________________

17. Which of the following is an example of using an anonymous object?

a. makeFire(new Matches(3));

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

18

b. makeFire(x); 18. Use the two following lines to create your own method call with an anonymous object.

Person p = new Person(“bob”); cannibalMeal(p); _________________________ 19. Which of the following is the local variable?

a. this.size b. size

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

19

Name: ________________________ Date: _____________ Period: __________

Quiz A: Class Basics KEY Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. The name of the class is the same as the name of the [ variable / method / file / field ].

2. An object is a specific [ variable / instance / method / constructor ] of a class.

3. As Class is to Object, a Blueprint is to a [ house / board / homebuyer ]

4. All classes have a constructor. [ True / False ]

5. A [ field / method ] is a definition of something a class can do.

6. A field is a member of a class [ True / False ]

7. In the Vampire class, bite would be considered a [ method / field ]

8. In the Student class, eyeColor would be a [ method / field ] .

Robot r1 = new Robot(“robby”);

9. In the code above, r1 is the [ class / constructor / instance / argument ]

10. In the code above, robby is the [ class / constructor / instance / argument ]

11. A constructor returns what data type? [ void / int / the data type of the class ]

12. Two different instances [ can / can NOT ] have different values for the same field. 13. In the expression r1.color, which one is the field name? [ r1 / color ]

14. In the expression r1.explode(), which one is the instance name? [ r1 / explode() ]

15. Write a line of code that creates a new instance named t1 of the Tree class, by calling a

constructor without arguments. Tree t1 = new Tree();

16. Assume there is an instance of the Squid class named s1, with a field called ‘arms’. Write a line of code that sets s1’s arms field to 10. s1.arms = 10;

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

20

17. Which of the following is an example of using an anonymous object? a. makeFire(new Matches(3)); b. makeFire(x);

18. Use the two following lines to create your own method call with an anonymous object.

Person p = new Person(“bob”); cannibalMeal(p); cannibalMeal(new Person(“bob”)); 19. Which of the following is the local variable?

a. this.size b. size

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

21

Name: ________________________ Date: _____________ Period: __________

Quiz B: Class Basics Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. A class always has a constructor. [ True / False ]

2. A constructor returns what data type? [ void / int / the data type of the class ]

3. Two different instances [ can / can NOT ] have different values for the same field. 4. In the expression x1.size, which one is the field name? [ x1 / size ]

5. In the expression x1.fly(), which one is the instance name? [ x1 / fly() ]

6. Write a line of code that creates a new instance named h1 of the House class, by calling

a constructor without arguments. ________________________;

7. Assume there is an instance of the Centipede class named cc, with a field called ‘legs’. Write a line of code that sets cc’s legs field to 100. ___________________;

8. Which of the following is an example of using an anonymous object?

a. makeFire(new Matches(3)); b. makeFire(x);

9. Use the two following lines to create your own method call with an anonymous object.

Person p = new Person(“bob”); cannibalMeal(p); ___________________________; 10. Which of the following is the local variable?

a. this.size b. size

11. The name of the class is the same as the name of the [ variable / method / file /

field ].

12. An object is a specific [ variable / method / constructor / instance ] of a class.

13. As Class is to Object, a Blueprint is to a [ board / homebuyer / house ]

14. A [ field / method ] is a definition of something a class can do.

15. A field is a member of a class [ True / False ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

22

16. In the Gun class, shoot would be considered a [ method / field ]

17. In the Tree class, height would be a [ method / field ] . Car c1 = new Car(“toyota”);

18. In the code above, toyota is the [ class / constructor / instance / argument ]

19. In the code above, c1 is the [ class / constructor / instance / argument ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

23

Name: ________________________ Date: _____________ Period: __________

Quiz B: Class Basics KEY Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. A class always has a constructor. [ True / False ]

2. A constructor returns what data type? [ void / int / the data type of the class ]

3. Two different instances [ can / can NOT ] have different values for the same field.

4. In the expression x1.size, which one is the field name? [ x1 / size ]

5. In the expression x1.fly(), which one is the instance name? [ x1 / fly() ]

6. Write a line of code that creates a new instance named h1 of the House class, by calling a constructor without arguments. House 11 = new House();

7. Assume there is an instance of the Centipede class named cc, with a field called ‘legs’.

Write a line of code that sets cc’s legs field to 100. cc.legs = 100;

8. Which of the following is an example of using an anonymous object? a. makeFire(new Matches(3)); b. makeFire(x);

9. Use the two following lines to create your own method call with an anonymous object.

Person p = new Person(“bob”); cannibalMeal(p); cannibalMeal(new Person(“bob”));

10. Which of the following is the local variable? a. this.size b. size

11. The name of the class is the same as the name of the [ variable / method / file /

field ].

12. An object is a specific [ variable / method / constructor / instance ] of a class.

13. As Class is to Object, a Blueprint is to a [ board / homebuyer / house ]

14. A [ field / method ] is a definition of something a class can do.

15. A field is a member of a class [ True / False ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

24

16. In the Gun class, shoot would be considered a [ method / field ]

17. In the Tree class, height would be a [ method / field ] .Car c1 = new Car(“toyota”);

18. In the code above, toyota is the [ class / constructor / instance / argument ]

19. In the code above, c1 is the [ class / constructor / instance / argument ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

25

Name: ________________________ Date: _____________ Period: __________

Quiz C: Class Basics Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. A constructor returns what data type? [ void / int / the data type of the class ]

2. Two different instances [ can / can NOT ] have different values for the same field. 3. In the expression r1.color, which one is the field name? [ r1 / color ]

4. In the expression r1.explode(), which one is the instance name? [ r1 / explode() ]

5. The name of the class is the same as the name of the [ variable / method / file /

field ].

6. An object is a specific [ variable / instance / method / constructor ] of a class.

7. All classes have a constructor. [ True / False ]

8. A [ method / field ] is a definition of something a class can do.

9. A field is a member of a class [ True / False ]

10. In the Frog class, jump would be considered a [ method / field ]

11. In the Frog class, color would be a [ method / field ] . Shirt ss = new Shirt(“blue”);

12. In the code above, ss is the [ class / constructor / instance / argument ]

13. In the code above, blue is the [ class / constructor / instance / argument]

14. Write a line of code that creates a new instance named ff of the Flower class, by calling a constructor without arguments. __________________________;

15. Assume there is an instance of the Cootie class named cc, with a field called ‘antenna’.

Write a line of code that sets cc’s antenna field to 2. ___________________;

16. Which of the following is an example of using an anonymous object? a. makeFire(new Matches(3)); b. makeFire(x);

17. Which of the following is the local variable?

a. weight b. this.weight

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

26

Name: ________________________ Date: _____________ Period: __________

Quiz C: Class Basics KEY Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below.

1. A constructor returns what data type? [ void / int / the data type of the class ]

2. Two different instances [ can / can NOT ] have different values for the same field. 3. In the expression r1.color, which one is the field name? [ r1 / color ]

4. In the expression r1.explode(), which one is the instance name? [ r1 / explode() ]

5. The name of the class is the same as the name of the [ variable / method / file /

field ].

6. An object is a specific [ variable / instance / method / constructor ] of a class.

7. All classes have a constructor. [ True / False ]

8. A [ method / field ] is a definition of something a class can do.

9. A field is a member of a class [ True / False ]

10. In the Frog class, jump would be considered a [ method / field ]

11. In the Frog class, color would be a [ method / field ] . Shirt ss = new Shirt(“blue”);

12. In the code above, ss is the [ class / constructor / instance / argument ]

13. In the code above, blue is the [ class / constructor / instance / argument]

14. Write a line of code that creates a new instance named ff of the Flower class, by calling a constructor without arguments. Flower ff = new Flower();

15. Assume there is an instance of the Cootie class named cc, with a field called ‘antenna’.

Write a line of code that sets cc’s antenna field to 2. cc.antenna = 2;

16. Which of the following is an example of using an anonymous object? a. makeFire(new Matches(3)); b. makeFire(x);

17. Which of the following is the local variable?

a. weight b. this.weight

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

27

Name: ________________________ Date: _____________ Period: __________

Test: Class Basics Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below. Wasp w1 = new Wasp(12); // #1 Wasp w2 = new Wasp(9); // #2 w1.fly(3); // #3 w1.energy = w1.energy++; // #4 w2.sting( ); // #5 Nest.addToNest(w2); // #6 Nest.addToNest(new Wasp(7)); // #7 public void fly(int energy) { // #8 this.energy = this.energy - energy; } // #9

1. In the code above, w1 is the [ class / constructor / instance / argument / field / method ]

2. In the code above, 12 is the [ class / constructor / instance / argument / field /

method ]

3. In the code above, fly is the [ class / constructor / instance / argument / field / method ]

4. In the code above, energy is the [ class / constructor / instance / argument /

field / method ]

5. In the code above, there are [ 0 / 1 / 2 / 3 ] instances.

6. In the code above, what is the data type of the argument that is passed to the method addToNest ? ____________

7. In the code above, which line is an example of an anonymous instance?

[ 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 ]

8. In the code above, the energy variable in line #8 [ is / is NOT ] the same variable as in line #4.

9. In the code above, in line #9, which is the local variable? [ this.energy / energy ]

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

28

Use your memory to answer the questions below.

10. A constructor returns what data type? [ void / int / the data type of the class ] 11. The name of the file is the same as the name of the [ class / variable /

method / field ].

12. A class must have a constructor. [ True / False ]

13. Methods and fields are both members of a class [ True / False ]

14. Two different instances [ can / can NOT ] have different values for the same field.

15. Write a line of code that creates a new instance named t1 of the Turtle class, by

calling a constructor without arguments. _________________

16. Assume there is an instance of the Turtle class named t1, with a field called ‘teeth’. Write a line of code that sets t1’s teeth field to 10. ______________________

17. Use the two following lines to create your own method call with an anonymous

object. Squid s1 = new Squid(“inky”); stirFry(s1);

___________________________

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

29

Name: ________________________ Date: _____________ Period: __________

Test: Class Basics KEY Objective: Demonstrate understanding of basic terminology and concepts of classes by answering the questions below. Wasp w1 = new Wasp(12); // #1 Wasp w2 = new Wasp(9); // #2 w1.fly(3); // #3 w1.energy = w1.energy++; // #4 w2.sting( ); // #5 Nest.addToNest(w2); // #6 Nest.addToNest(new Wasp(7)); // #7 public void fly(int energy) { // #8 this.energy = this.energy - energy; } // #9

1. In the code above, w1 is the [ class / constructor / instance / argument / field / method ]

2. In the code above, 12 is the [ class / constructor / instance / argument / field /

method ]

3. In the code above, fly is the [ class / constructor / instance / argument / field / method ]

4. In the code above, energy is the [ class / constructor / instance / argument /

field / method ]

5. In the code above, there are [ 0 / 1 / 2 / 3 ] instances.

6. In the code above, what is the data type of the argument that is passed to the method addToNest ? Wasp

7. In the code above, which line is an example of an anonymous instance?

[ 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 ]

8. In the code above, the energy variable in line #8 [ is / is NOT ] the same variable as in line #4.

IT: [Computer Programming]: [Career Opportunities] Plan Copyright © Texas Education Agency, 2013

30

9. In the code above, in line #9, which is the local variable? [ this.energy / energy ] Use your memory to answer the questions below.

10. A constructor returns what data type? [ void / int / the data type of the class ] 11. The name of the file is the same as the name of the [ class / variable /

method / field ].

12. A class must have a constructor. [ True / False ]

13. Methods and fields are both members of a class [ True / False ]

14. Two different instances [ can / can NOT ] have different values for the same field.

15. Write a line of code that creates a new instance named t1 of the Turtle class, by

calling a constructor without arguments. Turtle t1 = new Turtle();

16. Assume there is an instance of the Turtle class named t1, with a field called ‘teeth’. Write a line of code that sets t1’s teeth field to 10. t1.teeth = 10;

17. Use the two following lines to create your own method call with an anonymous object. Squid s1 = new Squid(“inky”); stirFry(s1);

stirFryl(new Squid(“inky”)); NOTE: it does NOT matter what is in the quotes, it could be “inky” or any other word.