- 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
- 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.
- There are a number of small programming exercises to be handed in and a few larger ones.
- There are two Java Exams worth a total of 30% your final mark.
- 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.
Do Programmers Actually Need Touch Typing?
Important Dates
- Canadian Computing Contest - Wed Feb 19 12-3
- Spring Break - March 15 to March 30
- APCS Exam - Wednesday May 7
Resources
- AP Classroom
- AP Computer Science A Home Page
- AP Textbook: Barron's AP Computer Science A
- Java API
- Allowed during exam: Java Quick Reference (2019)
- Forgot Java? Java For Beginners Video Tutorials
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- What is Java?
- How to program Hello World
- Ms. Wear's Slides for this Lesson. This may be review from CS 12 but is very important to remember.
- Read Hello World for an explanation of HelloWorld.java.
- Java API
- w3 Schools Java Tutorials
- Compile and Run Hello World in Class
- Watch this video to run Hello World in Eclipse: How To: Create a Simple Java Program Using Eclipse
- Create a new project for each program
- 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
- Download Eclipse Installer, and follow the directions on the download page. You want to install the version "Eclipse for Java Developers".
- Test Hello World.
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):- Read What's on the CCC?
- Join my CCC Google Classroom.
- Register here: https://cccgrader.com/register.php). Use the school number :
091301202
- Get my approval for your registration.
- Practice solving past CCC problems here.
- Ensure you can submit solutions correctly. Some students in the past received a zero despite correct answers because they didn't follow submission instructions.
- Read the CCC Rules carefully.
- All your classes must be called
Main
for the online grader to mark your work correctly.
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.
If you are writing the Senior contest focus on:
- Understanding Comparable. Ms. Wear's Comparable. Here is my solution to CCC 2020 S1 Surmising a Sprinter's Speed. Use it as an example of how to solve one of these problems with an object oriented that implements comparable and uses console input.
- Using BufferedReader instead of Scanner and String Tokenizer instead of String.split() for speed (some problems require efficient code for large test cases). Covered in class.
- Know Searches/Sorts (S1 problems)
- Past students also recommend learning:
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.
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.
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 isModify the program to read three space-separated numbers and print their average. Additional Resourcesand you are years old."
- Using the online grader. Do some J1 and J2's
- Lesson J3
- Lesson J4
- Lesson J5
- Practice - pairs programming
- Practice - individual
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
- Use case: When input consists of multiple words/numbers in a single line.
- How:
String.split()
orStringTokenizer
- 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
- Use case: When you need to analyze part of a string (e.g., first and last character).
- 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
- Use case: When analyzing each character in a string (e.g., checking vowels, counting letters).
- 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
- Use case: When modifying characters or words in a string.
- 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
- Use case: When checking for palindromes or reversing order of words.
- 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
- Use case: When checking for palindromes or reversing order of words.
- 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
- Palindrome Checker: Write a program that checks if a given word is a palindrome (e.g.,
"racecar"
). - Word Count: Count how many times a specific word appears in a sentence.
- 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!