Unit Plan - Basic Programming Constructs
Unit Plan: Basic Programming Constructs
Unit Overview
This unit introduces students to the foundational programming constructs in Java, including variables, data types, operators, control structures (conditional statements and loops), and basic debugging techniques. These concepts form the building blocks for writing effective and efficient programs. By the end of this unit, students will be able to write Java programs that use decision-making and repetition to solve problems.
Unit Objectives
By the end of this unit, students will be able to:
- Declare and initialize variables of different data types.
- Use arithmetic, relational, and logical operators in Java.
- Write programs using conditional statements (
if
,if-else
,switch
). - Implement loops (
for
,while
,do-while
) for repetition. - Debug and troubleshoot programs with logical and runtime errors.
- Solve real-world problems using basic programming constructs.
Unit Duration
- 3 Weeks (15 Class Periods)
Unit Outline
Week 1: Variables, Data Types, and Operators
Day 1: Variables and Data Types
- Topics:
- Declaring and initializing variables
- Primitive data types:
int
,double
,char
,boolean
- Variable naming conventions
- Activities:
- Code walkthrough: Examples of variable declarations
- Hands-on coding: Write a program that declares variables for a person's name, age, and GPA, then prints them.
- Homework:
- Practice: Write a program that calculates the perimeter of a rectangle using variables for length and width.
Day 2: Arithmetic and Relational Operators
- Topics:
- Arithmetic operators:
+
,-
,*
,/
,%
- Relational operators:
==
,!=
,<
,>
,<=
,>=
- Arithmetic operators:
- Activities:
- Coding exercises: Write programs that calculate simple mathematical operations.
- Debugging activity: Fix errors in a program using relational operators.
- Homework:
- Write a program that calculates the average of three test scores.
Day 3: Logical Operators and Expressions
- Topics:
- Logical operators:
&&
,||
,!
- Combining relational and logical operators in expressions
- Logical operators:
- Activities:
- Group activity: Write logical expressions to determine if a student passes or fails based on multiple conditions.
- Coding exercise: Write a program that checks if a number is within a specific range.
- Homework:
- Practice: Write a program that determines if a person is eligible to vote based on age and citizenship.
Week 2: Conditional Statements
Day 4: if
and if-else
Statements
- Topics:
- Syntax of
if
andif-else
statements - Writing programs with decision-making logic
- Syntax of
- Activities:
- Hands-on coding: Write a program that determines if a number is positive, negative, or zero.
- Debugging exercise: Fix errors in a program using
if-else
statements.
- Homework:
- Write a program that calculates the grade (A, B, C, etc.) based on a student's score.
Day 5: Nested if
Statements
- Topics:
- Using nested
if
statements for complex decision-making - Avoiding excessive nesting with logical operators
- Using nested
- Activities:
- Coding exercise: Write a program that determines the type of a triangle (equilateral, isosceles, scalene) based on side lengths.
- Group discussion: Best practices for writing readable conditional statements.
- Homework:
- Write a program that determines if a year is a leap year.
Day 6: switch
Statements
- Topics:
- Syntax of
switch
statements - Using
break
anddefault
inswitch
cases - Comparing
switch
withif-else
- Syntax of
- Activities:
- Code walkthrough: Example of a
switch
statement for a menu-driven program. - Hands-on coding: Write a program that outputs the day of the week based on a number input (1 = Monday, 2 = Tuesday, etc.).
- Code walkthrough: Example of a
- Homework:
- Write a program that outputs the name of a month based on a number input (1 = January, 2 = February, etc.).
Week 3: Loops and Debugging
Day 7: for
Loops
- Topics:
- Syntax of
for
loops - Iterating through a range of numbers
- Syntax of
- Activities:
- Coding exercise: Write a program that prints the first 10 multiples of a number.
- Debugging activity: Fix errors in a program using
for
loops.
- Homework:
- Write a program that calculates the factorial of a number using a
for
loop.
- Write a program that calculates the factorial of a number using a
Day 8: while
and do-while
Loops
- Topics:
- Syntax of
while
anddo-while
loops - Differences between
while
anddo-while
- Infinite loops and how to avoid them
- Syntax of
- Activities:
- Coding exercise: Write a program that keeps asking the user for input until they enter a specific value.
- Group activity: Discuss the pros and cons of
while
vs.do-while
.
- Homework:
- Write a program that calculates the sum of all even numbers between 1 and 100 using a
while
loop.
- Write a program that calculates the sum of all even numbers between 1 and 100 using a
Day 9: Nested Loops
- Topics:
- Writing loops within loops
- Applications of nested loops (e.g., printing patterns)
- Activities:
- Coding exercise: Write a program that prints a multiplication table.
- Challenge: Write a program that prints a pyramid pattern using
*
.
- Homework:
- Practice: Write a program that calculates the sum of elements in a 2D array (basic introduction to arrays).
Day 10: Debugging Techniques
- Topics:
- Common errors in loops and conditionals
- Debugging strategies: reading error messages, using print statements
- Activities:
- Debugging workshop: Students debug a set of faulty programs with loops and conditionals.
- Group discussion: Share strategies for identifying and fixing errors.
- Homework:
- Reflection: Write about a debugging challenge you faced and how you solved it.
Day 11: Mini-Project – Simple Calculator
- Objective:
- Create a program that acts as a basic calculator, allowing the user to perform addition, subtraction, multiplication, and division.
- Activities:
- Students work independently to write and test their programs.
- Peer review: Swap programs with a partner and test each other's code.
- Homework:
- Finalize the mini-project and submit it.
Day 12: Review and Assessment
- Topics:
- Review of key concepts: variables, operators, conditionals, loops
- Activities:
- Kahoot quiz: Review questions on the unit topics.
- Written assessment: Short-answer questions and a simple coding problem.
- Homework:
- Prepare for the next unit: Read Invitation to Computer Science, Chapter 5 (Object-Oriented Paradigms).
Day 13: Reflection and Extension
- Topics:
- Reflecting on the unit and connecting to future topics
- Activities:
- Class discussion: "What was the most challenging part of this unit?"
- Extension activity: Research a real-world application of loops or conditionals and share in the next class.
- Homework:
- Write a reflection: "How can you use loops and conditionals to solve real-world problems?"
Assessments
- Formative Assessments:
- Class discussions and participation
- Homework assignments
- Debugging exercises
- Summative Assessments:
- Mini-project: Simple Calculator
- Written assessment: Variables, operators, conditionals, and loops
Materials and Resources
- Textbook: Invitation to Computer Science by G. Michael Schneider and Judith L. Gersting
- IDE: IntelliJ IDEA, Eclipse, or BlueJ
- Online resources:
- Oracle Java Documentation
- Coding practice websites (e.g., Replit, Codecademy)
- Videos:
- "Java Basics: Variables and Data Types" (YouTube)
- "Loops in Java Explained" (YouTube)
Differentiation Strategies
- For Advanced Learners:
- Provide additional challenges, such as writing programs with nested conditionals and loops.
- For Struggling Learners:
- Offer one-on-one support during coding exercises.
- Provide partially completed code templates to guide their learning.
- For Visual Learners:
- Use flowcharts to explain the logic of conditionals and loops.
- For Hands-On Learners:
- Emphasize coding exercises and debugging workshops.