mdinfotech.net  



Course and Lab Introduction
  • course introduction on mdinfotech
  • expectations
  • the backup talk
  • logging in
  • H drive vs C drive vs Student_Collab Drive (SAVE EVERY PROGRAM YOU WRITE ON THE H (Host) DRIVE.)
  • Printing
  • evaluation
Types of assessments:
  1. 100/80/60 Quizzes: short programming problems given at the beginning of class. They are used to assess if your programming skills are where they should be.
    • 60% - indicates your programming skills are not where they should be and will require a meeting with the teacher to discuss what you can do differently to succeed
    • 80% indicates your programming skills are close to what they should be you may need to adjust the way you approach your learning in this class
    • 100% indicates you have the correct solution and that your programming skills are where they should be.
    If you are not getting 100 on these quizzes, read How to be Successful in a Programming Class on the course home page.
  2. There are a number of small programming exercises to be handed in and a few larger ones.
  3. There are two Java Exams worth a total of 30% your final mark.
  4. Term Project: a large scale problem that will take about 3 weeks to solve, in a group. Problem complexity will try to be matched with programmer skill.
Get on Google Classroom

Do Programmers Actually Need Touch Typing?
  • Test your code typing speed Typing.io.

  • Important Dates
    1. Canadian Computing Contest - Wed Feb 19 12-3
    2. Spring Break - March 15 to March 30
    3. APCS Exam - Wednesday May 7

    Resources

    A discussion on academic integrity and the importance of learning to code without relying on AI. There is value of building a strong foundation in programming.

    Notes for Ms. Wear
    Lesson: Resources
    1. Compile and Run Hello World in Class
    2. Create a new project for each program
    3. Using the Eclispse Debugger: lesson in class (Ms Wear's notes), not accessible to you). If you need more watch: Better Debugging with Eclipse Debugger Tutorial
    To Install Eclipse at HOME:
    • Download Eclipse Installer, and follow the directions on the download page. You want to install the version "Eclipse for Java Developers".
    • Test Hello World.
    Prepartion Timeline

    For the first 1-2 weeks, we will focus on CCC preparation to sharpen your programming skills, which will also help with AP Computer Science.

    How to Register for the CCC (Wednesday, Feb 19, 12-3 PM):
    1. Read What's on the CCC?
    2. Join my CCC Google Classroom.
    3. Register here: https://cccgrader.com/register.php). Use the school number : 091301202
    4. Get my approval for your registration.
    5. Practice solving past CCC problems here.
    6. Ensure you can submit solutions correctly. Some students in the past received a zero despite correct answers because they didn't follow submission instructions.
    Important CCC Rules & Guidelines
    1. Read the CCC Rules carefully.
    2. All your classes must be called Main for the online grader to mark your work correctly.
    Junior Contest Preparation:
    If you are writing the Junior contest focus on:
    • Use BufferedReader for input (taught in class)
    • Practicing J3/J4 problems more than J1/J2.
    • Reviewing String manipulation (often tested in J3).
    • Understanding 2D Arrays (common in J5)
    • Learning Breadth First Search, which past students found helpful for J5 questions.
    Senior Contest Preparation:
    If you are writing the Senior contest focus on:
    • BufferedReader is an efficient way to read input compared to Scanner, especially for large inputs.
    • It reads input as a string, so conversion is needed for numerical data.
    Code Example 1: Basic Input (String Input)
    import java.io.*;
    
    public class BufferedReaderExample {
        public static void main(String<> args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter your name: ");
            String name = br.readLine();
            System.out.println("Hello, " + name + "!");
        }
    }                
                    
    Code Example 2: Integer Input (String Input)
    import java.io.*;
    
    public class BufferedReaderInteger {
        public static void main(String<> args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter a number: ");
            int number = Integer.parseInt(br.readLine());
            System.out.println("You entered: " + number);
        }
    }                
                    

    Note: use Double.parseDouble() to deal with decimal values.

    Code Example 3: Reading Multiple Values Using StringTokenizer
      
    import java.io.*;
    import java.util.StringTokenizer;
    
    public class BufferedReaderMultiInput {
        public static void main(String<> args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter two numbers separated by space: ");
            StringTokenizer st = new StringTokenizer(br.readLine());
            int num1 = Integer.parseInt(st.nextToken());
            int num2 = Integer.parseInt(st.nextToken());
            System.out.println("Sum: " + (num1 + num2));
        }
    }
    
    Practice Exercise

    Write a program that asks for a user's full name and age, then prints:

    "Your name is  and you are  years old."
    
    Modify the program to read three space-separated numbers and print their average.

    Additional Resources
    1. Using the online grader. Do some J1 and J2's
    2. Lesson J3
    3. Lesson J4
    4. Lesson J5
    5. Practice - pairs programming
    6. Practice - individual
    Ms. Wear's notes - you won't have access to this

    Objective

    Essential string manipulation techniques commonly needed for CCC J3 problems include:

    • Splitting strings
    • Substring extraction
    • Character iteration
    • String replacement
    • Reversing and formatting strings

    Use the String API and StringBuilder API to learn more about the following examples.


    Common String Manipulation Techniques

    A. Splitting Strings

    1. Use case: When input consists of multiple words/numbers in a single line.
    2. How: String.split() or StringTokenizer
    3. Example Problem: "apple banana cherry" → Convert into an array of words.

    split() Example:

    import java.util.*;
    
    public class SplitExample {
        public static void main(String [] args) {
            String input = "apple banana cherry";
            String [] words = input.split(" ");
    
            System.out.println(Arrays.toString(words)); // [apple, banana, cherry]
        }
    }
    

    Key Point: .split(" ") breaks a string into parts using a space delimiter. This method is fine for small test cases (J1,J2). Use StringTokenizer for problems with large test cases (J3 and up).


    B. Extracting Substrings

    1. Use case: When you need to analyze part of a string (e.g., first and last character).
    2. Example Problem: Given "abcdef", extract "abc" and "def".

    Code Example:

    public class SubstringExample {
        public static void main(String [] args) {
            String text = "abcdef";
            String firstHalf = text.substring(0, 3); // "abc"
            String secondHalf = text.substring(3);  // "def"
    
            System.out.println(firstHalf + " | " + secondHalf); // abc | def
        }
    }
    

    Key Point: substring(start, end) extracts part of a string.


    C. Iterating Over Characters

    1. Use case: When analyzing each character in a string (e.g., checking vowels, counting letters).
    2. Example Problem: Count the number of vowels in "hello world".

    Code Example:

    public class CharIterationExample {
        public static void main(String [] args) {
            String text = "hello world";
            int vowelCount = 0;
            String vowels = "aeiou";
    
            for (char c : text.toCharArray()) {
                if (vowels.indexOf(c) != -1) {
                    vowelCount++;
                }
            }
    
            System.out.println("Vowel count: " + vowelCount); // Output: 3
        }
    }
    

    Key Point: .toCharArray() helps iterate through a string efficiently.


    D. Replacing Parts of a String

    1. Use case: When modifying characters or words in a string.
    2. Example Problem: Replace "cat" with "dog" in "The cat sat on the mat".

    Code Example:

    public class ReplaceExample {
        public static void main(String [] args) {
            String sentence = "The cat sat on the mat.";
            String newSentence = sentence.replace("cat", "dog");
    
            System.out.println(newSentence); // The dog sat on the mat.
        }
    }
    

    Key Point: .replace(old, new) replaces all occurrences of old with new.


    E. Reversing a String

    1. Use case: When checking for palindromes or reversing order of words.
    2. Example Problem: "hello""olleh"

    Code Example:

    public class ReverseExample {
        public static void main(String [] args) {
            String text = "hello";
            String reversed = new StringBuilder(text).reverse().toString();
    
            System.out.println(reversed); // olleh
        }
    }
    

    Key Point: new StringBuilder(text).reverse().toString() efficiently reverses a string. It is especially useful when modifying a string frequently (e.g., reversing a string, building a new string dynamically). Avoid using String concatenation (+ operator) in loops because it creates new objects each time, making it inefficient.


    F. Checking If a Word Contains a Substring

    1. Use case: When checking for palindromes or reversing order of words.
    2. Example Problem: "hello""olleh"

    Code Example:

    public class ContainsSubstring {
        public static void main(String [] args) {
           String word = "hello";
           if (word.contains("ll")) {
               System.out.println("Substring found!");
           }
        }
    }
    

    Key Point: .contains() returns true if a string contains a substring.


    Applying These Skills to CCC J3 Problems

    Example CCC-Style Problem:

    Problem: Given a sentence, reverse each word while keeping the order of words the same.
    Input: "hello world"
    Output: "olleh dlrow"

    Solution:

    public class ReverseWords {
        public static void main(String [] args) {
            String sentence = "hello world";
            String [] words = sentence.split(" ");
            StringBuilder result = new StringBuilder();
    
            for (String word : words) {
                result.append(new StringBuilder(word).reverse()).append(" ");
            }
    
            System.out.println(result.toString().trim()); // olleh dlrow
        }
    }
    

    Key Concepts Used: .split(), .reverse(), .trim(), and StringBuilder.


    Practice Exercises

    1. Palindrome Checker: Write a program that checks if a given word is a palindrome (e.g., "racecar").
    2. Word Count: Count how many times a specific word appears in a sentence.
    3. Replace Digits: Given a string with numbers, replace each digit with # (e.g., "abc123""abc###").

    Next Steps: Try solving CCC J3 problems from previous years using these techniques!