CS20 AP 2017/18
Block 2 & 3 - Semester s
Computer Science 20 Advanced Placement Complete Lesson Plan
Notes to Teachers
Class 81, Friday. June 14 - LAST DAY
Day 12 of GUI
Create a GUIReadMe.txt file in the project folder
Discuss CS30 AP
Class 79, Wednesday. June 12
Day 10 of GUI
Go over the Rubric
Class 78, Tues. June 12
Day 9 of GUI
Go over project marking scheme, focusing on final 20%
Discuss first steps of project
Class 77, Mon. June 11
Day 8 of GUI
Cam McDonnel from Macewan - 10:45ish
Planning doc - must be done today
Class 75 & 76, Thurs & Friday
Day 6 & 7 of GUI Unit
Introduce the project thoroughly
Finish up GUI 2-4 and start project
Class 74, Wednesday June 6
Day 5 of GUI Unit
8 Classes left in the course
Prep: get ComboboxModel code
B3 - Mark BeastMaster and Simple Calculator
Work time on GUI 1-3
Teacher Conference Example Extended
Add a new JFrame that lets them ‘login’ as a teacher or as a conference organizer
Add a conference organizer JFrame
JCompboBox User Code
ComboBox.setModel( new javax.swing.DefaultComboBoxModel(carsArray) )
Set up the array as a global variable.
References an arrayList in another class. Set Model requires a string array.
String[] carsArray = new String[CarMain.cars.size()];
In constructor, before the initComponents()
for(int i=0; i<carsArray.length; i++){
carsArray[i] = CarMain.cars.get(i).carName;
}
Class 73, Tuesday June 5
Day 4 of GUI Unit
9 Classes left in the course
Prep: get ComboboxModel code
B3 - Mark BeastMaster
Work time on GUI 1-3
Class 72, Monday June 4
Day 3ish of GUI Unit
Marking Notes
Discuss marking
GUI Review - Walk them through what we have done so far. Students that do not have these example packages should copy them. We will use the TeacherConference example tomorrow.
GUI Lesson - Creating our own GUI from scratch
Introduce GUI 3 - Quiz Program?
package GUI_Notepad;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class NotePad_GUI extends JFrame implements ActionListener {
private JPanel innerWindow = new JPanel();
private JButton read = new JButton("Load File");
private JButton write = new JButton("Save File");
private JTextField fileField = new JTextField(20);
private JTextArea textArea = new JTextArea(40,20);
private JLabel label = new JLabel("File name:");
public NotePad_GUI() {
super("Couprie's Block 4 Notepad Extravaganza");
//this.add(innerWindow);
innerWindow.setLayout( new GridLayout(2,2,1,1) );
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add("North",innerWindow);
this.getContentPane().add( new JScrollPane(textArea) );
this.getContentPane().add( "Center",textArea);
innerWindow.add(read);
innerWindow.add(write);
innerWindow.add(label);
innerWindow.add(fileField);
//innerWindow.add(textArea);
read.addActionListener(this);
write.addActionListener(this);
innerWindow.setBackground(Color.magenta);
textArea.setBackground(Color.yellow);
textArea.setForeground(Color.BLUE);
Font font = new Font("ravie",Font.PLAIN, 20);
textArea.setFont(font);
}
private void readTextFile(JTextArea textArea, String fileName) {
try {
BufferedReader inStream = new BufferedReader(new FileReader(fileName)); // Open the stream
String line = inStream.readLine(); // Read one line
while (line != null) { // While more text
textArea.append(line + "\n"); // textArea a line
line = inStream.readLine(); // Read next line
}
inStream.close(); // Close the stream
} catch (FileNotFoundException e) {
textArea.setText("IOERROR: File NOT Found: " + fileName + "\n");
e.printStackTrace();
} catch (IOException e) {
textArea.setText("IOERROR: " + e.getMessage() + "\n");
e.printStackTrace();
}
} // end readTextFile
//writes to a text file. Netbeans will look for it at the Project Folder level.
private void writeTextFile(JTextArea textArea, String fileName) {
try {
FileWriter outStream = new FileWriter(fileName);
outStream.write(textArea.getText());
outStream.close();
} catch (IOException e) {
textArea.setText("IOERROR: " + e.getMessage() + "\n");
e.printStackTrace();
}
} // end writeTextFile()
//watches the button and waits until it is clicked
public void actionPerformed(ActionEvent evt) {
String fileName = fileField.getText();
if (evt.getSource() == read) {
textArea.setText("");
readTextFile(textArea, fileName);
} else {
writeTextFile(textArea, fileName);
}
}//end actionPerformed()
}
Main
Notepad_GUI window = new Notepad_GUI();
window.setSize(400, 200);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Class 71, Friday June 1
Day 19 of OOP
Next year - change mileage calculation to Miles per Gallon, it is just easier to understand.
No Help Assignment
Class 70, Thursday, May 31 (with sub)
Day 18 of OOP
Work time with the following priorities:
Finish Database, including the Files extension
First 2 GUI assignments
Class 69, Wednesday, May 30
Day 17b of OOP
GUI Lesson 3 - Conference Sign Up Form
Work time on Database
Discuss tomorrow’s tasks while I am away
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
name = jTextField1.getText();
years = jSlider1.getValue();
onThurs = thursBox.isSelected();
onFri = friBox.isSelected();
district = (String)jComboBox1.getSelectedItem();
if(elementary.isSelected()){
gradeLevel = "Elementary";
} else if (junior.isSelected()){
gradeLevel = "Junior High";
} else {
gradeLevel = "High School";
}
jTextArea1.setText("");
jTextArea1.append(name + "\n" + years + "\n");
jTextArea1.append("Thursday: " + onThurs + " Friday: " + onFri + "\n");
jTextArea1.append(gradeLevel + "\n");
jTextArea1.append(district);
confirmPanel.setVisible(true);
}
private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {
ConferenceMain.attendeeList.add(new Teacher(name,years,onThurs,onFri,gradeLevel,district));
}
public class Teacher {
public String name;
public int years;
public boolean onThurs;
public boolean onFri;
public String gradeLevel;
public String district;
public Teacher(String n, int y, boolean t, boolean f, String g, String d){
name = n;
years = y;
onThurs =t;
onFri = f;
gradeLevel = g;
district = d;
}
}
Last year’s Example - Hockey Pool
Version 1
Slider updates the total box directly
int bet = betSlider.getValue();
costBox.setText("$" + bet);
Version 2
int numEntries = 0;
if(jCheckBox1.isSelected()){
System.out.println("chose Edmonton");
numEntries++;
}
bet*=numEntries;
Version 3
jPanel2.setVisible(false);
Class 68 - Tuesday, May 29
Day 17a of OOP
Post encryption sample code
Review GUI from Friday
Create a GUI Reference Google Doc - see next page
Encryption Example
Work time on Database
Challenge for those done everything. Look up the Vigenere cipher. Use a 2D array and see if you can implement it into the Encryption GUI example.
Mark BeastMaster at the end of block 3?
Wednesday GUI Plans
Later
GUI Reference (Block 2)
Top Level Containers
JFrame
JOptionPane - pop-up window
JApplet - a container for a java program in a html file
Other Containers
Panel - often turned on or off in the program
Components
Label - used for text or images label.setText()
Button
TextArea - for multiple lines of text textArea.setText() textArea.append()
TextField - for single lines of text
Slider - slider.getValue()
Class 67 - Monday, May 28
Day 16 of OOP
Reminder about the No Help Assignment - now on Friday as I will be away on Thursday (for block 2 and part of block 3)
In Class Marking
Work time on Beast Master and Database
Class 66 - Friday, May 25
Day 15 of OOP
Class 64 was at the Iverson Field Trip
Announcement:
In Class Marking
Intro to GUI with the Netbeans Swing GUI builder (30ish minutes)
GUI Example 1 - Intro to the JFrame
GUI Example 2 - Create the basic JFrame Calculator from the tutorial:
Class 65 - Thursday, May 24
Day 14 of OOP
Class 64 was at the Iverson Field Trip
Notes: How to plan your own instance class vs main method
Review the Actors File example. Have them build the LoadFile line in 3 steps:
Work time on Beast Master
In Class Marking
Introduce Database assignment
Class 63 - Thursday, May 17
Day 13 of OOP
Confirm Iverson Contest Details
Talk to Rushi about date change for staff meeting
Block 2
If not finished Assign 3 Geometry in 15 minutes, you are to skip the final 20% and move on. I will not mark it until Monday so you can finish it for homework or at lunch.
Demo Object Casting and using a Temp variable with the Bike A Thon demo.
Work on BeastMaster
Block 3
Demo Object Casting and using a Temp variable with the Bike A Thon demo.
Discuss but do not demo using InstanceOf
Work on Geometry and BeastMaster
Mark Bank Account
Class 63 - Wednesday, May 16
Day 12 of OOP
Find out who has not turned in their Iverson Forms
Lots of block 2 students away
Finish Spare Parts
Class 62 - Tuesday, May 15
Day 11 of OOP
Find out who has not turned in their Iverson Forms
Block 2 - Mark Console Games and Bank Account
Block 3 - Need more time and an extra catch up day on Wednesday during the movie
Mark Data structures project
For block 2 students, add the Beastmaster assignment to their list.
Class 61 - Monday, May 14
Day 10 of OOP
Note: Block 3 ‘lost’ Friday’s class
Register for Iverson today!!!!!!
Block 3 Only
CSV Files
Prep: set up the Actor class and get them to copy it first
Lesson on Using CSV files
TextFiles Example - Instance Class
Change this to an Actor class with name, sales, isPro, role
public class Student {
public String name;
public double feesPaid;
public int grade;
public String position;
public Student(String n, double f, int g, String p) {
name = n;
feesPaid = f;
grade = g;
position = p;
}
}
TextFiles Example - Main Class
import java.util.ArrayList;
import java.io.*;
public class TextFilesMain {
public static void main(String[] args) {
ArrayList<Student> allStudents = new ArrayList();
loadFile("studentfile.txt", allStudents);
for (int i = 0; i < allStudents.size(); i++) {
System.out.println(allStudents.get(i).name + " $" + allStudents.get(i).feesPaid);
}
allStudents.get(0).feesPaid += 100;
allStudents.add(new Student("Dani", 50, 12, "Chucker"));
saveFile("studentfile.txt", allStudents);
}//end main
public static void saveFile(String filename, ArrayList<Student> tempList) {
try {
PrintWriter file = new PrintWriter(new FileWriter(filename));
for (int i = 0; i < tempList.size(); i++) {
//the next lines are customized for whatever data you are getting.
String toSave = "";
toSave += tempList.get(i).name;
toSave += "," + tempList.get(i).feesPaid;
toSave += "," + tempList.get(i).grade;
toSave += "," + tempList.get(i).position;
file.println(toSave);
}
file.close();
} catch (IOException ex) {
System.out.println(ex.toString());
}
}//end
public static void loadFile(String filename, ArrayList tempList) {
String temp = "";
try {
BufferedReader file = new BufferedReader(new FileReader(filename));
while (file.ready()) {
temp = file.readLine();
String tempArray[] = temp.split(",");
//the next line is customized for whatever class you are creating.
//Here we create a new STUDENT so there are 4 variables
tempList.add(new Student(tempArray[0], Double.parseDouble(tempArray[1]), Integer.parseInt(tempArray[2]), tempArray[3]));
}
} catch (IOException e) {
System.out.println(e);
}
}//end loadFile
}//end class
Class 60 - Friday, May 11
Day 9 of OOP
Add to Notes - Visibility Indicators
Bike-A-Thon extension - how to add a Students class
Work time up to Geometry
Mark Console Games and perhaps Bank Account
New assignment needed with the Bike-A-Thon example
Class 59 - Thursday, May 10
Day 8 of OOP
Remind block 2 that we are in 207 on Friday.
Notes:
B2 - many students are still finishing up Console Games at the end of Wednesday’s class.
Discuss before adding: How would you automatically generate a client ID number so that it increases each time?
public static int counter = 100000;
clientNum = LawnMain.counter;
LawnMain.counter++;
Constructor Practice
Work time on Bank Account and Console Games
Class 58 - Wednesday, May 9
Day 7 of OOP
Release the entire assignment folder
Add the lawnclient code to a Google Doc
Have students sign up for the Iverson exam
Finish Lawn Mowing Example
Assignment 3 Bank Account
Class 57 - Tuesday, May 8
Day 6 of OOP
Note: In Block 3, 15 students are absent
Lawn Mower Major Example
Watch first half of Spare Parts (available via EPL)
Block 2 - ended at 56:46
Lawn Mower Example - Private and Public
LawnMowerClients
package Ex_LawnMowing;
public class Client {
private String name;
private String address;
private int lawnSize; //in square meters
private boolean hasDog;
private double outstandingFees;
public Client (String n, String a, int s, boolean dog){
name = n;
address = a;
lawnSize = s;
hasDog = dog;
outstandingFees = 0;
}
public void mowLawn(){
double charge = lawnSize * 0.25;
if( hasDog ){
charge += 10;
}
outstandingFees+= charge;
printBill(charge);
}//mow lawn
public void printBill(double c){
System.out.println(name + " your charge for today is $" + c);
System.out.println("Your total fees owing are $" + outstandingFees);
}
public String getName(){
return name;
}
public void processPayment(double amount){
outstandingFees -= amount;
System.out.println("The amount still owing is $" + outstandingFees);
}
public void overdue(){
outstandingFees *= 1.10;
System.out.println(name + " your amount still owing is $" + outstandingFees);
if( outstandingFees > 60 && hasDog){
hasDog = false;
}
}//overdue
}
Lawn Mowing Main
package Ex_LawnMowing;
import java.util.ArrayList;
import java.util.Scanner;
public class LawnMain {
static ArrayList<Client> allClients = new ArrayList();
static Scanner numscan = new Scanner(System.in);
static Scanner wordscan = new Scanner(System.in);
public static void main(String[] args) {
allClients.add(new Client("Mr. Couprie", "555 Maple Lane", 50, false));
allClients.add(new Client("Mr. Pendlebury", "8900 86 Ave", 75, true));
allClients.add(new Client("Mr. Van Ginhoven", "22 173 Street", 50, false));
allClients.add(new Client("Mrs. Gerun", "5200 86 Ave", 100, true));
while (true) {
System.out.println("1. Mow Lawn");
System.out.println("2. Process Payment");
System.out.println("3. exit");
int choice = numscan.nextInt();
if (choice == 3) {
break;
} else if (choice == 1) {
mow();
} else if (choice == 2) {
pay();
}
}
}//end main
public static void mow(){
allClients.get( searchByName() ).mowLawn();
}
public static void pay(){
int index = searchByName();
System.out.println("How much is being paid?");
double amount = numscan.nextDouble();
allClients.get(index).processPayment(amount);
}
public static int searchByName() {
System.out.println("Which client?");
String name = wordscan.nextLine();
for(int i=0; i<allClients.size(); i++){
if ( name.equalsIgnoreCase( allClients.get(i).getName() ) ){
return i;
}
}
return -1;
}//end search
}//end lawnMain
Class 56 - Monday, May 7
Day 5 of OOP
Post OOP 1
Have students sign up for the Iverson exam
Worktime on OOP 1.
___ visits at 10:55
Class 55 - Friday, May 4
Day 4 of OOP
Post OOP 1
Announce Guest Speaker for Monday -___ of ScopeAR
Discuss Field Trip - and update the form
StoreProducts Review example
Finish ArrayList Playlist up to ?, start OOP 1
Run through the jungle: https://www.youtube.com/watch?v=eOgwuZE_jp0
Old man down the road: https://www.youtube.com/watch?v=JbSGMRZsN4Q
Store Example Class
package StoreExample;
public class Product {
//instance variables
public String type;
public String brand;
public double price;
public int numInStock;
//constructor methods
public Product( String t, String b, double p ){
type = t;
brand = b;
price = p;
numInStock = 0;
gstExempt = false;
}
public Product( String t, String b, double p, int s ){
type = t;
brand = b;
price = p;
numInStock = s;
gstExempt = false;
}
public void printProduct(){
System.out.println("Product Type: " + type + " Brand: " + brand);
System.out.println("$" + price);
System.out.println("In stock: " + numInStock);
System.out.println("GST Exempt?: " + gstExempt);
System.out.println();
}
public void sellProduct(int numSold){
numInStock -= numSold;
}
public void receiveProduct(int numReceived){
numInStock += numReceived;
}
}//end product
Class 54 - Thursday, May 3
Day 3 of OOP
Reminder: AP students will skip assignment 1
Review Notes from Day 1
Notes on Types of Non-Instance Classes (AP student in mind)
Add to OOP Notes - Instance Classes
Parts of an Instance Class
BikeAThonTeams Brainstorm
Bike-a-thon v1 Major example
Extra Activity - Ted talk on SpaceX
package BikeAThon;
import java.util.ArrayList;
public class BikeTeam {
//instance variables
public String teamName;
public String captain;
public double totalRaised;
public boolean minRaised;
public ArrayList<String> studentList = new ArrayList();
//constructor method
public BikeTeam(String t, String c){
teamName = t;
captain = c;
totalRaised = 0;
minRaised = false;
studentList.add(c);
}
//instance methods
public void printAll(){
System.out.println("Team Name: " + teamName);
System.out.println("Captain Name: " + captain);
System.out.println("Total Raised: " + totalRaised);
System.out.print("Team Members: ");
for(int i=0; i<studentList.size(); i++){
System.out.print(studentList.get(i) + ", ");
}
System.out.println();
System.out.println();
}
public void addStudent(String name){
studentList.add(name);
}
public void addDonation(double amount){
totalRaised += amount;
}
}//end bikeTeam
Class 53 - Wednesday, May 2
Introduce ArrayLists with Strings
Alter yesterday’s monster class to use an ArrayList of Monsters
Finish Arrays Project
ArrayList<Monster> monsterList = new ArrayList();
monsterList.add(m2);
monsterList.add(m1);
monsterList.add( new Monster("ghost", false, 1) );
monsterList.add( new Monster("vampire", true, 4) );
monsterList.add( new Monster("ghost", true, 1) );
monsterList.add( new Monster("mummy", true, 5) );
for(int i=0; i<monsterList.size(); i++){
if ( monsterList.get(i).getEvil() ){
System.out.println("You meet a mean " + monsterList.get(i).getType());
}else {
System.out.println("You meet a friendly " + monsterList.get(i).getType());
}
Class 52 - Tuesday, May 1
Day 1 of OOP
First OOP assignment - console games - is too much like the later databasey assignments. Changes its direction to be more like bank account where methods update a variable.
Introduction to the Object Oriented Programming Credit
Create a notes doc
Introduction to the OOP Credit with the Monster Class
Need new activity for students done everything
Block 2 - told they get 40 minutes on Tuesday to finish and/or work on AI and/or work on this new activity
Block 3 - Same as above
Those that are done continue to make a game with the Monster Class
package Ex1_Monster;
import java.util.ArrayList;
import java.util.Scanner;
public class E1_Main {
public static void main(String[] args) {
Scanner wordscan = new Scanner(System.in);
Monster m1 = new Monster("zombie", true, 2);
Monster m2 = new Monster("werewolf", true, 4);
System.out.println( m1.getType() );
System.out.println( m1.getHealth() );
System.out.println( m1.getDescription() );
int playerhealth = 100;
int playerdamage = 10;
System.out.println("You are walking through an abandoned amusement park");
System.out.println("Suddenly you come upon a " + m1.getDescription() + " "+ m1.getType());
while( playerhealth > 0 && m1.getHealth()>0 ){
playerhealth -= m1.attack();
m1.defend(playerdamage*2);
wordscan.nextLine();
}
if(playerhealth<1){
System.out.println("You lose game over");
return;
}
}
}//end main
}//Ex1_Main
public class Monster {
private String type;
private boolean isEvil;
private int strength;//between 5 and 10
private int health;
private String description;
//************* constructor methods **************************
public Monster(String t, boolean e, int s){
type = t;
isEvil = e;
strength = s+5;//parameter is a 1 to 5 value
health = 100;
String[]sizes = {"small","big","enormous"};
String[]colors = {"green","blue","violet"};
String[]look= {"ugly","polkadotted","furry"};
description = sizes[(int)(Math.random()*3)] + ", " + colors[(int)(Math.random()*3)]+", " + look[(int)(Math.random()*3)] ;
}
//********** getter methods ***********************
public String getType(){
return type;
}//getType
public boolean getEvil(){
return isEvil;
}//getEvil
public int getHealth(){
return health;
}//getHealth
public String getDescription(){
return description;
}//getType
//********** other methods **********************
public int attack(){
//when the monster is attacking
//returns the amount of damage done to the player
int multiplier = (int)(Math.random()*5 +1);
return strength * multiplier;
}//end attack
public int defend(int damage){
//when the monster is defending
//returns the current health of the monster
health-=damage;
if(health<0){
health = 0;
}
return health;
}//end defend
}
Class 51 - Friday, April 27
Class 16 of Data Structures
Exam today
Ted 2018 Major Interview - COO of Space X Gwynne Shotwell (20:00)
Class 50 - Thursday, April 26
Class 15 of Data Structures
Prompt review for exam by coping these questions one at a time into the agenda:
Block 2 has survey for 20 minutes
Finish project
Class 49 - Wednesday, April 25
Class 14 of Data Structures
Prompt review for exam by coping these questions one at a time into the agenda:
Work time on project
Mark Coffee counter in class
Class 48 - Tuesday, April 24
Class 13 of Data Structures
Note: Block 3 has a sub
Work time on Wrap Up Project
Class 47 - Monday, April 23
Class 12 of Data Structures
Formally announce Data Structures Exam for Thursday
Block 3 - Needs full tictactoe example
Discuss tic-tac-toe solution to help with final project
Work time on Wrap Up Project
Class 46 - Friday, April 20
Class 12 of Data Structures
Jeffery Hui - A few more questions on Roles will get you to 80%
Introduce Arrays Wrap Up project
Mark Bike a Thon and Translator
Class 45 - Thursday, April 19 - With sub
Class 11 of Data Structures
Class 44 - Wednesday, April 18 - With Sub
Class 10 of Data Structures
Class 43 - Tuesday, April 17 - Block 2 Only
Block 3 has external module work
Class 9 of Data Structures
Discuss marking
File Chooser?
Approach individual students
2D Arrays Quick review
2D Array Lesson 2 - Varying length rows
Pass by reference lesson
Work time on Translator and Coffee Counter
Introduce the 2D array project
import java.util.Scanner;
public class Ex7_TicTacToe {
public static void main(String[] args) {
Scanner wordscan= new Scanner(System.in);
String[][] tictactoe = new String[3][3];
setupBoard(tictactoe);
//complete setupBoard function after printBoard
//discuss Pass by Reference
printBoard(tictactoe);
tictactoe[0][1] = "X";
printBoard(tictactoe);//run between plays
tictactoe[1][1] = "O";
printBoard(tictactoe);
}//end main
public static void checkWinner(String[][] tictactoe){
//use a for loop to check if a row is a winner
for(int i=0; i<tictactoe.length; i++){
if( tictactoe[i][0].equals(tictactoe[i][1]) ){
System.out.println("We have winner with " + tictactoe[i][0]);
}
}
//use a for loop to check columns
}
public static void printBoard(String[][] tictactoe){
for(int i=0; i<tictactoe.length; i++){
for(int j=0; j<tictactoe[i].length; j++){
System.out.print(tictactoe[i][j] + " | " );
}
System.out.println();
}
System.out.println(); //otherwise successive prints run together.
}//end printBoard
public static void setupBoard(String[][] tictactoe){
for(int i=0; i<tictactoe.length; i++){
for(int j=0; j<tictactoe[i].length; j++){
tictactoe[i][j] = " ";
}
}
}//end
}//end class
Class 42 - Monday, April 16
Class 8 of Data Structures
Discuss marks:
What about using the Vigenere Cipher for 2D arrays example?
A new Soduko version of the assignment is needed. Base it on the start code is in F: drive in a project called SolutionsForMarking
2-Dimensional Arrays Part 1
Set up a 2D int array to hold up to 4 golfers and their scores
Processing 2D Arrays with For Loops
Introduce Translator and Coffee Counter
Class 41 - Friday, April 13
Class 7 of Data Structures
Catch up time
Last 50 minutes- Big Data Revolution Documentary
Class 40 - Thursday, April 12
Class 6 of Data Structures
Prep: Do we need notes for Data structures? Check exam
Linear Searching (see next page)
Challenge for those that are done early today:
Introduce assignment 5 - Translator ONLY to those that are done everything and are anxious to move on.
Announce that tomorrow will be a full work day with a possible second half video
Class 39 - Wednesday, April 11
Class 5b of Data Structures
Prep: Do we need notes for Data structures? Check exam
Files set up
Files Example 1 - Countries and Populations
Introduce assignment 4 Bike A Thon algorithms
Simple Searching
import java.util.Scanner;
public class Ex6_SimpleSearching {
static Scanner numscan = new Scanner(System.in);
static Scanner wordscan = new Scanner(System.in);
public static void main(String[] args) {
String[] names = Files.loadStringArr("nhl_last_names.txt");
int[] goals = Files.loadIntArr("nhl_goals.txt");
String[] teams = Files.loadStringArr("nhl_teams.txt");
int[] games = Files.loadIntArr("nhl_games_played.txt");
String nameToFind;
int foundIndex = -1;
System.out.println("Who do you want to search for?");
nameToFind = wordscan.nextLine();
for (int i = 0; i < names.length; i++) {
if (nameToFind.equalsIgnoreCase(names[i])) {
foundIndex = i;
break;
}
}//end for loop
if (foundIndex == -1) {
System.out.println("Player not found");
} else {
System.out.println(names[foundIndex] + goals[foundIndex] + teams[foundIndex] + games[foundIndex]);
}
//****************************************************
foundIndex = -1;
do {
System.out.println("Who do you want to trade?");
nameToFind = wordscan.nextLine();
for (int i = 0; i < names.length; i++) {
if (nameToFind.equalsIgnoreCase(names[i])) {
foundIndex = i;
break;
}
}//end for loop
} while (foundIndex == -1);
teams[foundIndex] = "Golden Coupries";
//**************************************************
String teamToFind;
foundIndex = -1;
System.out.println("What team played last night?");
teamToFind = wordscan.nextLine();
for(int i=0; i<teams.length; i++){
if(teamToFind.equalsIgnoreCase(teams[i])){
games[i]++;
foundIndex=i;
}
}
for (int i = 0; i < names.length; i++) {
System.out.println(names[foundIndex] + goals[foundIndex] + teams[foundIndex] + games[foundIndex]);
}
Files.saveFile("nhl_last_names.txt", names);
Files.saveFile("nhl_goals.txt", goals);
Files.saveFile("nhl_teams.txt", teams);
Files.saveFile("nhl_games_played.txt", games);
}//end main
}//end class
Complete Files Class
import java.io.*;
public class Files {
public static void saveFile(String filename, int[] array) {
try {
PrintWriter file = new PrintWriter(new FileWriter(filename));
for (int i = 0; i < array.length; i++) {
file.println("" + array[i]);
}
file.close();
} catch (IOException e) {
System.out.println(e);
}
}//end saveFile
public static void saveFile(String filename, double[] array) {
try {
PrintWriter file = new PrintWriter(new FileWriter(filename));
for (int i = 0; i < array.length; i++) {
file.println("" + array[i]);
}
file.close();
} catch (IOException e) {
System.out.println(e);
}
}//end saveFile
public static void saveFile(String filename, String[] array) {
try {
PrintWriter file = new PrintWriter(new FileWriter(filename));
for (int i = 0; i < array.length; i++) {
file.println("" + array[i]);
}
file.close();
} catch (IOException e) {
System.out.println(e);
}
}//end saveFile
public static String[] loadStringArr(String filename) {
String addLines = "";
try {
BufferedReader file = new BufferedReader(new FileReader(filename));
while (file.ready()) {
addLines += file.readLine() + ",";
}
} catch (IOException e) {
System.out.println(e);
}
String[] tempStringArray = addLines.split(",");
return tempStringArray;
}//end loadStringArr
public static int[] loadIntArr(String filename) {
String addLines = "";
try {
BufferedReader file = new BufferedReader(new FileReader(filename));
while (file.ready()) {
addLines += file.readLine() + ",";
}
} catch (IOException e) {
System.out.println(e);
}
String[] tempStringArray = addLines.split(",");
int[] tempIntArray = new int[tempStringArray.length];
for (int i = 0; i < tempIntArray.length; i++) {
tempIntArray[i] = Integer.parseInt(tempStringArray[i]);
}
return tempIntArray;
}//end loadIntArr
public static double[] loadDoubleArr(String filename) {
String addLines = "";
try {
BufferedReader file = new BufferedReader(new FileReader(filename));
while (file.ready()) {
addLines += file.readLine() + ",";
}
} catch (IOException e) {
System.out.println(e);
}
String[] tempStringArray = addLines.split(",");
double[] tempDoubleArray = new double[tempStringArray.length];
for (int i = 0; i < tempDoubleArray.length; i++) {
tempDoubleArray[i] = Double.parseDouble(tempStringArray[i]);
}
return tempDoubleArray;
}//end loadIntArr
}//end Files Class
Class 38 - Tuesday, April 10
Class 5a of Data Structures
Prep: Do we need notes for Data structures? Check exam
Theory Exam - mark the matching question in class? Smart Joe
Work time on assignment 2 & 3
Prepare for the text files lesson tomorrow by copying the text files, preparing the FILES code
Class 37 - Monday, April 9
Class 3 of Data Structures
Prep:Do we need notes for Data structures? Check exam
Arrays Algorithms Lesson 1 - Sum, Countif, SumIf
Introduce Assignment 3 - Guitar Store Revisited
Discuss and review for test with Crossword puzzles
public class Ex3_BasicAlgorithms {
public static void main(String[] args) {
int[] allCards = new int[13];
for(int i=0; i<allCards.length; i++){
allCards[i] = (int)(Math.random()*13 + 2);
}
//Add all the numbers in the array
int totalOfCards = 0;
for(int i=0; i<allCards.length; i++){
totalOfCards += allCards[i];
}
System.out.println("The sum of the cards is: " + totalOfCards);
//Count all the 5s in the array
int countTotal = 0;
for(int i=0; i<allCards.length; i++){
if(allCards[i] == 5){
countTotal++;
}
}
System.out.println("The number of 5s is: " + countTotal);
//SumIF
//Total points for the hand
//If the card is a 10 or higher, it is worth 10 points
//If it is less than 10, it is worth its face value
int pointsTotal = 0;
for(int i=0; i<allCards.length; i++){
if( allCards[i] >= 10){
pointsTotal += 10;
} else {
pointsTotal += allCards[i];
}
}
System.out.println("Total for your hand is: " + pointsTotal);
Set them up with this challenge but do not solve it… at least not today. Give them the For Loops. Allow them to count a 3 of a kind as 3 pairs.
printArray(allCards, true);
//Count the number of pairs in your hand
int numPairs = 0;
for(int i=0; i<allCards.length; i++){
System.out.println("Checking card #" + i);
for(int j=i+1; j<allCards.length; j++){
System.out.println(allCards[i] + " and a " + allCards[j]);
if(allCards[i] == allCards[j]){
numPairs++;
System.out.println("I found a pair.");
}
}
}
System.out.println("The number of pairs is: " + numPairs);
}//end main
public static void printArray(int[] arr, boolean across) {
if (across) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + ", ");
}
System.out.println();
} else {
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}//end printArray
}//end class
Class 36 - Friday, April 6
Class 2 of Data Structures
Check with library about printing crossword puzzles. I will send someone to collect them all.
Review concept: Why are blockchains less susceptible to hacking than traditional databases?
Print crossword puzzles
Old Kahoots?
Data Structures Example 2 - Door prize generator
Data Structures Example 2b - Door Prize Generator - with text entry
Passing Arrays to Methods
Assignment 1 marked as Complete/Incomplete
Class 35 - Thursday, April 5
Class 1A of Data Structures
Review concept: What is the most common PC operating system used in the world today? Smartphone?
Emerging Tech - Machine Learning - How Neural Networks work
20 Minutes to finish SDLC
Review with Kahoots
Start data structures
Introduce the concept of a Data Structure
Discuss Arrays as an abstraction of a cupboard
Arrays Example 1a:
Data Structures Example 1b - Door prize generator
Data Structures Example 2 - Door Prize Generator - with text entry
public class Ex1_ArraysIntro {
public static void main(String[] args) {
String[] allStudents = {"Bob", "Stu", "Diana", "Jasmine", "Snoop"};
int[] allGrades = { 10, 11, 12, 10, 12};
int[] allMarks = new int[5];
allMarks[0] = 55;
allMarks[1] = 98;
allMarks[2] = 67;
allMarks[3] = 88;
allMarks[4] = 34;
System.out.println("Marks summary");
for (int i=0; i<allStudents.length ; i++ ){
System.out.println(allStudents[i] + " " + allGrades[i] + " " + allMarks[i]);
}
allMarks[1] = -1;
allMarks[4] = -1;
System.out.println("Students with unfinished assignments");
for (int i=0; i<allStudents.length ; i++ ){
if( allMarks[i] == -1 ){
System.out.println( allStudents[i] );
}
}
// five minute challenge
// create an algorithm to change all -1s to Zeros
//then in separate reprint all names and grades
}//end main
}//end class
Class 34 - Wednesday April 4
Confirm Registration info
The Central Processing Unit (CPU): Crash Course Computer Science #7
Add to notes - neural networks, assembly languages
Make a Crossword Puzzle assignment
Class 33 - Tuesday, April 3
Review our notes and discuss the remaining concepts in the Credit:
How Memory is Built
Emerging Tech - Quantum Computer - How Does it Work (6:46)
40 Minutes to work on SDLC Assign 2
Class 32 - Friday, March 23
Cambridge Analytica/Facebook Scandal -watch the first 10 minutes or so of this video.
Priority 1 - Finish SDLC Assign 1 to the 80% mark
Priority 2 - All of SDLC Assign 2
Priority 3 - Past assignments
Class 31 - Thursday, March 22
Block 2 - Course selection info
Ray Kurzweil - Get Ready for Hybrid Thinking (9:49)
Software Development Life Cycle - Assignment 2
Class 30 - Wednesday, March 21
Encryption
Public Key Encryption - Computerphile Video 6:30;
Review Parts of the CPU from last year:
Add to Notes:
Note to Couprie: Time to look at Crash Course Computer Science instead of the following video. Possibly numbers 5-7
20s - How the CPU Works Video (20:41 minutes) https://www.youtube.com/watch?v=IkdBs21HwF4
Machine Code Temp Links
Class 29 - Tuesday, March 20
Mark Procedural Programming
Theory Notes
Block chain -
‘
SDLC Assignment 1
Class 28 - Monday, March 19
Announce and discuss the Java marking tomorrow.
Discuss the Theory Credit
Bitcoin Video - John Oliver?
Introduce the Systems Development Life Cycle with the notes file.
Discuss key tools in Analysis and Design
Extra Activity - Innovation
Where do good ideas come from - https://www.youtube.com/watch?v=NugRZGDbPFU (4:30)
Soccket video: https://www.youtube.com/watch?v=yeQ-OrkUTII (2:30)
Deam Kamen News Story http://www.cbsnews.com/news/welcome-to-dean-kamens-cool-world/ (9:30)
Systems Development Life Cycle Notes
How do you plan a major, long term project?
Two ways to implement it:
Case Study: EPSB’s Gradebook Software
Step | |
Analysis | Software only Interactions: Scheduling software, Government reporting software User group: Students, teachers, admin, parents, post secondary, government Students & parents: Check marks Teachers: Enter marks, Produce reports Admin: Enter marks, Set up classes, Produce reports |
Design | Plan java with a UML Diagram Plan timeline with a Gantt chart |
Implementation | Writing and debugging the code. |
Testing | Thorough testing needed as beta tests not possible |
Deployment &Maintenance | Train one school at each grade level Those schools pilot for 1 year All schools did training in May Full rollout in September New update when necessary |
Class 27 - Thursday, March 15
Finish Ethics
Finish Dice Game/Mastermind
Class 26 - Wednesday, March 14
Create a new Lucid Chart with CS Ethical Issues- Review the ethical issues we have seen
Ethics assignment
Class 25 - Tuesday, Mar 13
Procedural Programming test
Class 23 & 24
Work on wrap up project
Class 22 - Thursday, Mar. 8
Announce credit exam for Tuesday
Mark Olympic Champions and Theory assignment, discussing the exam as they go.
Practice-IT
Work on assignments
Tomorrow - discuss Practice-IT Self Check - numbers 3.17, 3.13, 3.15
Class 21 - Wednesday, Mar. 7
Arrays Searching Example
Saving a single variable to a text file (for high score, for example)
Class 20 - Tuesday, Mar. 6
Block 3 Only
Ethics Videos:
Walk them through the next 2 assignments:
Next up: quick intro to Arrays and ArrayLists
Class 19 - Monday, Mar. 5
(Different lessons for the two blocks)
Prep: Release remaining assignments to Classroom
Discuss Roles of OS marking
Confirm Open House attendees
Discuss remaining assignments
Block 2
Call vs declaration practice
Method call and declaration practice worked really well but needs to be continued in the second half of the credit with a second full quiz dedicated just to this once the return values have been added on.
Via an email, mark The Restaurant, Home Reno and Simple Calculator in class. Ask who is completed the theory questions too.
Introduce Olympic Champions and Casino assignments
Block 3
Block 3 Ted talk - vote on one of the more recent uploads
Ethics Videos:
Network Ethics video: http://vimeo.com/34750078
Ethics videos:
Fair trade Cellphones https://www.ted.com/talks/bandi_mbubi_demand_a_fair_trade_cell_phone (9 min)
Introduce Olympic Champions and Casino assignments
Class 18 - Wednesday, Feb. 28
(shortened class for block 2)
Arrizing Tech Issues -
Call vs declaration practice
Method call and declaration practice worked really well but needs to be continued in the second half of the credit with a second full quiz dedicated just to this once the return values have been added on.
Via an email, mark The Restaurant, Home Reno and Simple Calculator in class. Ask who is completed the theory questions too.
Block 3 Ted talk - vote on one of the more recent uploads
main () {
String todaysDate;
todaysDate = getDate();
System.out.println(“The Raptors points are” + getWins( ) * 2);
if ( checkAbsences(“Suzie”) > 6 ) {
System.out.println(“Call home”);
}
if ( isPassing(“Suzie”, 12) ){
System.out.println(“Begin next credit”);
}
myaverage =
}//end main
public static double getAverage (int assign1, int assign2, int assign3){ }
Class 17 - Tuesday, Feb. 27
Return Values Example 2: Card Game
Roles of the OS Theory Assignment
Worktime on Simple Calculator and Olympics
Discuss assignment 5 Olympics
//aka the Casino Example
public class ReturnValuesCardGame {
public static void main(String[] args) {
System.out.println("Welcome to Couprie's Casino");
String p1suit;
int p1number;
p1suit = getSuit();
p1number = getNumber();
String p2suit;
int p2number;
p2suit = getSuit();
p2number = getNumber();
String c1suit;
int c1number;
c1suit = getSuit();
c1number = getNumber();
String c2suit;
int c2number;
c2suit = getSuit();
c2number = getNumber();
System.out.println("You were dealt a " + p1number+ " of " +p1suit);
System.out.println("Your second card was a " + p2number+ " of " +p2suit);
System.out.println("The Casino was dealt a " + c1number+ " of " +c1suit);
System.out.println("The Casiono's second card was a " + c2number+ " of " +c2suit);
System.out.println();
//check the player's hand
if ( isFlush(p1suit, p2suit) ){
System.out.println("You have a flush.");
} else if ( isPair(p1number, p2number) ){
System.out.println("You have a pair.");
} else {
System.out.println("You have nothing.");
}
//check the casino's hand
if ( isFlush(c1suit, c2suit) ){
System.out.println("The Casion has a flush.");
} else if ( isPair(c1number, c2number) ){
System.out.println("The Casino has a pair.");
} else {
System.out.println("The Casino has nothing.");
}
}//end main
public static boolean isPair( int c1, int c2 ){
if(c1==c2){
return true;
} else{
return false;
}
}//end isPair
public static boolean isFlush( String c1, String c2 ){
if( c1.equals(c2) ){
return true;
} else{
return false;
}
}//end isFlush
public static int getNumber(){
int temp = (int) (Math.random() * 12) + 2;
return temp;
}//end getNumber
public static String getSuit() {
int temp = (int) (Math.random() * 4);
if (temp == 1) {
return "clubs";
} else if (temp == 2) {
return "hearts";
} else if (temp == 3) {
return "spades";
} else {
return "diamonds";
}
}//end getSuit
}//end class
Class 16 - Monday, Feb. 26
Creating a MyUtil Class
Check on how many have started simple calculator
Input Class
import javax.swing.JOptionPane;
public class Input {
public static String getString(String prompt) {
String temp;
temp = JOptionPane.showInputDialog(prompt);
return temp;
}//nd getString
public static int getInt(String prompt) {
int temp;
temp = Integer.parseInt(JOptionPane.showInputDialog(prompt));
return temp;
}//end getInt
public static double getDouble(String prompt) {
double temp;
temp = Double.parseDouble(JOptionPane.showInputDialog(prompt));
return temp;
}//end getInt
public static void sendMessage(String message) {
JOptionPane.showMessageDialog(null, message);
}
public static void sendMessage(double message) {
JOptionPane.showMessageDialog(null, message);
}
public static void sendMessage(int message) {
JOptionPane.showMessageDialog(null, message);
}
}//end class
Class 13-15 - With Sub
Class 12 - Tuesday, Feb 20
Block 2
Bike-a-thon video: https://www.youtube.com/watch?v=7zTwuuU1FWM
Go over how the exam was marked.
Finish Assign 1 Restaurant
Start Assign 2 Methods Questions
Walk through the Home Reno Assignment
Discuss rest of the week with the sub:
Note to Scott - Do a parameters Call vs Declaration the day we get back to ensure understanding
Class 11 - Friday, Feb 16
Discuss the U of a Contest
Method Call vs Declaration
Practice on a google doc, then have a neighbour mark it
What would the call from Main have to look like to call the following methods
Public static void placeOnMap(double lat, double long){ }
Public static void printInitials(String fn, String ln){ }
Public static void findCharacter(String word, int charNum){ }
What would the top of method declaration have to look like if the following calls came from main
callHome(“555-2454”)
addTax(299.90)
breakRecord(42.5, 46)
buyForCouprie(“Porche”, 2)
Make them aware of Java Docs for the theory assignment AND for the other Final 10% assignment
Methods Assignment 1 - Restaurant
When I am gone… Give them time on Assign 2 Theory
Class 10 - Thursday, Feb. 15
No Help Test
Class 9
Discuss tomorrow’s test - Project it first and discuss, then give access.
Parameters Example 3 - Banking
Banking Part 2 - Introduce Return Values
Finish Second Lang 2 and 3 and mark in class
If finished early, start Methods 2 - Methods Theory Questions
Banking PARAMETERS VERSION to start, moving into Return values
import java.util.Scanner;
public class Ex2_BankingParameters {
public static Scanner numscan = new Scanner(System.in);
public static Scanner wordscan = new Scanner(System.in);
public static void main(String[] args) {
double account1 = 1000;
String choice;
do {
System.out.println("deposit, withdraw, balance or exit");
choice = wordscan.nextLine().toLowerCase();
if (choice.contains("bal")) {
printBalance(account1);
} else if (choice.equals("deposit")) {
System.out.println("How much do you want to deposit?");
double amount = numscan.nextDouble();
deposit(account1, amount);
//account1 = deposit(account1, amount);
} else if (choice.equals("withdraw")) {
System.out.println("How much do you want to withdraw?");
double amount = numscan.nextDouble();
withdraw(account1, amount);
//account1 = withdraw(account1, amount);
}
} while (!choice.equals("exit"));
}//end main
public static void withdraw(double balance, double amt) {
//public static double withdraw (double balance, double amt){
if (balance >= amt + 0.5) {
balance -= amt;
balance -= 0.50;
} else {
System.out.println("Insufficent Funds");
}
printBalance(balance);
//return balance;
}//end withdraw
public static void deposit(double balance, double amt) {
//public static double deposit(double balance, double amt){
balance += amt;
printBalance(balance);
//return balance;
}//end deposit
public static void printBalance(double balance) {
System.out.println("Your balance is $" + balance);
}//end printBalance
}//end class
Class 8 - February Day, Feb. 13
Materials/Prep:
Discuss the Procedural Programming Credit
Introduce void Methods with Parameters
Practice Challenge
Work time on 99Bottles and How Cool are You
Intro to Methods
/*
Synonyms: method, function, procedure, sub-routines
Parameter - a variable that you send INTO the method
Return value - data that you send BACK from the method
Scope of a variable -
*/
import java.util.Scanner;
public class Ex1_IntroMethods {
public static Scanner numscan = new Scanner(System.in);
public static Scanner wordscan = new Scanner(System.in);
public static void main(String[] args) {
double diameter = 10.5;
printArea(diameter);
printCircumference(diameter);
printArea(20, 5);
printVolume(diameter, "cm");
//ask the user for a height
}//end main
//declare your methods here
public static void printVolume(double d, String units){
double r = d/2.0;
System.out.println("What is the height?");
double height;
height = numscan.nextDouble();
double volume = height * Math.PI * r * r;
System.out.println("The cylinder is " + volume + units + " cubed in volume.");
}//printArea
public static void printArea(double h, double w){
System.out.println("The area of the rectangle is: " + (h*w));
}//printArea
public static void printArea( double d ){
//prints surface area of a circle
double r = d/2;
System.out.println("The area of the circle is " + ( Math.PI*r*r ) );
}//end printArea
public static void printCircumference (double d){
System.out.println("The circumference is " + Math.PI*d);
}//end printCircumference
}//end class
Class 7 - Monday, Feb. 12
Materials/Prep:
Emerging Tech (videos found by students as part of Industry Profile) - Hyperloop (Colby J’s presentation) - 2:30
Other interesting things I read in the assignment
Announcement - Thursday, we will have a no help assessment (aka a coding exam). It will be similar to the How Cool are You.
For those that need help/review or extra time
For block 2 - How to set the default main class, so the play button works
Shopping Cart Example - While Loops and Switch Statement
For Loops focused review
Introduce 3 (99Bottles) including the new addition for those done early
Finish Assign 2 (How Cool) and begin 99 Bottles
Shopping Cart Example Code
import java.util.Scanner;
public class SwitchExample2Store{
public static void main(String[] args) {
Scanner wordscan = new Scanner(System.in);
Scanner numscan = new Scanner(System.in);
double checkout = 0;
int choice;
int numBought;
String stillShopping = "yes";
while( stillShopping.equals("yes") ){
System.out.println("What are you going to buy Mr. Couprie?");
System.out.println("1. HoverCar....... $100,000 ");
System.out.println("2. Weird monkey... $800 ");
System.out.println("3. Black Socks.... $9.98 ");
System.out.println("4. An apple pie... $4.50 ");
System.out.println("5. Second Cup Chiller... $5.00 ");
choice = numscan.nextInt();
System.out.println("How many are you buying?");
numBought = numscan.nextInt();
switch (choice){
case 1:
checkout += (100000*numBought);
break;
case 2:
checkout += (800*numBought);
break;
case 3:
checkout += (9.98*numBought);
break;
case 4:
checkout += (4.50*numBought);
break;
case 5:
checkout += (5.00*numBought);
break;
default:
System.out.println("Please enter one of the above numbers");
}//end switch
System.out.println("Do you want to keep shopping (yes or no)?");
stillShopping = wordscan.nextLine().toLowerCase();
}
System.out.println("Your total is: $" + checkout + ". Thank you, come again");
Class 6 - Thursday, Feb. 8
Materials/Prep:
Ted Talk (25:30) - What AI is and Isn’t
30 minutes - Finish Industry Profile assignment
Announcement - We are approaching the end of the Java Intro Unit. To end the unit, we will have a no help assessment (aka a coding exam). It will be similar to the How Cool are You.
For those that need help/review or extra time
For block 2 - How to set the default main class, so the play button works
Work time on Java 2
Block 2 notes - Told them we will mark How Cool on Tuesday. Some still will work on it Monday.
Class 5 - Wednesday, Feb. 7
Materials/Prep:
CES 2018 Highlights Video (4:33) https://www.cnet.com/videos/best-tech-of-ces-2018/
Work time on Industry Profile
Demo other String Methods:
Introduce the So You Think You Can Rap assignments
Introduce Java 2 - How Cool are You
For block 3 - mark
String Methods Sample Code
String date;
System.out.println("Please enter your birthdate?");
date = wordscan.nextLine();
if (date.endsWith("2000") || date.endsWith("2001") ){
System.out.println("You are likely in grade 11");
}
String month;
String day;
String year;
month = date.substring(0, 3);
System.out.println("Month: " + month);
month = date.substring(0, date.indexOf(" ") );
System.out.println("Month: " + month);
year = date.substring(date.length()-4);
System.out.println("Year: " + year);
int newyear = Integer.parseInt(year);
Class 4 - Tuesday, Feb. 6
Materials/Prep:
Java Lesson 3B
Java Lesson 4 - String IF Statements Example
Java Assignment 1
Finished early? Work on Industry Profile Assignment
public static void main(String[] args) {
Scanner numscan = new Scanner(System.in);
Scanner wordscan = new Scanner(System.in);
String savedUser = "couprie";
String savedPass = "1234";
String username;
String password;
System.out.println("Enter your username");
username = wordscan.nextLine().toLowerCase();
System.out.println("Enter your password");
password = wordscan.nextLine();
if( username.toLowerCase().equals(savedUser) && password.equals(savedPass) ){
System.out.println("You may continue");
} else {
System.out.println("Invalid");
}
if ( username.contains("cust") ){
System.out.println("Welcome to our store");
}
if (username.endsWith("_99")){
System.out.println("You get a discount");
}
String Methods Sample Code
Scanner wordscan = new Scanner(System.in);
String date;
System.out.println("Enter the date");
date = wordscan.nextLine();
if (date.endsWith("2001")) {
System.out.println("You are probably in grade 11");
}
if (date.startsWith("Sep")) {
System.out.println("Happy birthday");
}
if (date.toLowerCase().contains("sep")) {
System.out.println("Go downstairs at lunch for cake");
}
String year;
year = date.substring(date.length() - 4);
System.out.println("You were born in:" + year);
Class 3 - Monday, Feb. 5 - Sub here
Materials/Prep:
Activity 1 - Ted.com Video (15 minutes)
Go to Ted.com and search for the following video or click the link if you have access to this file: How Algorithms Shape our World. Before beginning the video let them know that they are about to start a project talking about how Computer Science is shaping many different industries. This particular video focuses on the stock market. Please ask them What does it mean to trade stocks? How do you make money trading stocks? Then just take a couple of minute ensuring everyone knows the basics. Tell them to Put Your Thinking Caps On and then start the video.
Activity 2 - Industry Profile Assignment (remainder of class)
Go to this link and project it up: looking at the Alberta Industry categories on this link. https://occinfo.alis.alberta.ca/occinfopreview/industries.aspx
Once you have walked them through the website, have them open two documents via Google Classroom:
Please walk them through the assignment instructions. Note that it can be completed in partners and there is an extra section for partners that I will discuss with them next class
Give them the rest of the class to work on it. I expect most of it to be completed today but they will have about 30 minutes to finish next class.
Block 3 Notes - Talk to Garrett about signing up for the CCC
Ted.com Video: How Algorithms Shape our World
Industry Profile Assignment (50 minutes)
Class 2 - Friday, Feb. 1
Materials/Prep:
Scanner Lesson 2
Java Lesson 3 - Inputting Numbers and While Loops with the Number Guess Game (see below for code)
Scanner Lesson 2
import java.util.Scanner;
public class Ex2_Scanners {
public static void main(String[] args) {
Scanner numscan = new Scanner(System.in);
Scanner wordscan = new Scanner(System.in);
String name;
String course;
int percentage;
String letter;
double bribe = 0;
System.out.println("What is your name?");
name = wordscan.nextLine();
System.out.println("What course?");
course = wordscan.nextLine();
System.out.println("What percentage did you get?");
percentage = numscan.nextInt();
if ( percentage < 50){
letter = "F";
} else if ( percentage >= 50 && percentage < 70 ){
letter = "C";
} else {
letter = "A";
}
System.out.println( name + " your mark in " + course + " is a " + letter );
System.out.println();
System.out.println("Did you forget your wallet on my desk? Wink wink?");
String wink = wordscan.nextLine();
if( wink.equalsIgnoreCase("yes") ){
System.out.println("How much is in there?");
bribe = numscan.nextDouble();
}
if (bribe > 74.99){
letter = "A";
}
System.out.println( name + " your mark in " + course + " is a " + letter );
}//end main
}//end class
Number Guess Game
Scanner numscan = new Scanner( System.in );
Scanner wordscan = new Scanner( System.in );
// System.out.print("Food Trucks Tomorrow.");
// System.out.println("Bring your \t\t\tmoney!");
// System.out.println("Clubs Fair Wed\nnesday");
// System.out.println("Robotics starts Tuesday");
// System.out.println("Curling starts next Month");
String name;
String course;
int percentage;
String letter;
Double bribe;
int rations;
System.out.println("What is your name?");
name = wordscan.nextLine();
System.out.println("What course?");
course = wordscan.nextLine();
System.out.println("What percentage did you get");
percentage = numscan.nextInt();
if( percentage <50 ){letter = “f”
Else if (p
System.out.println("How much money do you have on you?");
bribe = numscan.nextDouble();
If (bribe > )
Letter = “a”
System.out.println( //Bob you get an A in Math 10
Class 1 - Thursday, Feb. 1
Materials/Prep:
Contingency Plan - Move to Library, complete Industry Profile (in partners?)
Welcome and introductions
Discuss the CCC - I must register tomorrow
Introduction to Algorithms - Moving from Coders to Developers
Simple Algorithms In Processing - Factorials
Introduction to Netbeans and Java
Recreate the Factorial Function in Java
Java Lesson 2 - Introducing the Scanner Class
//how to factorial
int total = 1;
void setup() {
for ( int i=10; i>0; i-- ) {
total *= i; //total = total * i
}
println(total);
int number = 17;
total = 1;
for ( int i=number; i>0; i-- ) {
total *= i; //total = total * i
}
println(total);
factorial(10);
factorial(5);
factorial(17);
}
void factorial ( int num ) {
total = 1;
for ( int i=num; i>0; i-- ) {
total *= i; //total = total * i
}
println(total);
}//end factorial