Links :
Basic
Java LessonsLewis+Loftus
Java 7 Java
Tutorial
Java Video Tutor
Pseudocode
Wu
Java Textbook IBCS Course Guide Notes and Review Page (for 2017 exams) Internal Assessment Project Notes Vocabulary CS-Dictionary HowStuffWorks - Computers Java Algorithm Practice |
Next graded assignment : Functional Prototype - 24 Aug 2017 at 18:00 |
Functional Prototype
Notes
about Functional Prototype
We
will work on the functional prototype assignment
during class this week. Students should ask questions and get help
if they are unsure what is required.
Here are some examples:
Here is a VISUAL prototype for TicTacToe.
Here is a FUNCTIONAL prototype for TicTacToe
Here is a VISUAL prototype for adding numbers
Here is a FUNCTIONAL prototype for adding numbers
The
assignment is due on 24 Aug 2017.
http://ibcomp.fis.edu/275979/ibcomp/CaseStudy2018Taxis/CaseStudy2018Taxis.pdf
http://ibcomp.fis.edu/275979/ibcomp/CaseStudy2018Taxis/CaseStudy2018Taxis.pdf
Here are some HL questions, emphasizing what we studied this year:
Answers to Last Year's Final Exam
Read this Blog
You may continue working on your Visual Prototype today.
Next week we will be reviewing for the final exam,
so you won't be working on the Visual Prototype during class.
If you have questions or uncertainties, get help today.
First of all, the planned test for next Tuesday is CANCELLED.
We are too close the final exams, so we don't need another test.
Secondly, due to cancelled class on Thursday, and ISSTs,
the Visual Prototype will be due on Monday 29 May at 18:00
(instead of 24 May).
We will spend today working on the Visual Prototype,
and maybe one day next week.
Starting
Simple
Big
Tic Tac Toe Prototype
Why do malware programs, like WannaCry,
only affect Windows OS machines? What is a patch, anyway?
=== HOMEWORK ===
Watch this video.
Video about Operating SystemsReview for the final exam by reading through the notes on this blog -
for HL, search for HL in the blog. There will be HL
questions in the final exam.
topic 1.2 notes
The teacher will help individual students to get started
writing User Stories.
We will put NetBeans aside for a few days.
Today, we will watch some of this video.
We will also read some of these syllabus notes : topic 1.2.
And we will again discuss the concept of User Stories,
after watching this
video.
We will continue working on the Tabs program, and add a JTable.
*** Client Interview Notes
*****************************************
Before 18:00 today, in Haiku upload your notes about your Client Interview.
Normally this would be a .PDF file, but you may upload an MS Word
document
if you prefer.
***************************************************************
********************************************************
*** REMINDER - your Client Interview Notes are due on Monday
***
*** turned in to Haiku before 18:00. You may wish to look
at ***
*** this
example from an IBO Sample project (look at Appendix). ***
*** Yours does NOT need to look EXACTLY like the example, but ***
*** it should include actual notes from your interview with
your ***
*** client and should be 1-2 pages in length. This
assignment ***
*** is just a project check - no grade will be assigned,
but ***
*** the teacher may make
comments.
***
********************************************************
The teacher will demonstrate how to create a Tabbed interface.
Continue with this NetBeans project and open the TABS class.
In each Tab, add another copy of the same control that is already there.
For example a second Password field on the first tab,
and another set of Spinners to input another PIN number.
Then add one more Tab. In this new Tab,
add controls to create a program that
inputs a student's grades on various tests
in a class. Then add a button that adds up
the grades and divides by the number of grades
to calculate the average grade.
You can read about STACKS and QUEUES in Data Structures .
Here is code for a STACK List - the list is called list1.
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String item = input("New Item"); list1.add(item); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { int count = list1.getItemCount(); String item = list1.getItem(count-1); list1.remove(count-1); output(item); } |
Create a Java class that implements the Stack shown above.
If you need it, here is the code for the IBIO input and output commands:
http://ibcomp.fis.edu/ibo/IBIO.html
Then add a Queue, with [Enqueue] and [Dequeue] buttons.
The Dequeue button must always remove the first item in the list,
rather than removing the last item in the list.
Finally, add appropriate ERROR handling code, so that when
the Stack or Queue is empty, then trying to remove an item
generates a warning like [The Stack is empty],
rather than causing a BIG RED EXCEPTION.
You can do this by checking list1.getItemCount().
If it is zero, then output a warning message.
If not, perform the expected operation.
Download this NetBeans project and open the DataFile class.
Try the following exercises:
- Load data.txt, change some of the text,
Save the result, then close the program and
run it again and Load data.txt to check whether
if kept your changes.
- Find out how to type a file path+filename to save and
load from the Desktop.
- Change the program to maintain a LOG of who uses the program
and when they use it. That means it needs to do the
following:
- at the start, input the user's name
- use new Date() to get the current date and time
- LOAD the old LOG.TXT file
- use .getText() to get all the data
- Append the user name and date to the end, including
"\n"
to put this on a new line
- Save the result in LOG.TXT
- This should all happen automatically when the program
starts.
The LOG.TXT file should get longer each
time the program runs.
- Load the file wordlist.txt. This is list of 45000 English words.
Notice that they are NOT in alphabetical order.
Discuss whether that matters. For example, if you
insert "hilfe"
at the end of the list, and the [Search] button finds it,
is that enough? If not, you need to use
.split("\n") to change
the huge String into an array, then sort the array,
then
concatenate all the separate entries back into a single
String,
and save the result back in the file.
Read these notes:
http://ibcomp.fis.edu/275979/ibcomp/projects2014/softwareDesign.html
We will continue discussing topic 1.2.
We will discuss how to make a Java program that loads data, presents it,
changes it and then saves it.
Download this NetBeans project and open the DataFile class.
Before tomorrow, submit your project proposal.
Fill in this information and upload to Haiku:
IA Proposal for Topic and Client Fill out the following and upload it
into Haiku. ================================================== Student Name:_______________________________ Client Name :
________________________________ |
We will continue discussing topic 1.2.
Remember that on Tuesday 2 May (next class)
you must SUBMIT the name of your CLIENT (intended user)
and a brief description of the TOPIC/PROBLEM you will be doing.
You will need to WRITE THIS ON PAPER during class on Tuesday,
following the instructions you receive on that day.
Download this NetBeans application.
You should add more buttons in each section -
more picture buttons, more web-site buttons,
and more application buttons. Do as many as
you can in the time available, but for sure
at least 2 in each section.
We will discuss USABILITY and USER-INTERFACE design,
using NetBeans to help with the actual implementation.
== NetBeans Practice ==
Create the attendance program shown below,
using the code below.
~~~~~~
The program below contains:
- a Swing JLabel
- an AWT Choice
- a Swing JTextField
- 6 Swing JRadioButtons, grouped together
in a Swing ButtonGroup
- a Swing JButton
- an AWT List
public Teacher2() { initComponents(); choice1.add("Teachers"); choice1.add("Adams"); choice1.add("Baker"); choice1.add("Charles"); choice1.add("Davis"); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String s = jTextField1.getText(); String t = choice1.getSelectedItem(); String p = period; String info = s + " | " + t + " | " + p; list1.add(info); } String period = ""; private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) { period = "1"; } private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) { period = "2"; } private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) { period = "3"; } private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) { period = "4"; } private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) { period = "5"; } private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) { period = "6"; } |
Internal Assessment Project Notes
Choosing
a Topic (from last week)
Example Design Overview - Attendance System
***
HOMEWORK ***
We will start using NetBeans for writing Java programs.
You need to install it and bring it to class tomorrow
in working condition. You can download it at:
https://netbeans.org/downloads/
Choose the Java SE version (smallest download).
== OR ==
http://www.oracle.com/technetwork/articles/javase/jdk-netbeans-jsp-142931.html
to download NetBeans WITH the Java JDK.
== OR ==
borrow a USB stick from the teacher.
User Stories and Acceptance Tests
What is Software Engineering Anyway?
Here are some more videos about User Centered Design:
https://www.youtube.com/watch?v=RlQEoJaLQRA&list=PLR84EITvtzM3iCs3PWHBli8SuXtqvuhwE
How Designers Destroyed the World
We will look at Starting the IB Comp Sci IA Project - Choosing a Topic
Look at the first section in Software Design Principles
and at PAGE 4 in Guidance Notes (from old syllabus - ignore details)
https://www.c-span.org/video/?328407-1/master-algorithm
You will present your finished video to the class on Friday 31 Mar.
Do your test about 2D arrays.
*** Homework ***
Read this news article about Algorithms:
https://www.theguardian.com/science/2013/jul/01/how-algorithms-rule-world-nsa
Here is a video about magic squares:
https://www.youtube.com/watch?v=zPnN046OM34
Now download this Java program
and do the practice exercises listed at the bottom:
public class MagicSquare
{
public static void main(String[] args)
{
new
MagicSquare();
}
int[][] nums = {
{3,5,7,0} ,
{4,2,9,0} ,
{6,1,8,0} ,
{0,0,0,0}
};
public MagicSquare()
{
sums();
checkRows();
checkCols();
}
public void sums()
{
nums[0][3] =
nums[0][0]+nums[0][1]+nums[0][2];
nums[1][3] =
nums[1][0]+nums[1][1]+nums[1][2];
nums[2][3] =
nums[2][0]+nums[2][1]+nums[2][2];
}
public void checkRows()
{
if(nums[0][3]==nums[1][3]
&& nums[1][3]==nums[2][3])
{
System.out.println("ROWS SUCCESS"); }
else
{
System.out.println("ROWS failure"); }
}
public void checkCols()
{
if(nums[3][0]==nums[3][1]
&& nums[3][1]==nums[3][2])
{
System.out.println("COLS SUCCESS"); }
else
{
System.out.println("COLS failure"); }
}
}
/**** Magic Square ***************
A Magic Square is a square 2D array.
It contains SEQUENTIAL INTEGERS.
All ROWS and all COLUMNS and both DIAGONALS
must add up to the same number.
In the example above, all the rows add up equal.
But the column totals are not equal.
The method that checks the columns is NOT CORRECT,
because the SUMS method did not actually add up
the columns. So the column totals are all 0,
which appears to be the same for all 3.
But this is wrong, of course.
There are lots of improvements needed here.
(0) Write a method that prints out the entire NUMS
array, AFTER the SUMS method has run. So it
will look like this:
3 5 7
15
4 2 9
15
6 1 8
15
0 0
0 0
(1) Fix the SUMS method so that it adds up the columns.
(2) Change the program so that it checks everything
correctly: rows, columns and diagonals.
(3) Fix the NUMS array so that it is actually correct.
(4) Change the program so that the SUMS method
uses LOOPS to add up all rows and all columns.
(5) EXPAND the program to do a 4x4 magic square,
containing the numbers 1,2...16 . This is quite
a famous problem - you will find correct
number arrangements online. You should try to
do all the adding up (SUMS) with loops.
Extra Credit (only if you are interested and have time)
The interesting part of a Magic Square program is that
the program actually SOLVES the Magic Square - that means
it puts the numbers in the correct positions.
You will find solutions for number placement online.
**********************************/
Extra Credit : https://www.youtube.com/watch?v=QSmPrDSVLEU
This is a video about Binary Search Trees:
https://www.youtube.com/watch?v=a7xOXL7hn94
Here is a program that demonstrates how a Binary Search Tree functions.
//====================================
/******************************************************************\
-- TreeArrays --
This programs demonstrates how a tree can be stored in arrays.
Position 0 in the arrays is not used - a 0 entry indicates null.
Answer the following questions:
(1) Without running the program, predict what it will print.
(2) Without running the program, predict what would be printed
if root were changed to 6.
(3) Predict what would be printed if root were changed to 1.
(4) Run the program and check your answers to 1,2, and 3.
(5) Make a data array with names that are NOT in
alphabetical order, then change the POINTERS
so the program prints the names in alphabetical order.
\******************************************************************/
public class TreeArrays
{
public static void main(String[] args)
{ new TreeArrays();}
int root = 4;
String[] data =
{"","Arnie","Bob","Carla","Don","Ed","Fern","Gene"};
int[] left = { 0 , 0 , 1 , 0 , 2 , 0 , 5 ,
0 };
int[] right = { 0 , 0 , 3 , 0 , 6 , 0 , 7 , 0 };
public TreeArrays()
{ traverse(root);
}
public void traverse(int pos)
{
String word = data[pos];
int leftPointer = left[pos];
int rightPointer = right[pos];
if(left[pos]>0)
{ traverse(leftPointer);
}
System.out.println(word);
if(right[pos]>0)
{ traverse(rightPointer);
}
}
}
//============================================
When you attack a square, it might contain 0. If so, the program
should tell you the SUM of all the squares AROUND that square (like
MineSweeper).
Be careful that errors do not occur at the edge of the board.
Write the code for this - the teacher will get you started.
Download this program and do the practice exercises at the end.
*** Test Announcement *******
We will have a written test about 2D arrays
on Monday 20 March.
***************************
We will start with this Kino Seating program.
There are lots of improvements needed.
Today, we will work together to make some improvements, for example:
(1) It should be possible to reserve 2 seats without needing
to click twice or type the name twice.
(2) It should NOT be possible to replace one name with another.
Once a seat is reserved, it is protected.
(3) SEARCH for a name - later, after lots of reservations
have happened, then search for which
seat
belongs to a specific name.
(4) Count the number of empty seats.
... etc ...
More on Monday.
Start with this finished program.
We will discuss some/all of the following:
(1) How can we make the game more flexible, allowing larger boards?
If we do this, will the computer's "perfect
strategy" still work?
Will the computer at least continue to play
legally?
(2) How can we convert this program to a GUI version,
where the players can just click on squares
to play,
rather than typing in 2D array
coordinates?
(3) Discuss : is this an example of Artificial Intelligence?
Here are some introductory notes about TREES.
Here is a short video with a brief introduction to the MINI-MAX evaluation algorithm.
Mr Mulkey is out sick again today - hopefully back at school on Monday.
Start with this program:
http://ibcomp.fis.edu/275979/ibcomp/kings2017/kings4.zip
Then work together with another student to add some of the following improvements:
(1) The game should end automatically when the board is full.
To do this, the program needs a
method that:
- scans through all the squares on
the board
- checks whether each square is FREE
and COUNTS all the free squares
- if the resulting count is zero,
then the game is over
(2) Change the COMPUTERMOVE method so that:
- it always checks the middle square first.
If the middle square is FREE,
it chooses that square.
Otherwise, it chooses a RANDOM
square, by choosing a random ROW
between 0 and 4 and a random
COLumn between 0 and 4.
If that spot is not FREE, it
tries again, choosing random squares
until it finds a FREE square.
(3) Make a SMART COMPUTERMOVE method. Assuming it plays
first, in the middle,
it always chooses the square that is
symmetrically opposite from
the human's move. For example,
if the human chooses 30, then the
computer must choose 14. That
means it must "remember"
what the player's last move was.
Here is a copy of the Kings program that correctly rejects
illegal moves.
http://ibcomp.fis.edu/275979/ibcomp/kings2017/kings3.zip
(1) Download the program. Run it and check that it correctly
rejects
illegal moves, including at the edges of the
board and off the board
if the player types 88.
(2) Try changing the program to use a 6x6 board.
Does it still correctly reject illegal
moves?
Now it is time to implement a PERFECT strategy for winning.
It goes like this:
- choose to play on a 5x5 board (or any other odd-numbers size)
- choose to play first
- play in the center square
- now wherever the other player moves, you must play
in the exact symmetric location - symmetric through the
center square.
- This must win, because you will always make the last move.
For example:
- 22
- 00
- 44
- 41
- 03
- 20
- 24
Now the board is full and the first player is the winner.
There are two tricky parts here:
(.1) The game should end automatically when the board is full
(2) How can the COMPUTER correctly calculate the position
for the next move, base on the other player's
move
(assuming the computer played first)?
Spend some time talking with other students about how
these two things can be added to the program,
especially how can we make the computer play automatically
Mr Mulkey is at home with the flu today.
He will hopefully return on Thursday.
Before allowing a move, the FREE method
checks
whether it is a legal move or not. It does not work perfectly.
It needs to check 8 squares around the intended move,
as well as the square itself. You should try to improve
the FREE method to be as good as possible.
You will probably get ERRORS when you try to do this,
Make the program as good as you can and we will
discuss (and fix) the problems tomorrow.
If you finish the FREE method early, you can continue
searching for a "winning strategy". If you find a solution
for the 5x5 board, then search for a solution for a 6x6 board.
Download
this program
and do the practice exercises at the end of the program.
We are going to watch
this video (or at least part of it).
We will discuss this tomorrow during class.
- How can machines use LISTS to store data and learn?
- How much data does a "learning" computer need to absorb and store?
- How many words do you know?
- How can we write a Java program that "learns"?
- How could a computer "learn" a foreign language?
Then we will watch
this video , at least part of it.
== We will do the rest next class (no homework) ==
Internet of Things
Video (4 min)
History of Moore's Law - reduced sizes
Apple 1 Motherboard 1978 (picture)
486 Motherboard 1990 (picture)
SOC Motherboard (system on a chip)
Wednesday is an HL class.
The test on Topic 2 will be on Thursday -
a written test, no computers.
Today's planned test is postponed until Thursday 16 Feb.
(or we can discuss a better day on Monday).
Today we will continue discussing Machine Language and Binary.
Binary Addition with Gates (video)
2.1.9 |
Define the terms: bit, byte, binary, denary/decimal, hexadecimal. |
1 |
bit = true/false , 1/0 = BInary digiT Byte = 8 bits = 0 … 255 binary = number system Base 2, using bits denary/decimal = base 10 hexadecimal = base 16 using 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
|
2.1.10 |
Outline the way in which data is represented in the computer. |
2 |
To include strings, integers, characters and colours. This should include considering the space taken by data, for instance the relation between the hexadecimal representation of colours and the number of colours available. TOK, INT Does binary represent an example of a lingua franca? S/E, INT Comparing the number of characters needed in the Latin alphabet with those in Arabic and Asian languages to understand the need for Unicode. |
numbers = stored in binary, usually displayed in hexadecimal characters = stored in ASCII (8 bits) or UNICODE (16 bits) colours = 24 bit = True Color = Red/Green/Blue 1 Byte each 2^24 = 16 million colors |
The circuit above contains an AND gate, an OR gate, and a NAND gate.
Make a truth table for the circuit.
Then state which single logic gate performs the same function.
------------------
NAND Gates and More Questions (4-7,10)
These are things you should SEE - you do not need to KNOW them.
Types of OS Fast As Possible Video (5 min)
Robotics Operating System Video (first 14 min)
Dual OS for Drones Video (5 min)Low Budget Burglar Alarm Video (7 min)
2.1.13 |
Construct a logic diagram using AND, OR, NOT, NAND, NOR and XOR gates. |
3 |
Problems will be limited to an output dependent on no more than three inputs. The gate should be written as a circle with the name of the gate inside it. For example:
LINK Thinking logically, connecting computational thinking and program design, introduction to programming. |
Not enough space here Logic Gates Intro Video |
We will spend a couple (maybe 3) weeks discussing Topic 2.
Topic 2 - Computer Organization Version of Topic 2 with Vocabulary Markup Systems and Hardware Pictures |
==
Cross Platform == What software runs EVERYWHERE? How can we MAKE software run everywhere? When it does work, how do we move software around? Should I buy a Chromebook? (http://www.zdnet.com/article/amazons-top-selling-laptop-doesnt-run-windows-or-mac-os-it-runs-linux/) -- Vocabulary -- Cross-Platform (and Platform) Portable Open Source Native JVM Operating System Look and Feel Skeuomorphism Chrome, Android, iOS, Windows, Mac OSX, Linux ARM and RISC processors SoC = System on a Chip ASIC = Application Specific Integrated Circuit ... more to come ... |
== We will do the rest next class (no homework) ==
What is a BUS?
Video
Notes
with Pictures
Topic
6 - System Resources
(1) Show your 5 question program to the teacher.
(2) We will change the program to save results into a text file.
Here
is the "finished" program, including saving results.
http://ibcomp.fis.edu/275979/ibcomp/oop/Questions5.zip
Download
this Questions Program that uses a LinkedList
Do the practice exercises at the end of the Questions class.
*** Test on Monday 23 Jan **********************
We will have a test on Monday 23 Jan about:
- storing data in a class/object like the Question class
- storing Objects in an array
- storing Objects in a LinkedList
- storing data in files on the hard-disk
********************************************
Download this new copy of the Questions program.
This program can SAVE all the questions in a disk file,
and then later load them back in when the program runs again.
(1) Download the program. Click the [Add 3] button.
Then click the [Save] button.
Now run the program again. Press the [Load]
button.
Check that it really did load 3 questions.
(2) Make a new button called [Add Q].
This should INPUT a question, answer, and picture
name,
then add this new question into the qs[] array.
Now you should be able to add your own questions,
press the [Save] button, and then rerun the
program
again and [Load] the questions from disk.
(3) Now make your own quiz with 5 questions,
using 5 pictures you found in Google.
Don't spend too much time on this. Monday we will
change the program to use a LinkedList instead of an array,
so your questions file won't work any more.
You will need to make a new one. So don't make lots of questions -
5 is enough for practice.
We will rewrite yesterday's quiz program
using a different data-structure -
an array of Objects.
Extra for James : http://ibcomp.fis.edu/275979/ibcomp/oop/Questions3.zip
We will start writing Java programs again
now with GUI and OOP and Arrays.
We will work on this program: Questions.zip
You should do the practice exercises
listed at the end of the Questions class (program).
Try to finish as much of this as possible today
(maybe work at home for 30 minutes)
because we will be working on a different
version of the program tomorrow.
import
java.awt.Button;
public
class Test extends GUI
{
public static void main(String[] args)
{
new Test();
public Test()
{
super(200,200);
}
Button b1 =
addButton("1",50,50,50,50,this);
Button bReset =
addButton("Reset",10,10,100,40,this);
if(command.equals("Reset"))
{
b1.setLabel("1");
}
}
}
Here is the finished TicTacToe program:
import java.awt.*; import javax.swing.*; public class TicTacToe extends GUI { // Constructor public TicTacToe() { super(600,600); } Button b0 = addButton("",50,50,50,50,this); Button b1 = addButton("",100,50,50,50,this); Button b2 = addButton("",150,50,50,50,this); Button b3 = addButton("",50,100,50,50,this); Button b4 = addButton("",100,100,50,50,this); Button b5 = addButton("",150,100,50,50,this); Button b6 = addButton("",50,150,50,50,this); Button b7 = addButton("",100,150,50,50,this); Button b8 = addButton("",150,150,50,50,this); String player = "X"; // TOGGLE public void actions(Object source, String command) { doButton( (Button)source ) ; } public void doButton(Button b) { if(b.getLabel().length() == 0) { b.setLabel(player); checkVictory(); if(player.equals("X")) { player = "O"; } else { player = "X"; } } } public void checkVictory() { match(b0,b1,b2," top row"); match(b3,b4,b5," middle row"); match(b6,b7,b8," bottom row"); match(b0,b3,b6," left col"); match(b1,b4,b7," mid col"); match(b2,b5,b8," right col"); match(b0,b4,b8,"d1"); match(b2,b4,b6,"d2"); } public void match(Button c1, Button c2, Button c3,String msg) { if(c1.getLabel().length() != 0) { if(c1.getLabel().equals(c2.getLabel()) && c2.getLabel().equals(c3.getLabel())) { output("Winner is " + player + " in " + msg); System.exit(0); } } } public static void main(String[] args) { new TicTacToe(); } } |
Download this new version of the Trees program.
Do the following practice exercises:
- add another button that opens another web-site
it should be appropriate to the theme of the program
Copy the code that is used for the Red Man button.
- Change the colors of all the Tree decorations
- Add a button that links to a Youtube video
about the holiday season (or winter or snow...)
- Add a one more picture to the program window -
but not a tree. Maybe a reindeer or skier, etc.
- Investigate the Red Man web-site
(e.g. have some fun!)
-
Why does a USB stick read faster
than writing?
-
What is the biggest Hard Disk
actually used?
10 GB ? PetaByte? Exabyte?
You
can download this program,
or continue on your old program.
The teacher will show how to write code
for decorating the trees.
*** Test - 15 Dec 2016 ***
We will have a PROGRAMMING TEST
on Thursday 15 Dec 2016.
You will have 30 minutes to fix/improve
a Java program that is similar to
the Tree decoration program we
are currently practicing. You will be
permitted to use any notes you have,
including web-sites.
We will draw a tree - use a separate class
and put it into the same program that
you worked on last class.
You can start with a tree Button and a normal method.
Then make and use a TREE class similar to the STAR class.
Here are some notes that might help:
http://ibcomp.fis.edu/275979/ibcomp/BlueJGUIDates4/JavaTree.pdf
Here is TOO MUCH INFORMATION about Graphics2d in Java:
https://imcs.dvfu.ru/lib.int/docs/Languages/Java/Java%202D%20Graphics.pdf
Download and unzip this program
Open the CLICKING program and COMPILE it and RUN it.
(1) Start with the green box in the top left corner.
Click the green box several time.
Figure out the purpose of the variable drawingClicks.
Change the corresponding method to allow larger
values of drawingClicks.
(2) Move on to the pink box in the lower left corner.
Click on this box several times.
Find the corresponding method.
Change the color of the eyes.
Change the smile to a frown.
Add 2 more circles for ears.
(3) There are 2 blue stars on the screen.
Find the commands that draw these stars.
Add 2 more stars, in appropriate locations.
(4) Change the clown picture to a different picture.
Then change the corresponding method/commands
so that clicking on the clown does NOT open a
web-site,
but rather changes the clown to a different
picture.
Make this toggle back and forth between 2
pictures.
(5) Choose any other part of the program and
change it to do something slightly different.
Optional Reading - Self Driving Car Record Trip
Download
this program and do the practice listed in the program
documentation.
This is our last day for the SkiTrip program.
We will write a Sorting Algorithm to sort the names alphabetically.
*** HOMEWORK ***
Come to class tomorrow with a recommendation of
how and when the execute the [Save] method,
so that the [Save] button can be removed.
1
- Topic
6 - System Resources
2 - Notes
with Pictures
Open the following project and do the tasks listed at the beginning of the program.
http://ibcomp.fis.edu/275979/ibcomp/BlueJ/SkiTrip3.zip
Here are some more useful additions:
- a button that sorts the Students by their names, e.g. alphabetical
- the CountVehicles button automatically enters data into the Cars
and Busses boxes,
according to whether a code occurs 4 times or less
(car) or more than 4 (bus)
Then it automatically calculates the cost for these cars and
busses
- the CountBeds method enters data into the HotelRooms and
LodgeRooms boxes,
and then executes the <Calc Cost> commands to
automatically perform this function
===== Planning Notes =====
/***
Ski
Trip ************************************************
Memorial
High
School is planning a ski trip for 188 students.
They
have
some choices for transportation and lodging:
-
Transportation - They can use busses that each carry 20
students
Each bus costs 1000
Euros to drive. Each car carries 4 students
and costs 250 Euros
to drive.
-
Lodging - A hotel room costs 300 Euros and accomodates 4
students.
A ski lodge room
costs 800 Euros and accomodates 12 students.
They
can
use a mixture of cars and busses, as well as a mixture
of
hotel
rooms and youth hostel rooms.
The trip committee can change
the
numbers
of cars, busses, rooms and lodges until they find
a
solution with enough seats and beds, but at minimum cost.
The
code
below is a “first idea” about what needs to happen.
int
cars
= 8;
int
busses
= 8;
int
hotel
= 10;
int
lodge
= 12;
int
seats
= cars*4 + busses*20;
int
beds
= hotel*4 + lodge*12;
float
cost
= cars*250 + busses*1000 + hotel*300 + lodge*800;
println(cars
+
" cars and " + busses + " busses = " + seats + " seats");
println(hotel
+
" rooms and " + lodge + " lodges = " + beds + " beds");
println("Total
cost
= " + cost);
~~~~~~~~~~~~~~~~~~
After a bit more thought, we realize that we need to record (save)
the locations of seats in vehicles and bed locations, not to
mention
the name of each student. So we will need a CLASS so we can have an OBJECT for each student, like this:
class
Student
String name
String vehicle
String bed
We will need METHODS for all of the following tasks:
-
Save Data (Students) into a disk file
-
Load Data from disk
-
Add a new student entry
-
Change/edit/correct a student entry
-
Display all the student data
-
Search for a student
-
Count the number of SEATS required in various vehicles
-
Count the number of BEDS required
...
Checking that ...
- Data is VALID - Each vehicle is not
overloaded
- Rooms (beds) do not
have too many students assigned
- There are no
duplicate names entered
...
Printing ...
- The list of all
student names with vehicle and bed assignments
- For each vehicle,
the list of students assigned
- For each
room/lodge, the list of students assigned \**************************************************************/ |
It's sort ;) of like a Bubble Sort, but not really.
Here is Java Code for a Shell sort.
"JUST" copying this code into your program won't work.
It requires some "refactoring" to make it work.
We will do this is class.
Here is a video about the Shell sort.
You can watch it with the Visualization Tool.
The Shell Sort is FAST, but how fast is it?
We will discuss this.
You don't need to "learn" the Shell sort algorithm,
but you might wish to USE it to speed up your sorting tasks.
*** Quiz on Monday about Bubble Sort and Selection Sort ***
You should be able to WRITE the Bubble Sort and the Selection Sort
correctly in Java, using a pen and paper. There will also be
a question about an "unknown" algorithm.
Here is an interesting program: http://www.cleverbot.com/
-------------------------------------
Continue with the "Lots of Numbers" program.
We will discuss the "speed" of sorting algorithms.
When you run
manyBubble();
manySelect();
manyMystery();
manySmartBubble();
it produces the following output - on an i3 Windows 8 machine.
Bubble 10000 = 0.469 sec Iterations = 99990000 Bubble 20000 = 1.828 sec Iterations = 399980000 Bubble 40000 = 5.825 sec Iterations = 1599960000 Bubble 80000 = 23.767 sec Iterations = 6399920000 Bubble 160000 = 95.973 sec Iterations = 25599840000 Selection 10000 = 0.141 sec Iterations = 49995000 Selection 20000 = 0.562 sec Iterations = 199990000 Selection 40000 = 2.094 sec Iterations = 799980000 Selection 80000 = 8.447 sec Iterations = 3199960000 Selection 160000 = 33.812 sec Iterations = 12799920000 Mystery 10000 = 0.313 sec Iterations = 100000000 Mystery 20000 = 1.25 sec Iterations = 400000000 Mystery 40000 = 4.218 sec Iterations = 1600000000 Mystery 80000 = 17.89 sec Iterations = 6400000000 Mystery 160000 = 71.796 sec Iterations = 25600000000 Smart Bubble 10000 = 0.312 sec Iterations = 49995000 Smart Bubble 20000 = 1.297 sec Iterations = 199990000 Smart Bubble 40000 = 3.75 sec Iterations = 799980000 Smart Bubble 80000 = 15.201 sec Iterations = 3199960000 Smart Bubble 160000 = 61.446 sec Iterations = 12799920000 |
1
- Topic
6 - System Resources
2 - Notes
with Pictures
Intro to Operating
Systems Video
Here is a better version of the "Lots of Numbers" program.
We will discuss the "speed" of sorting algorithms.
Here is an interesting program: http://www.cleverbot.com/
The teacher is away this week. You should do the following
assignments
(in whichever order you prefer).
- Lots of numbers : http://ibcomp.fis.edu/275979/ibcomp/ibBook/javaBasics/BubbleSort/index.html
- In your textbook, read p.564-571 (write down questions to discuss on Monday)
- Sorting names : http://ibcomp.fis.edu/275979/ibcomp/ibBook/javaBasics/CDlistSorted/index.html
- Try out this game (don't get hooked) : http://2048game.com/
Sorting
Explained with Java Code
Java Algorithms (including Sorting)
- QUIZ -
Spend 30 minutes on your quiz. Pens only, no computers.
Turn it in when finished.
- Read about Sorting -
In your textbook, read about
Selection Sort and Bubble Sort
on pages 218-222.
- Investigate your New Textbook -
HL students may work on their HL homework,
writing an ALGORITHM for producing an index.
1
- Topic
6 - System Resources
2 - Notes
with Pictures
Intro to Operating
Systems Video
Here are solutions to yesterday's NumList problems.
Some numlist puzzles problems.
Sorting
Explained with Java Code
Java Algorithms (including Sorting)
Here is a finished
version of the ArraysOfWords program,
including the improved doAdd() method.
We will discuss this program about arrays containing numbers.
*** Quiz on Arrays ***
On Mon 7 Nov, we will have a 25 min written quiz about arrays.
Here is the ArraysOfWords
program,
including a Delete function.
== HOMEWORK ==
Write a better doAdd method, like this:
// Plan in Pseudocode
check
whether full
if full then return (quit)
print a
list of free rooms
input a
room num
check
if it's vacant
if not, try again, until you find vacancy
input a name
loop
through all the rooms to find the name
if found, ask whether you want another room
if yes then
reserve num for name, FINISHED (return)
end
loop
reserve
num for name
HOMEWORK = write Java code for this
We will finish #10 in Version 2 of the SearchLists program.
Then we will work on LOADING all the words in this
list of words
into
an array. Then we will do some SEARCHING in the array.
Intro to Operating
Systems Video
1
- Topic
6 - System Resources
2 - Notes
with Pictures
What is an Operating System (OS)? What do
you know about it? Input, Processing, Output Browser can access only one type of file OS can access a variety of files available to
the computer Windows, IOS, Linux Manages - computer hardware Manages memory Simple function - getting the time Complicated function - opening a program OS is not the first thing that is loaded – BIOS
comes first OS gets updated – once a year |
We will continue the Searching Lists program on Monday.
Today, you can download this program: Jeopardy
Add more questions, going up to at least 300 in each category.
It's programming practice - try to become fast and reliable.
Download Version 2 of the SearchLists program.
Start with #7 today. Then do 8, 9 and 10 in the next 2 days.
Download this program and do the practice exercises.
(1) 5 minute quiz
(2) Discuss the September Test
(3) We
will be learning about:
- lists
-
arrays
-
sequential search
-
binary search
We
will be using this
list of words
and this
program.
We
might also use this
random list of words.
Here
is a list of names by popularity: Given
Names.txt
(1) Return end of September Test
(2)
We will be learning about:
- lists
-
arrays
-
sequential search
-
binary search
We
will be using this
list of words
and this
program.
We
might also use this
random list of words.
Here
is a list of names by popularity: Given
Names.txt
Here
is a text file for future use: Airports.txt
*** HOMEWORK ***
STUDY
the Airports.txt file,
especially looking for SYNTAX RULES.
And find out what ICAO and IATA mean.
5
minute QUIZ Tomorrow.
Scan this ENTIRE BLOG to remind yourself what we studied.
Do some experiments with some of the programs that we practiced.
The test will include the following items (and maybe other things):
Java: calculations, variables, Strings,
if.. commands , Dates and times , GUI programming
Theory : , Characters and ASCII and Unicode
HL = embedded control systems
HL students will have a slightly longer test, including questions about embedded control systems.
We will transfer the ALGORITHMS into our GUI DICE program.
*** Test Announcement - Mid Term Test 30 Sep ***
*** covers everything we have studied this year ***
Questions/problems about Friday's practice?
We
will work on this program: EasyDice(GUI)
You
should do the practice exercises
listed
at the end of the EasyDice class (program).
Try
to finish as much of this as possible today
(maybe
work at home for 30 minutes)
because
we will be working on a different
version
of the program tomorrow.
Download this program and open it in
BlueJ.
BluejGUI
example program
Do as many of the following exercises as you can during class.
No need to work on this at home - we will continue on Monday.
Getting
Started
To get started, you should download 2 files:
-
BlueJ IDE at http://bluej.org
Get the version WITH Java 8 SDK
The
teacher will demonstrate how to use BlueJ,
and explain how the BluejGUI example program works.
Here are some sample projects.
Here is a video with a basic introduction for writing your first programIBCS Course Guide M Brookes Notes on Item 7
The Internet of Things (IoT) video
Use Google, books, web-sites, other peoples' brains, whatever.
Find out how to INPUT today's date (or maybe get it automatically)
and then produce the date that is 1 year ago,
without using a calculation like: 1000L*60*60*24*365 (or 366).
Try to find a BUILT-IN Java method (maybe in java.util.Date)
that can subtract exactly one year from a Date.
Wu
Java Book section 2.4.3 about Dates
Notes about Date and Time in Java.
Background Info about Dates and Times
import
java.util.*; @Deprecated public class CountDays { public static void main(String[] args) { new CountDays(); } public CountDays() { Date today = new Date("30 Nov 2016"); Date yearEnd = new Date("31 Dec 2016"); long dayMillis = 1000*60*60*24; long days = ((yearEnd.getTime()-today.getTime())/dayMillis); output(days + " days\n" + "between " + today.toString().substring(0,10) + "\n" + "and " + yearEnd.toString()); } public String input(String prompt) { return javax.swing.JOptionPane.showInputDialog(null,prompt); } public void output(String message) { javax.swing.JOptionPane.showMessageDialog(null,message); } } |
Brief Overview of Dates and Times
We will also discuss all the details in this program:
import java.util.*; // Date import java.text.*; // DateFormat @Deprecated // Ignore Date depecration warnings public class Holidays { public static void main(String[] args) { new Holidays(); } public Holidays() { Date now = new Date(); output(now.toString()); // what will this show? DateFormat formatter = new SimpleDateFormat("dd MMM yyyy"); String today = formatter.format(now); output(today); // what will this show? String yesterday = "" ; // make this calculate yesterday's date output("Yesterday = "+yesterday); // show German format howOldAreYou(); } public void howOldAreYou() { String born = input("Type your birthdate as: dd MMM yyyy"); long bornMillis = new Date(born).getTime(); Date today = new Date() ; // make this equal today's date and time long todayMillis=today.getTime() ; // make this equal today's milliseconds long aliveMillis = todayMillis - bornMillis; long yearMillis = 1000L*60L*60L*24L*365L ; // calculate milliseconds in one year // 3.154e+10 long age = (long)(aliveMillis / yearMillis); output("Your age is " + age); } public String input(String prompt) { return javax.swing.JOptionPane.showInputDialog(null,prompt); } public void output(String message) { javax.swing.JOptionPane.showMessageDialog(null,message); } } |
(1) Brief quiz - 10 min on paper, no computers
(2) Library books - dates and overdue charges
== Time Check ==
String time = input("Type the time as hh:mm"); |
George Washington Initials
String first =
name.substring(0,1);
int s = name.indexOf(" ");
String second =
name.substring(s+1,s+2);
System.out.println(first.concat(second));
The whole Initials program
public class Test
{
public static void main(String[] args)
{
new Test("George
Washington");
new Test("Madonna");
new Test("");
new Test("George X Y Z
Peacock");
}
public Test(String name) // parameter
{
System.out.println("Name = "
+ name);
if(name.length()==0)
{
System.out.println("Empty string, no initials");
}
else
{
String first = name.substring(0,1);
int s
= name.lastIndexOf(" "); // produces -1 if no space
if(s
== -1)
{
System.out.println(first);
}
else
{
String second = name.substring(s+1,s+2);
System.out.println(first.concat(second));
}
}
// + is POLYMORPHIC =
has more than one meaning/function
// char is a PRIMITIVE type,
not a class/object
// does not contain
Methods
}
}
1. Khush will present his findings about Automatic Doors.
2. All will tell STORIES about their devices.
3. Past Paper Question - May 2015 Paper 1 #12
** HOMEWORK
************************************
Write answers to the fire-station question (above).
This should take less than 1 hour (during an exam
you would do this in 20 minutes.
Hint 1 :
a 4 point question requires 4 ideas.
So question (a) probably requires 4 sentences or more
-
but not a lot more than 4 sentences. So your
written answers
to these questions should certainly fit on one page
(probably less).
There are 15 points, so probably 15-20 sentences
altogether.
Hint 2 :
These questions do not have "right" or "wrong"
answers.
They do have "better" and "worse" answers.
Try to write "good" answers, but don't worry about
them being "right".
Bring your written answers to the next HL class.
*************************************************
1. Questions about the passwords article?
Encryption
Read
Section 2.5 in McFadyen (p.46-59)
Here is a simple sample encryption program:
public class Encryptor { public static void main(String[] args) { new Encryptor(); } String plainText = "secret message for today"; // input("Type the plain text"); public Encryptor() { String crypText = encrypt(plainText); output("Original message = \n" + plainText + "\n\nEncrypted = \n" + crypText); } String encrypt(String plain) { // split up the letters .substring // change ASCII codes by adding 1 or 2 String result = ""; for(int c = 0; c < plain.length(); c = c + 1) { char ch = plain.charAt(c); char nch = (char)(ch + 1); result = result + nch; } return result; } public String input(String prompt) { return javax.swing.JOptionPane.showInputDialog(null,prompt); } public void output(String message) { javax.swing.JOptionPane.showMessageDialog(null,message); } } |
идти
FIRST - 10 min Java quiz
Second - Password
and ID
Homework = in the Password program, make one of
the passwords be in Russian (Cyrillic) characters
Shruti Washing Machine
Jasmin GPS
Alex Elevator
Catherine Device Drivers
Michael Heating Systems
Gwen Traffic Lights
Khush
Automatic doors
========
In
each case, consider the following questions:
We will have a quiz on Thursday.
You will need to fix a Java program, using your computer and notes.
/*** Cafeteria ************************************ This is a very simple example of the calculations needed in a cafeteria cash register. It demonstrates an INTERACTIVE GUI INTERFACE. **************************************************/ public class Cafeteria { public Cafeteria() { double sandwich = inputDouble("Sandwich price"); double drink = inputDouble("Drink price"); double total = sandwich + drink; output("Total = " + total); double paid = inputDouble("How much do you want to pay (e.g 10.00)?"); double change = paid - total; output("Your change is " + change); } public static void main(String[] args) { new Cafeteria(); } static String input(String prompt) { return javax.swing.JOptionPane.showInputDialog(null,prompt); } static double inputDouble(String prompt) { double result=0; try{result=Double.valueOf( input(prompt).trim()).doubleValue();} catch (Exception e){result = 0;} return result; } static void output(String message) { javax.swing.JOptionPane.showMessageDialog(null,message); } } /*** Sample Output ******************************** Sandwich Price --> 3.50 Drink Price --> 1.75 Total = 5.25 Paid --> 10.00 Your change is 4.75 *****************************************************/ |
Make this program better by doing the following:
- add a Dessert Price
Homework : read section 2.3.2 in McFadyen Java Book
== Homework ==
Read McFadyen 2.1+2.2 (Java and BlueJ)
We will also check that everyone installed
BlueJ successfully
by running this very simple Java class:
public class Test { { System.out.println(99*111); } } |
=== Homework (due 30 Aug) ===
Investigate YOUR chosen device. Answer question 1-4 completely and thoroughly.
=========
Shruti Washing Machine
Jasmin GPS
Alex Elevator
Catherine Device Drivers
Michael Heating Systems
Gwen Traffic Lights
Khush
Automatic doors
========
In
each case, consider the following questions:
For the most part, there is little storage in embedded controllers, or at least nothing interesting.
--------------------------
7.1.1 Discuss a range of control systems.
A variety of control systems should be examined such as:
- automatic doors
- heating systems
- taxi meters
- elevators
- washing machines
- process control
- device drivers
- domestic robots
- GPS systems
- traffic lights
. . . and other common devices.
Technical knowledge of specific systems is not expected
but students should be able to analyse a specified system.
7.1.2 Outline uses of microprocessors
and sensor input in control systems.
~~~~~~~~
We will study some sample control systems.
In
each case, consider the following questions:
For the most part, there is little storage in embedded controllers, or at least nothing interesting.
Today's Assignment
- What is COMPUTER
SCIENCE? http://www.macmillandictionary.com/us/dictionary/american/computer-science
- How do we define the
term COMPUTER? http://searchwindowsserver.techtarget.com/definition/computer
- We will discuss these notes Computer
Systems Notes about computer SYSTEMS.
Homework
- install BlueJ from http://bluej.org
Download the version WITH Java JDK installer
- Read these notes Computer
Systems Notes
and be prepared to discuss them next class.
Brief Overview of Dates and Times
LocalDateTime Quickstart More Notes
Too Much Info about Java 8 (Chap 12) (don't read this)