The end of line problems should also be solved, now.
Saturday, December 20, 2008
Summative Data Files Updated
I've modified all the summative data files so that the fields in each record are separated by ":". For example an address might look like: "124 Main St.:K1K 0N7:Ottawa:ON"
Friday, December 12, 2008
Homework
There's homework (that I'll be checking) for the weekend.
You must have completed (or demonstrate a good faith effort) both of the linear search exercises on the 2nd handout. (This is the handout that says Array Exercises in the header and that has the filename ICS3M_2.25_Exercise.doc in the footer.)
If you are one of the people who had already finished then you must do one of exercises 1, 3, 4, or 8 at the end of Chapter 10 in the text.
You must have completed (or demonstrate a good faith effort) both of the linear search exercises on the 2nd handout. (This is the handout that says Array Exercises in the header and that has the filename ICS3M_2.25_Exercise.doc in the footer.)
If you are one of the people who had already finished then you must do one of exercises 1, 3, 4, or 8 at the end of Chapter 10 in the text.
Make Up Test
Heads up the couple of people who weren't in class today. I handed back the tests. Not everyone passed. If you got less than 60% you can do a re-test (different content) next Wednesday the 17th of December in class.
Here's the deal, though. The maximum mark you can get on the re-test is 60%. It wouldn't otherwise be fair to people above the 60% cutoff line if one could blow the original and then do a re-test and get a better mark than them.
You have to let me know by Monday if you want to do the re-test on Monday.
Here's the deal, though. The maximum mark you can get on the re-test is 60%. It wouldn't otherwise be fair to people above the 60% cutoff line if one could blow the original and then do a re-test and get a better mark than them.
You have to let me know by Monday if you want to do the re-test on Monday.
Saturday, December 6, 2008
Facebook virus
I'm seeing credible reports about a virus spreading via facebook's messaging system. The subject line in an infected message is something like "You look awesome in this new movie". When you click the link you get prompted to upgrade your flash player. At this point malicious s/ware is installed on your computer. The software turns your computer into a (cyber) zombie that will then participate in net attacks against other sites against your will.
Forewarned is forearmed.
Forewarned is forearmed.
Monday, November 17, 2008
I Need A Raise
That should be "I need arrays".
Today we're tackling arrays. If you missed class then the homework will help you catch up.
Read Ch. 10, pp 237-241. Then do Questions 1, 2, 3, 4 and 14a, 14b, 14c, and, 14d.
Note that question 4 asks you to write a for-each statement but it turns out that J# hasn't implemented the for-each statement. (D'oh!)Use a regular for statement instead.
You should note that I've put a sample program that I wrote in class showing an array of strings being used in a for loop in the ICS3M\Arrays Handout folder. In addition, you can also find the powerpoint presentation for Arrays in that same folder. Make sure you look at the presentation in Notes view mode so you can see my notes which augment the information in the slides. I don't recommend that you try and rely on the slides alone without reading the text. There's a lot more information in the text that can be found in the slides.
Today we're tackling arrays. If you missed class then the homework will help you catch up.
Read Ch. 10, pp 237-241. Then do Questions 1, 2, 3, 4 and 14a, 14b, 14c, and, 14d.
Note that question 4 asks you to write a for-each statement but it turns out that J# hasn't implemented the for-each statement. (D'oh!)Use a regular for statement instead.
You should note that I've put a sample program that I wrote in class showing an array of strings being used in a for loop in the ICS3M\Arrays Handout folder. In addition, you can also find the powerpoint presentation for Arrays in that same folder. Make sure you look at the presentation in Notes view mode so you can see my notes which augment the information in the slides. I don't recommend that you try and rely on the slides alone without reading the text. There's a lot more information in the text that can be found in the slides.
Wednesday, November 12, 2008
J# software download site
Some people have asked me to re-link to the download site for the J# software. Here it is:
http://www.microsoft.com/express/2005/download/default.aspx
http://www.microsoft.com/express/2005/download/default.aspx
Monday, November 10, 2008
Assignment 2
Reminder: This is due on Thursday. For Homework today, I want you to write the pseudocode for evaluateBet(). In your pseudocode write:
- the actual method declaration,
- the inputs and what their possible values are
- and the output(s)
- the algorithm for executing/implementing evaluateBet()'s problem solution.
Thursday, November 6, 2008
We did some basics review over the past couple of days in an attempt to solidify students' skills. Here's what we did:
Consider:
and
Identify:
1. the loop control variable
2. the initialization code
3. exit condition
4. increment statement
5. executable satement(s)
6. what output will be produced?
We filled out the || and && and ! truth tables
Given:
-there is at least 1 other way to re-write this while condtion. What is it?
and there's also....
Given:
Loop control variable (i.e. counter): index
Executable stmt: finalValue: -= index;
increment statement: index++;
initialization statement: index = 1;
Write the for loop that implements these conditions.
Assume that finalValue has itself been intialized to a value of 7, what output would be produced by the following line of code assuming it came directly after the for loop exited.
System.out.println(“The final value is “ + finalValue);
Also
Answer the following questions:
1. What discount will be applied if I buy 175 items at a price of $8.00?
2. What discount will be applied if I buy 225 items at a price of $10.29?
3. What discount will be applied if I buy 50 items at $0.99?
4. What discount will be applied if I buy 1500 items at $11.99?
5. What discount will be applied if I buy 1500 items at $6.99?
I'll post the answers in the comments.
Consider:
for(int i=0;i<=20;i++)
System.out.println(i);
and
for(int i=45;i>=-5; i-=5)
System.out.println(i);
Identify:
1. the loop control variable
2. the initialization code
3. exit condition
4. increment statement
5. executable satement(s)
6. what output will be produced?
We filled out the || and && and ! truth tables
Given:
do
PUT Prompt for usrNum
GET usrNum
//while usrNum is out of range
while(usrNum>10 || usrNum <1)>
-there is at least 1 other way to re-write this while condtion. What is it?
and there's also....
Given:
Loop control variable (i.e. counter): index
Executable stmt: finalValue: -= index;
increment statement: index++;
initialization statement: index = 1;
Write the for loop that implements these conditions.
Assume that finalValue has itself been intialized to a value of 7, what output would be produced by the following line of code assuming it came directly after the for loop exited.
System.out.println(“The final value is “ + finalValue);
Also
if (quantityPurchased >= 150 && price > 9.99)
discount = .05;
else if (quantityPurchased >= 1000 && price > 7.99)
discount = .1;
else if (quantityPurchased >= 10000 || price < discount =" .33;" discount =" 1;">
Answer the following questions:
1. What discount will be applied if I buy 175 items at a price of $8.00?
2. What discount will be applied if I buy 225 items at a price of $10.29?
3. What discount will be applied if I buy 50 items at $0.99?
4. What discount will be applied if I buy 1500 items at $11.99?
5. What discount will be applied if I buy 1500 items at $6.99?
I'll post the answers in the comments.
Wednesday, November 5, 2008
Quantity is Quality (sometimes)
Yesterday's and today's class have been mostly devoted towards reviewing some fundamentals since I'd sensed a weakness in quite a few students. I'm going to continue with that tomorrow and, aside from some notes on documenting methods, am not planning on introducing any more new material this week. I think the fundamental weakness is that the class hasn't written enough code for the basic constructs to be at your fingertips. Once you've written a hundred for loops you won't be struggling with how to put one together anymore.
Quantity is (can lead to?) quality. It's like martial arts. You practice the same move over and over and over again. You do the same thing a thousand, two thousand times. The point? To insert the moves into your nervous system. To make this artificial sequence of moves something that you do automatically, instinctively. Once you reach that level of integration then you can start improvising with the moves and do creative things with them.
Computer Science, then, as a form of mental karate.
The other big challenge that a lot of students are facing right now has to do with the difficulty of translating the requirements laid out in the review exercises into a solution implemented in the code. It's like word problems in math. You have to keep practicing the process of turning the descriptions into java code. How do you this if you don't already know how to do it? That's the sixty-four thousand dollar question.
One part of the answer is to write some *&(@#$ stuff down. The program description contain pieces of the puzzle you have to put together. Get them out of your head (where they reside after you read the problem) and onto some paper so you can look at them.
Another part of the answer is to do lots of them. Again, practice is going to lead you in the right direction. Every problem that you successfully solve is an approach that enters your repertoire and that you then have available for re-use down the road.
Quantity is (can lead to?) quality. It's like martial arts. You practice the same move over and over and over again. You do the same thing a thousand, two thousand times. The point? To insert the moves into your nervous system. To make this artificial sequence of moves something that you do automatically, instinctively. Once you reach that level of integration then you can start improvising with the moves and do creative things with them.
Computer Science, then, as a form of mental karate.
The other big challenge that a lot of students are facing right now has to do with the difficulty of translating the requirements laid out in the review exercises into a solution implemented in the code. It's like word problems in math. You have to keep practicing the process of turning the descriptions into java code. How do you this if you don't already know how to do it? That's the sixty-four thousand dollar question.
One part of the answer is to write some *&(@#$ stuff down. The program description contain pieces of the puzzle you have to put together. Get them out of your head (where they reside after you read the problem) and onto some paper so you can look at them.
Another part of the answer is to do lots of them. Again, practice is going to lead you in the right direction. Every problem that you successfully solve is an approach that enters your repertoire and that you then have available for re-use down the road.
Thursday, October 30, 2008
Tuesday, October 28, 2008
There's a madness in his method
We started methods today (Ch 07 in your book). You find the PPT presentation that I was running in the handout folder now. It's called ICS3M_2_Ch07.ppt. Note that I've included a bunch of stuff in the slide notes so you should view the slide in Notes view.
On a really general level methods are a way to support modularity in computer software in general and in Object-Oriented programming (of which Java is an example) in particular. Methods are a way of grouping together code that performs a specific/singular function in a way that hides the details of how that function is implemented from the main body of the code and that promotes the reuse of that code. We'll talk about that aspect (the implementation hiding aspect) of methods tomorrow. If I fail to mention this issues please remind me, OK?
You'll need to know the details of how we actually include, code and call methods in our code.
Calling methods is easy. You've been doing it all along. Just put the method name along with any arguments in the brackets in your code and it will be executed under the appropriate circumstances.
For instance: System.Convert.toInt16("3457"); is a method call. So, for that matter, is System.out.println("Some kinda textin' goin' on");
For 10 points everybody, how do we know if a piece of code is a method call?
We also reviewed for loops.
We remember how a for loop works by
where
Be prepared to chant it tomorrow.
On a really general level methods are a way to support modularity in computer software in general and in Object-Oriented programming (of which Java is an example) in particular. Methods are a way of grouping together code that performs a specific/singular function in a way that hides the details of how that function is implemented from the main body of the code and that promotes the reuse of that code. We'll talk about that aspect (the implementation hiding aspect) of methods tomorrow. If I fail to mention this issues please remind me, OK?
You'll need to know the details of how we actually include, code and call methods in our code.
Calling methods is easy. You've been doing it all along. Just put the method name along with any arguments in the brackets in your code and it will be executed under the appropriate circumstances.
For instance: System.Convert.toInt16("3457"); is a method call. So, for that matter, is System.out.println("Some kinda textin' goin' on");
For 10 points everybody, how do we know if a piece of code is a method call?
IT HAS BRACKETS
We also reviewed for loops.
We remember how a for loop works by
Interesting
Challenges
Excite
Innovators
where
I - Initialize the counter
C - Check the (exit) condition
E - Execute the body
I - Increment the counter
Be prepared to chant it tomorrow.
Monday, October 27, 2008
Visual J#
A student told me today that he was being prompted for a registration key when he tried to start J# at home. That indicates to me that he had downloaded Microsoft J# Visual Studio Express 2008 rather than Visual Studio Express 2005. If you're having this problem you probably need to download the 2005 version of J# which you can locate here: http://www.microsoft.com/express/2005/download/default.aspx
Tomorrow it's on to Chapter 7 - Methods. If you want to get ahead a little, read pp 157 to 161.
Tomorrow it's on to Chapter 7 - Methods. If you want to get ahead a little, read pp 157 to 161.
Tuesday, October 14, 2008
Getting Started
As I walked 'round the class today while you were working on the AccountSetup program, I noticed more than a couple of you have trouble just getting started. Once you get over that initial hump, you seem to be able to make progress. But the first step's a doozy.
So, how to get started? How, for that matter, do I get started?
It's a hard process to describe and I suspect that I don't always proceed in the same way.
The first thing I do when getting started is to pick something simple that the program asks me to do. In AccountSetup (p. 139) one of the things we're asked to do is to get a user name and later on to display it. So I'd do that first. I'd declare a variable to hold the user name and then prompt the user to enter a user name and since I'll have to display it later, I might as well as display it now.
String userName;
System.out.print("Enter a user name, please: ");
userName = System.Console.ReadLine();
System.out.println("Your user name is " + userName);
OK. That's a start. And it also relieves you of some of the mental effort of keeping track of that particular part of the puzzle.
The other thing we had to do in AccountSetup was to prompt the user for a password and keep prompting them until they entered a password with at least 8 characters. Of course, this means that we need a loop (because we're going to keep prompting them until we get a password that 8 characters or more long). It also means that you'll need another String variable to store the password in. This part of the program can be implemented with either a while or a do...while loop. And you might as well make the condition that keeps the loop running the thing that checks to see if the password is 8 characters long or not.
do
{
System.out.print("Enter a password (8 characters minimum): ");
password = System.Console.ReadLine();
} while (password.length < 8);
I'll leave the last part up to you. That's the output part. Don't forget to convert the user name and password to lower case!!
So, how to get started? How, for that matter, do I get started?
It's a hard process to describe and I suspect that I don't always proceed in the same way.
The first thing I do when getting started is to pick something simple that the program asks me to do. In AccountSetup (p. 139) one of the things we're asked to do is to get a user name and later on to display it. So I'd do that first. I'd declare a variable to hold the user name and then prompt the user to enter a user name and since I'll have to display it later, I might as well as display it now.
String userName;
System.out.print("Enter a user name, please: ");
userName = System.Console.ReadLine();
System.out.println("Your user name is " + userName);
OK. That's a start. And it also relieves you of some of the mental effort of keeping track of that particular part of the puzzle.
The other thing we had to do in AccountSetup was to prompt the user for a password and keep prompting them until they entered a password with at least 8 characters. Of course, this means that we need a loop (because we're going to keep prompting them until we get a password that 8 characters or more long). It also means that you'll need another String variable to store the password in. This part of the program can be implemented with either a while or a do...while loop. And you might as well make the condition that keeps the loop running the thing that checks to see if the password is 8 characters long or not.
do
{
System.out.print("Enter a password (8 characters minimum): ");
password = System.Console.ReadLine();
} while (password.length < 8);
I'll leave the last part up to you. That's the output part. Don't forget to convert the user name and password to lower case!!
Thursday, October 9, 2008
Factor this, buddy!
Almost everbody has either done the Factorial program or is almost there. The really tricky part is seeing how using the for loop (or any loop, for that matter) allows you to incrementally solve the problem of calculating the factorial. Here's my take on it.
The factorial of a number is what we get when we multiply all the numbers between 1 and the number together. (We write it as 5! or 4! or whatever.)
5! is 5 * 4 * 3 * 2 * 1 (= 120)
4! is 4 * 3 * 2 * 1 (=24)
3! is 3 * 2 * 1 (=6)
The difficulty (conceptually speaking) is how to implement this relatively simple piece of mathematics in a loop.
Let's look at 4!
4! is 4 * 3 * 2 * 1 and is equal to 24.
Look at the diagram below. Note that going from right to left, the number we are multiplying by increases by 1. That's our loop control variable (which I was calling idx today) because it is always incrementing by a set amount.
In each loop we multiply the product of the previous loop by the current value of the counter. So in loop 3 below we multiply 2 (which was the product from the previous loop) by 3 which is the counter value in loop 3. In loop 4, we multiply that value (6) by the counter value (which is now 4) to get 24. We exit our for loop when the counter reaches the value that we got from the user.
Tomorrow, we'll be looking more closely at Strings and some neat methods we
can use to manipulate them. Read pp 138 and 139 if you get the chance.
The difficulty (conceptually speaking) is how to implement this relatively simple piece of mathematics in a loop.
Let's look at 4!
4! is 4 * 3 * 2 * 1 and is equal to 24.
Look at the diagram below. Note that going from right to left, the number we are multiplying by increases by 1. That's our loop control variable (which I was calling idx today) because it is always incrementing by a set amount.
In each loop we multiply the product of the previous loop by the current value of the counter. So in loop 3 below we multiply 2 (which was the product from the previous loop) by 3 which is the counter value in loop 3. In loop 4, we multiply that value (6) by the counter value (which is now 4) to get 24. We exit our for loop when the counter reaches the value that we got from the user.
Loop 4 * 3 * 2 * 1
2 | | |___|
| | |
3 | 3 * 2
| |_____|
| |
4 4 * 6
|______|
|
24
Tomorrow, we'll be looking more closely at Strings and some neat methods we
can use to manipulate them. Read pp 138 and 139 if you get the chance.
Tuesday, October 7, 2008
Loop Tips
Here are a couple of pieces of advice regarding how to handle loops that arose from working with some of you today. Neither of these is always true. Consider them rules of thumb to be followed unless there's a reason not to.
- Always increment your counters at the bottom of the loop after your loop processing has been completed. This helps you to control any effects that your counters might have on your calculations.
- Report the results of loop calculations ouside the loop after it exits.
Please don't forget the homework for tomorrow. It's page 149, Qs 2, 4a, 7, 9, 10. It would also be helpful to re-read pp 135-137.
Finally, we'll also finish reviewing the test so bring your papers if you want to be able to track the corrections.
Wednesday, October 1, 2008
Gettin' Loopy
Today we had our first encounter with loops in the form of the while and the do...while loop. (pp 131-134 in the text) Here are a couple of things to remember about loops:
Homework for today? Why, yes, glad you asked. P149, Qs3, 5, and 6.
- the body of the loop (which can be one statement or many) keeps executing repeatedly (i.e. looping) while the loop condition remains true.
- the loop condition is the same type of Boolean expression as you find in the if and if...else statements
- the loop condition is evaluated (to see if it's still true or not) every time the loop iterates
- when the loop condition turns to false the loop stops executing and the program continues with the next statements after the loop
- an improperly formed loop can iterate infinitely. (Bad, bad, programmer.)
Homework for today? Why, yes, glad you asked. P149, Qs3, 5, and 6.
Friday, September 26, 2008
We spent some time on the board and the projector screen making sure that your understanding of conditionals is solid. You'll be using them all the time from now on so I want to make sure everybody's got it. Please make sure that you see me or email me if there's anything that you're unsure of about them.
Then we talked about compound Boolean expressions which sound more fearsome than they are. Compound Booleans or, if you'd prefer, compound conditionals, are just a simpler way to write what would otherwise be a series of nested if...else statements. Suppose we're trying to find people who are between the ages of 18 and 65 then we could write:
But wouldn't it be simpler to write:
In terms of hands on work we/you wrote the Discriminant application on p108 and Hurricane on p109. Discriminant supports the use of nested if...else and the idea that we can test for negative numbers by testing for less than zero. Hurricane gives practice using the switch statement.
If you haven't already, once those two are done, go on to do Delivery on p112. Delivery involves the use of compound Boolean expressions.
I forgot to ask you to do homework (bad teacher!) so if you're feeling all keen and want to get ahead, then do p121, Qs 1, 2, 3, 4b, 5 and 6 to really lock in your understanding of conditionals. Otherwise expect to do these questions on Monday night.
Then we talked about compound Boolean expressions which sound more fearsome than they are. Compound Booleans or, if you'd prefer, compound conditionals, are just a simpler way to write what would otherwise be a series of nested if...else statements. Suppose we're trying to find people who are between the ages of 18 and 65 then we could write:
if(age >= 18)
if age( <= 65)
System.out.println("You're in the right age group.");
But wouldn't it be simpler to write:
if((age >= 18) || (age <= 65))
System.out.println("You're in the right age group.");
In terms of hands on work we/you wrote the Discriminant application on p108 and Hurricane on p109. Discriminant supports the use of nested if...else and the idea that we can test for negative numbers by testing for less than zero. Hurricane gives practice using the switch statement.
If you haven't already, once those two are done, go on to do Delivery on p112. Delivery involves the use of compound Boolean expressions.
I forgot to ask you to do homework (bad teacher!) so if you're feeling all keen and want to get ahead, then do p121, Qs 1, 2, 3, 4b, 5 and 6 to really lock in your understanding of conditionals. Otherwise expect to do these questions on Monday night.
Tuesday, September 23, 2008
Nothing special today. We wrapped up the presentation on variables, Java arithmetic and constants and spent the balance of the class working on your GradeAverage and TempConverter applications. Most people seem to have found their way through it.
Let me stress how important it is to keep up to speed on the application side of things. Most of what we are and are going to be learning is cumulative. 'C' builds on 'B' which was built on 'A', etc. If you get too far behind you will have trouble absorbing the new material as it will assume you (mostly) grasp what has been done so far.
Tomorrow, I'll finish off checking your TempConverter and GradeAverage applications. If you haven't finished them you need to start coming to the lab early before class starts (I'm there every day by 8:40 at the latest and, so far, actually by 08:10) and/or requesting that I stay in the lab at lunch for you to catch up. That will be mostly up to you to initiate the extra help process.
What's on the agenda for tomorrows class? Conditionals. These are the programming constructs that allow your program to start making decisions. In other words, some of the interesting stuff.
A last note, I would really, really appreciate any feedback from you guys as to what is working for you (Yay!) or, more importantly, what is not working. You can use the comment section on the blog or just talk to me. Or leave an anonymous note.
Let me stress how important it is to keep up to speed on the application side of things. Most of what we are and are going to be learning is cumulative. 'C' builds on 'B' which was built on 'A', etc. If you get too far behind you will have trouble absorbing the new material as it will assume you (mostly) grasp what has been done so far.
Tomorrow, I'll finish off checking your TempConverter and GradeAverage applications. If you haven't finished them you need to start coming to the lab early before class starts (I'm there every day by 8:40 at the latest and, so far, actually by 08:10) and/or requesting that I stay in the lab at lunch for you to catch up. That will be mostly up to you to initiate the extra help process.
What's on the agenda for tomorrows class? Conditionals. These are the programming constructs that allow your program to start making decisions. In other words, some of the interesting stuff.
A last note, I would really, really appreciate any feedback from you guys as to what is working for you (Yay!) or, more importantly, what is not working. You can use the comment section on the blog or just talk to me. Or leave an anonymous note.
Monday, September 22, 2008
Testing, testing, 1, 2, 3
Homework for today is to read pages 105-110 in your text. We're starting what are called conditional control structures. This is the feature of the language that allows your program to make choices based on certain data. It's what allows your program to be responsive to input from outside itself.
OK. I tried to introduce number formatting using the NumberFormat class and confused the whatchamacallit out of you - for which I apologize. We'll go over it again at the top of tomorrow's class but here's some background.
I said that in order to use NumberFormat we needed to declare a NumberFormat object and I gave an example of such a declaration:
NumberFormat myFormattingObj = NumberFormat.getInstance();
The line of code above creates a new NumberFormat object called myFormattingObj.
I hesitated when saying that because I realized that it contradicted what I had previously told you (and what you'd just practiced in the test) about declaring new objects in Java. Marya picked up on in it right away. Shouldn't it be something like NumberFormat myFormattingObj = new NumberFormat();, she asked?
So, it turns out that there is special type of method in Java called factory methods whose particular job is to instantiate objects. (If you have 10 minutes at some point I can explain why it's a good thing to have such a special type.) The getInstance() method of the NumberFormat class is such a factory method. All it does is return a new object. Effectively, you could replace NumberFormatNumberFormat.getInstance(); in the declaration above with new NumberFormat(); For our purposes (and to the best of my understanding) it does exactly the same thing.
Aside from the mechanics of declaring an object using a factory method, it's probably confusing that you're declaring an object to do number formatting at all.
Think of myFormattingObject as like a small custom body shop or garage that you declare to do some work on your numbers.
First you create the body shop: NumberFormat myFormattingObj = NumberFormat.getInstance():
Then you tell the body shop how you want to customize your number: myFormattingObj.setMaximumFractionDigits(3);
This says to set the maximum number of digits to display to be 3.
Then you submit your number to the body shop to have the work done on it: myFormattingObj.format(numWithDecimal);
If your number was 5.678948, then the result of the the last bit of code would be 5.679.
OK. I tried to introduce number formatting using the NumberFormat class and confused the whatchamacallit out of you - for which I apologize. We'll go over it again at the top of tomorrow's class but here's some background.
I said that in order to use NumberFormat we needed to declare a NumberFormat object and I gave an example of such a declaration:
NumberFormat myFormattingObj = NumberFormat.getInstance();
The line of code above creates a new NumberFormat object called myFormattingObj.
I hesitated when saying that because I realized that it contradicted what I had previously told you (and what you'd just practiced in the test) about declaring new objects in Java. Marya picked up on in it right away. Shouldn't it be something like NumberFormat myFormattingObj = new NumberFormat();, she asked?
So, it turns out that there is special type of method in Java called factory methods whose particular job is to instantiate objects. (If you have 10 minutes at some point I can explain why it's a good thing to have such a special type.) The getInstance() method of the NumberFormat class is such a factory method. All it does is return a new object. Effectively, you could replace NumberFormatNumberFormat.getInstance(); in the declaration above with new NumberFormat(); For our purposes (and to the best of my understanding) it does exactly the same thing.
Aside from the mechanics of declaring an object using a factory method, it's probably confusing that you're declaring an object to do number formatting at all.
Think of myFormattingObject as like a small custom body shop or garage that you declare to do some work on your numbers.
First you create the body shop: NumberFormat myFormattingObj = NumberFormat.getInstance():
Then you tell the body shop how you want to customize your number: myFormattingObj.setMaximumFractionDigits(3);
This says to set the maximum number of digits to display to be 3.
Then you submit your number to the body shop to have the work done on it: myFormattingObj.format(numWithDecimal);
If your number was 5.678948, then the result of the the last bit of code would be 5.679.
Friday, September 19, 2008
Review for Monday's Test
Most of today was test review. [You know there's a test on Monday, right?] Please check the handout folder for a copy of the review handout (ICS3M_RvwNotes_1.doc) that we looked over in class.
I also asked a number of students (at random) to put questions from last night's homework on the board. No. one. (that I asked) had. done. it. Here's the threat. If no one sees fit to do the homework then I'm going to get all Grade 9-ey and start going round the class and checking homework and calling home and stuff. Let's not go there. Last warning.
On a lighter note, I mentioned a flash game that targeted the programming skill set. It's behind the school firewall but the link is here. It's neat and making it work does actually have something to do with programming skills. Check it out.
Last thing. I stumbled across this article on online literacy - or the lack thereof. The basic argument is that in spite of all the hopes that the "online experience" would produce a renaissance of literacy, the experience of consuming text online is somehow impaired. It certainly reflect my own experience consuming text online (and I spend a lot of time on the net). I'm all about loving computers and the massive uber-connectiveness that is the SeriesOfTubes but I'm also a long-time book reader from before the dawn of time (ca. 1966) with a big hardcopy library. There are some important ideas in the article.
Good luck on Monday. Have a good weekend!
I also asked a number of students (at random) to put questions from last night's homework on the board. No. one. (that I asked) had. done. it. Here's the threat. If no one sees fit to do the homework then I'm going to get all Grade 9-ey and start going round the class and checking homework and calling home and stuff. Let's not go there. Last warning.
On a lighter note, I mentioned a flash game that targeted the programming skill set. It's behind the school firewall but the link is here. It's neat and making it work does actually have something to do with programming skills. Check it out.
Last thing. I stumbled across this article on online literacy - or the lack thereof. The basic argument is that in spite of all the hopes that the "online experience" would produce a renaissance of literacy, the experience of consuming text online is somehow impaired. It certainly reflect my own experience consuming text online (and I spend a lot of time on the net). I'm all about loving computers and the massive uber-connectiveness that is the SeriesOfTubes but I'm also a long-time book reader from before the dawn of time (ca. 1966) with a big hardcopy library. There are some important ideas in the article.
Good luck on Monday. Have a good weekend!
Wednesday, September 17, 2008
Movin' On
Everybody pretty much finished up the ParseInteger program today. I'll post my solution soon.
We moved on to discuss typecasting and the situations in which it might be used and this led us to the notion that when typecasting a double to an int we should consider rounding the int values when doing it so as to preserve as much accuracy as possible.
We also discussed the order of arithmetic operations. Misunderstanding this order can lead to unexpected results in your programs. Be careful, it's a minefield out there, people.
There are two new applications to work on: GradeAvg and TempConverter from page 85 of the text.
There is also homework: page 97 Qs 6-10. I'd mentioned the possibility of doing Qs 13, 14, and 15 but we didn't get that far in the presentation today so we'll save them for later.
We moved on to discuss typecasting and the situations in which it might be used and this led us to the notion that when typecasting a double to an int we should consider rounding the int values when doing it so as to preserve as much accuracy as possible.
We also discussed the order of arithmetic operations. Misunderstanding this order can lead to unexpected results in your programs. Be careful, it's a minefield out there, people.
There are two new applications to work on: GradeAvg and TempConverter from page 85 of the text.
There is also homework: page 97 Qs 6-10. I'd mentioned the possibility of doing Qs 13, 14, and 15 but we didn't get that far in the presentation today so we'll save them for later.
Parsing the Integer; Hunting the Snipe
Today was all about consolidating yesterday's admittedly confusing foray into integer and modulus division. (Sorry!) It seems like most of you get it, now, and should be able to finish your ParseInteger programs tomorrow.
Many thanks to all those students who were able to finish early and then move on to help others.
If there's one thing I want you to take away from today, it's some hints about the thinking process that you can (and should!) go through when confronted with a difficult programming problem.
Many thanks to all those students who were able to finish early and then move on to help others.
If there's one thing I want you to take away from today, it's some hints about the thinking process that you can (and should!) go through when confronted with a difficult programming problem.
- Write down what you're supposed to do. Write it down, even if it's already given to you written down. The actual act of writing it down shifts your brain into the problem space.
- Write down what you know about the problem. Don't worry too much about how organized it is. If you have pieces of the puzzle put them down even if you don't know how they fit together. This is just a version of the kind of brainstorming you might do before writing and essay or short story in English or the kind of noodling a musician might do when approaching a composition.
- Get a high-level design down on paper - just the big, gross steps of what you think needs to happen in the program. E.g. Get some input; Process some input; Print some Output.
- I didn't talk about this but the fourth thing is to experiment. Hack at it. Try some stuff and see if it works.
Tuesday, September 16, 2008
Divided We Fall
See slides 8 through 11 of ICS3M_1.9_VarsConsts_2.ppt for what we covered today. (Basically integer division and modulus division.) Everyone started work on the project/assignment (call it what you will) that's on slide # 11.
Here's a hint:
Assuming the user has input 647 then:
647 / 100 ==> 6
47 / 10 ==> 4
7 / 1 ==> 7
The challenge is that although you get 647 from the user you have to figure out how to get the 47 and then the 1 in order to perform the integer division on them. Could modulus division be the answer?
HEAR YE! HEAR YE! HEAR YE!
Mini-test next Monday the 22 of September on what we will have covered by then. There'll be a review on Friday's class.
Here's a hint:
Assuming the user has input 647 then:
647 / 100 ==> 6
47 / 10 ==> 4
7 / 1 ==> 7
The challenge is that although you get 647 from the user you have to figure out how to get the 47 and then the 1 in order to perform the integer division on them. Could modulus division be the answer?
HEAR YE! HEAR YE! HEAR YE!
Mini-test next Monday the 22 of September on what we will have covered by then. There'll be a review on Friday's class.
Welcome to the ICS3M blog
Hi everyone,
Here's the plan. I'll use this space to put up announcements, homework and a brief summary of what we did on a particular day if it's applicable. Check in here if you were away and want to find out what to do.
Here's the plan. I'll use this space to put up announcements, homework and a brief summary of what we did on a particular day if it's applicable. Check in here if you were away and want to find out what to do.
Subscribe to:
Posts (Atom)