Tuesday, December 27, 2011

My Life in the Past Thirty Days

During the past thirty days or so, I went through what was the busiest and most work-loaded time of my life. I had to complete two reading journals, write and present a speech, create a 25-page picture book about Macbeth, prepare an application for a summer camp, finish building my bridge for physics class, write my English ISP essay, and... you get the idea. I also had to constantly review school materials at home because there was an unusually large amount of tests. As a result, I had almost no chance to take a break and relax myself.

Perhaps this was why I got sick on December 8th (I think?). So sick that I couldn't concentrate, couldn't think properly, couldn't even eat without vomiting afterwards! Consequently, I had to stay at home to recover, and to go to a doctor to do some checkups. Fortunately, I got better after two days, and the doctor couldn't find anything particularly wrong with me.

So, I resumed my school life, gradually caught up with my school work, and miraculously completed all assignments in the next two weeks. Unfortunately, just as I was about to celebrate the beginning of the winter break, I started sneezing and coughing! And as if these are not bothersome enough, I also had major nosebleeds for four days in a row.

Evidently, my life in the past thirty days hasn't been very pleasant or comfortable. I had a ton of school work, as well as many physical/health problems. However, now that it is the winter break, I am sure I can get myself back together, and have the next thirty days of my life completely different from the last thirty days of my life. 

Thursday, November 24, 2011

Busy, Busy, Busy

For the next few weeks or so, I will be extremely busy— busier than I ever was. I will have to complete four to six tasks each day, and each of them will take at least half an hour (and as much as 2-3 hours). So starting tomorrow, I must not even waste a minute on television, Internet-surfing, or games. I also have to make sure that I am constantly thinking about my projects so that they will not have poor qualities. Otherwise, my marks will suffer and my average will be even lower than it is now.

Rant: My English teacher is driving me crazy! Five *big* assignments in 20 days!? How's that giving us "ample amount of time" for each assignment?

Monday, November 21, 2011

Chemical Equilibrium #4: Manipulating the Equilibrium Constant (keq)

When calculating the keq of the reverse reaction:



When multiplying the entire equation by a number:



When adding several equations together:

Chemical Equilibrium #3: Equilibrium Constants

In a closed chemical system at constant temperature, there's a constant (keq) that defines the relationships between the concentrations of products and reactants.

Keq= (concentration of each product raised to a power of the coefficient of the corresponding product)÷ (concentration of each reactant raised to the coefficient of the corresponding reactant).

To make it more clear,

(where the lower case letters are the coefficients)


What keq tells:
Since keq is products over reactants, the larger it is, we know that the more products there are in the equilibrium (and vice versa). So a large keq (e.g., 1000000) means that the reaction is close to completion, and a very small keq (e.g., 0.00000001) means that the reaction barely occurs.

Chemical Equilibrium #2: Le Chatelier's Principle

Le Chatelier's Principle predicts what would happen to a system at equilibrium if certain conditions are changed. The general statement is:
If a chemical system at equilibrium experiences a change in concentration, temperature, pressure or volume, the equilibrium will be shifted to counteract this change, and a  new equilibrium will be established.
Now, let's break this statement down:

Change in Concentration
A + B ⇌ C + D

In the above reaction, if the concentration of C were increased, then the equilibrium must shift to counteract this change. In order to do so, the equilibrium will have to shift toward the reverse direction so that the excess C can be consumed.

If, instead, the concentration of C were decreased, then the opposite will happen. The reaction will have to shift toward the forward direction so that there can be more C.

Chemical Equilibrium #1: Introduction

What is equilibrium? 

Equilibrium is the state of a closed system at which two opposing reactions are simultaneously occurring at the same rate. In other words, in an equilibrium, the concentrations of all chemicals are constant.

(Note: even though the two reaction rates are equal to each other, it doesn't mean that the concentrations of the chemicals are equal)

Saturday, November 19, 2011

Chemistry: How to Solve Titration Questions

Strong Acid + Strong Base Titration
  1. Convert concentrations to number of moles
  2. Subtract the smaller n from the larger n
  3. Calculate -log (difference÷total volume)
  4. If the larger n is of the acid, the result is the pH. Otherwise, it's the pOH.

Weak Acid+ Strong Base Tritation

Thursday, November 17, 2011

Dream: What is Fibonacci?


This dream actually occurred a couple of nights ago, and its details have already faded away from my memory. However, I find the content of it to be quite significant, so I want to make sure that I record it before it is completely gone from my mind.

Novel for English Class

Today it was revealed that we'd be reading The Picture of Dorian Gray by Oscar Wilde as the novel for English class. Strange, because I am pretty sure that at the beginning of September, the teacher said that we'd be reading The Kite Runner by Khaled Hosseini.

But this is actually good, because I've already read The Kite Runner two years ago, and it would be sort of boring if I were to read it twice. Also, as The Picture of Dorian Gray has quite a high rating from various websites, I am looking forward to reading it.

So yeah, I hope I will be able to enjoy this book.

Thursday, October 27, 2011

Not Doing Well

Lately I haven't been doing well in physics, chemistry or English. (In other words, I am only doing well in math).

For physics, it's mainly because of my lack of effort: I spend almost all my time doing my English assignments, and as a result, I rarely complete my homework or do any studying. That's why so far all my test and quiz scores are in the 80s.

For chemistry, it's also because of my lack of effort. Yes, even though I know it is a grade 12 course, I haven't been putting a lot effort into it because I always thought the material was pretty easy. Also, all of a sudden the teacher started giving us difficult tests (in grade 11 I used to be able ace all the tests pretty easily), and started being extremely picky when marking communication questions.

As for English, even though I do put a lot of effort into it, I haven't been getting very good marks because I still don't know what the teacher expects of me. As a result, my writing and reading marks— which really should be pulling my mark up— are not very satisfactory. Also, there is an surprisingly huge amount of work for the course, so even though in total I do spend a lot of time on the assignments, the time spent on each individual assignment isn't as much as it could be.

I hope I will do better from now on.


Tuesday, October 25, 2011

Macbeth Comprehension Questions: Act 1 Scene 5

1. Who wrote the letter to Lady Macbeth? What does the fact that he wrote it indicate about their relationship?

  • It was Macbeth who wrote the letter to Lady Macbeth, and this indicates that they have a close relationship.

2. Whom does the letter not mention? What does this suggest?
  • The letter does not mention Banquo, and this can have many implications. For example, it may suggest that Macbeth does not care about Banquo; that in Macbeth's mind, Banquo is not important

3. What does Lady Macbeth almost immediately start to plan?
  • She immediately starts planning the killing of Duncan.

4. What does Lady Macbeth criticize about her husband?
  • She criticizes that her husband is too nice, that he is often too afraid to achieve what he wants.

5. What does Lady Macbeth reveal about her own character and personality?
  • She is evil, ambitious, cunning, and cold-hearted

6. Where do things stand at the end of the scene?
  • Lady Macbeth is ready to kill the king at night, whereas Macbeth is still wavering. 

Friday, October 21, 2011

Macbeth Comprehension Questions: Act 1 Scene 2

1. Who is Macdonwald? What happened to him?
  • He was the former Thane of Cawdor, who betrayed the Scotland. He was killed by Macbeth, sliced open from his navel to his jaw.

2. What does the description of Macbeth's action emphasize?
  • It emphasizes on his courage and bravery; how valiant he is

3. What other captain is fighting alongside Macbeth?
  • Banquo

4. Point out the irony in the captain's response to the king's question about whether Macbeth became dismayed by the army from Norway
  • The captain first responded that Macbeth was as afraid of the new troops as sparrows are afraid of eagles and as rabbits are afraid of lions. However, Macbeth was not scared at all, and he fought valiantly against the Norwegians and won. Therefore, the captain's first line of response was ironic. 

5. Who's the thane of Cawdor? What does the king say about him? How is the king going to reward Macbeth?
  • The thane of Cawdor is MacDonwald, and the king wants him executed. Macbeth is going to be awarded with the title thane of Cawdor

6. Based on what you've read, what are some of Macbeth's personal qualities?
  • He is brave, courageous, loyal, and merciless.

Thursday, October 20, 2011

Strategies for Proving Trigonometric Identities

From all the trig identity problems that I have solved, I have come up with these strategies:
  1. Convert everything to sine and cosine. In other words, get rid of the tangents, cotangents, cosecants and secants.
  2. Work with the more complex side first: it's often easier to simplify expressions that are complex than to make the more simple side equal to the more complicated one.
  3. Use common denominators: if the two sides have different denominators, how can they equal to each other?
  4. If the sines and cosines have 2 or 4 as their exponents, then try to use the identity sin2 θ + cos2 θ = 1 to simplify.
  5. Don't just work on one side: unless one of the sides is a simple value like "1" or "sin Î¸", it's usually a good idea to try to make the two sides meet in the middle.
  6. Factor: A lot of times it is important to factor, as this would often help simplifying the sides

Thursday, October 13, 2011

Seventy-Seven Percent


Today I got my English essay test back, which was a 17/22 (77%). However, as low as this mark was, I actually felt quite happy about it: I could have gotten a lot worse.

For the test, I basically had to read this article, identify the thesis and the methods of developments, and answer a variety of questions such as "why does the author find the happiness of Canada's teenagers disturbing?" And although this does not sound particularly difficult, it was.

For me, it was very hard to find the thesis, and even after reading the article for about five times, I still could not be sure about what the thesis was (and I got it wrong in the end). Also, for each question— opinion-based or not— we were required to provide evidence from the text. This actually made me a lot slower because then I had to find specific lines in the article, and copy them down to my answer sheet. In addition, the last question was an opinion-based paragraph worth five marks, and I found it difficult to make my arguments clear and strong.

So when I finished the test, I knew I did terribly: I was not sure on many questions, and the teacher could easily take one or two marks off of each question. I felt so afraid that I was going to actually fail the test, to the extent where I even had trouble sleeping well!

So when I saw that my mark was a 17/22—0.5 higher than the median— I felt extremely relieved and, even, happy.

Monday, October 10, 2011

Magnesium Oxide?


Today, when cooking lunch, I accidentally turned the wrong knob on the electric stove. As a result, in the few minutes that I was away, a cooking pot cover was being burnt.

Friday, October 7, 2011

Goals for the Rest of The Year

So, as the title has indicated has indicated, here are my goals for the rest of the year:

  • Exercise at least two hours every week
  • If nothing special comes along, memorize 20 vocabularies every weekday
  • Do all physics homework
  • Study properly before each physics and chemistry test
  • Perfectly solve each problem encountered in the programming team
  • Finish each English writing at least a day before it is due
  • Study the following topics for math:
    • Euclidean and analytic geometry
    • Trigonometry, including functions, graphs, identities, sine and cosine laws
    • Exponential and logarithmic functions
    • Functional notation
    • Systems of equations
    • Polynomials, including relationships involving the roots of quadratic and cubic equations
    • The remainder theorem
    • Sequences and series
    • Simple counting problems
    • The binomial theorem
    • Elementary number theory, including tests for divisibility, number of divisors, and simple Diophantine equations
  • Learn harder algorithms for programming
  • Make sure that I get a good sleep before each test


Blocking Websites

In grade ten, I often had to stay up late at night to finish assignments or projects that were due on the next day; I had poor time-management skills. And upon reflection, I realized that it was all because of the Internet: I simply spent too much time surfing the Internet or playing online games.

Therefore, in order to prevent myself from wasting too much time on the Internet, I have recently disabled—or blocked—websites such as youtube or online game sites by using hosts file.

The effect was instantaneous. Immediately, I found that I could do close to nothing on the Internet, and as a result I would either sleep (replenish my energy) or actually work on my assignments/projects. And ever since I have done so, I have never had to sleep later than 12:00.

I hope this would be enough to solve my problem of Internet addiction...

Wednesday, September 28, 2011

Annoyance

Today in math class my math teacher announced that we would have a math test on next Friday, and this meant that like last week, I will have three tests on the same day (along with chemistry and physics tests).

Obviously, having three tests on the same day is not particularly pleasant. Not only do you have to organize your time better and make sure that you allocate some time to study for each of the tests, you also have to make sure that you eat more and sleep better, for your brain will use up more energy on that day.

Monday, September 26, 2011

A Convenient Mistake

Occasionally, when I check out items from the library, an item would not be properly scanned and would appear on the library system as "in library" even though it is actually in my bag.

 Usually when such an event occurs, I would still return the book in a week or two, depending on when I finish it; I wouldn't intentionally not return the book just because I don't have to.

Today, however, is different. The novel in question is the novel that I will use for my English final project, and I will need it until the end of December. This means that I can just conveniently "forget" to return the book until three months later!

I am so fortunate that the staff has made this kind of mistake at the right time.

Friday, September 23, 2011

Grade 11 English ISP Book List

Today I got my English ISP, for which I have to read a Canadian novel, write five reading responses about the novel, and write a literary essay on it.

I also got to choose my ISP novel. The choices were as follows:

TitleAuthor
Oryx and CrakeMargaret Atwood
Year of the FloodMargaret Atwood
Green Grass Running WaterThomas King
The Concubine’s ChildrenDenise Chong
Life of PiYanna Martel
A Fine BalanceRohinton Mistry
Lullabies for Little CriminalsHeather O’Neil
Funny BoyShyam Selvaduri
Apprenticeship of Duddy KravitzMordecai Richler
The RomanticBabara Gowdy

Even though there were only 10 choices, it was hard for me to decide on my ISP book: none of them aroused  my interest. However, since there was a limit of five people per novel, I had to choose mine quickly, for the good ones may easily become unavailable. In a way it was like a huge sale in a store, where you needed to quickly grab an item before all the better ones got taken away by other people.

So I chose Oryx and Crake, for it was a dystopian novel and its description sounded more interesting than most others.

Added Note: ISP stands for Independent Study Project

Wednesday, September 21, 2011

Too Busy

Grade 11 is much harder than I had expected. Not only does it have a lot more assignments and tests than grade 10, each individual assignment is also a lot more demanding. As a result, three weeks into school and I am already struggling to finish everything on time!

With this kind of work load, I don't think I'll be able to update this blog very often. Besides posting my study notes (to prepare for quizzes or tests), I would probably only update this blog at most once per week.

So yeah, I hope things wouldn't get any worse.


Monday, September 19, 2011

Random Memory?

Ever since I started using the new computer, I have been carefully watching the available memory of my hard drive. Therefore, I can confidently say that during the past week or so, the amount of memory left has always been about 405 or 406 GB.

Then, today I downloaded some software needed for my printers, so naturally the amount of available memory should only decrease. However, when I checked the number, it actually increased to 411 GB!

I know, this increase in memory probably didn't have anything to deal with the printers. Still, it was strange that it had just suddenly increase. Perhaps it was because some temporary files got deleted, or...?

Saturday, September 17, 2011

What's The Problem?

For some reason, the seats that we chose in math class are never permanent. You can sit at spot A on one day, then on spot B and spot C for the next two days.

Anyway, yesterday, I arrived at math class slightly earlier and chose a seat that was closer to the board. Then, some ten seconds later, student M—  who was on friendly terms with me— asked me if I could move to another seat. Since he asked me very nicely, and I knew that he had always sat in that seat, I agreed to move. I didn't care about where I sat anyway, so there really was no reason for me not to give the seat to him.

So I moved back by two rows, from row three to row five. Then, a few moments later, student S, who sat in front of me (in row four), asked me why I had moved from row three to row five. I told him what happened, and suddenly he yelled "Why didn't you just stay there?"

Really, what was wrong with him? We were in no way friends, so that yell was definitely not meant as a joke. And, I really don't see how this switching spot thing was any of his business, and why he should care at all. So, this incident just confirmed that he was obnoxious, and made me dislike him even more.

Friday, September 16, 2011

Do Androids Dream of Electric Sheep?


This novel is set in a post-apocalyptic future in which the earth is almost uninhabitable because of a recent nuclear war. A lot of animals are extinct or nearly extinct, and a lot of humans have emigrated to Mars to ensure that the human race would not die of radiation. And, as an incentive for people to emigrate to Mars, the governments promised to give them free androids that would be their servants on Mars.

However, some androids have killed their masters and have secretly travelled back to earth, where they disguise themselves as regular humans. They are physically undistinguishable from real humans, and the only ways to tell them apart from real humans are to give them empathy-tests (robots are not empathetic) or to run tests using their bone marrows. Thus, it becomes very difficult for the police to hunt down these escaped robots.

The novel focuses on Rick Deckard, a bounty hunter whose job is to hunt the androids and "retire" (i.e., kill) them. He has to track these robots down, give them the empathy test (to make sure that they're robots), and then kill them using his laser gun. At the end,

Wednesday, September 14, 2011

English Homework

I am not sure if this is fortunate or unfortunate, but it really seems that this semester I will get a lot of work for English class.

My teacher gives (unmarked) homework almost every day, and if I were to put an honest effort into these homework, I'll need to spend about 30-60 minutes per day doing them. I also need to have two journal entries every week, and depending on the topic, I will need to spend perhaps two to three hours on each entry. That's a minimum of 6.5 hours per week!

And, of course, when the essays, presentations, and speeches come, the amount of hours spent on English class will just sky- rocket.

This amount of work is definitely higher than that of last year. In grade ten, I don't remember having to spend any time on English except when the assignments were almost due. Even though I did spent a lot of time thinking about what I was going to write for English, I definitely didn't have to spend a lot of time on the actual writings.

So, with this huge increase in the workload, I'll certainly have to manage my time a lot better.

Tuesday, September 13, 2011

Stoichiometry Note #5: Limiting Reactants

The Concept
Suppose that you need one cup of flour plus one egg to make a dozen cookies:
1 egg + 1 cup a flour→ 12 cookies

If you have 2 eggs and 2 cups of flour, then supposedly you would be able to make 24 cookies, right? But how many cookies will you be able to make if you have two eggs and ten cups of flour? Well, you can still only make 24 cookies.

How come? Well, in the second case, the egg was the limiting reactant. In other words, there was a shortage of eggs, and as a result even though there were still many cups of flour, no extra cookie could me made.

Carelessness

Yesterday in English class my teacher assigned us a paragraph to write. The instructions were as follows:
Write a well organized 200 word paragraph describing your opinion of whether or not you think the government has made getting a high school diploma too easy. Refer to what you know about late policies, credit recovery courses, the literacy test, summer school, and private school credits. 
She made this paragraph due the next day, so I spent literally the whole afternoon and evening working on the paragraph (yes, I think and write very slow). And, at ten o'clock, I finally finished it.

However, just as I was happily checking over my writing and the instructions, I noticed that I did the whole paragraph wrong: I did not make any references to the things that I was supposed to refer to!

So at ten o'clock, I had to start my whole paragraph over. And unfortunately, it wasn't until after midnight that I was able to produce my second and rushed paragraph.

This was very ironic, because in my first paragraph, I criticized that many students were bad at follow instructions...

Sunday, September 11, 2011

Parallel Lines: The Different Pairs of Angles

Note: This is more of a review for myself...

When two parallel lines are cut by a transversal line, eight angles will be formed, like this:

In such a situation, you can identify four types of angle pairings: alternate exterior angles, alternate interior angles, corresponding angles, and same-side interior angles.

Saturday, September 10, 2011

A Premonition

I was thinking about my classes, and I suddenly had a premonition that I would receive a horrible mark in English!

This feeling was not at all illogical, for from the first few days of school there were already a some signs that the teacher would not give me a very good mark. The first being the teacher giving a lot of creative assignments and oral presentations, and the second being the teacher being rigid and close-minded.

The Internet is a Playground by David Thorne


Well, what should I say about this book? It's basically a compilation of the articles and emails published on http://27bslash6.com/, and if you want to take a glimpse at the content, simply read one of the emails.

Personally, I liked reading the emails, for it was very interesting to see what people's replies to David Thorne's nonsense were. However, I skipped most of the other parts, for I found them to be extremely fake and boring. For example, in the parts where his friends described how they interacted with him, I simply had the impression that they were trying very hard to make their descriptions funny.

Friday, September 9, 2011

Fatigue


I've only been to school for four days, yet I'm already feeling great fatigue from it. Everyday during the fourth period, I would start feeling sleepy, and this feeling would continue to intensify until I arrive home (at four o'clock) from school, at which point I would feel so tired that I would not be able to concentrate on anything at all. Then, it wouldn't be another three hours until I finally feel more energetic.

I'm not sure, but I don't think it has always been like this. I certainly remember having this kind of feelings during last year's second semester, but before that, I can't recall ever feeling so tired after arriving home from school.

Thursday, September 8, 2011

Unreasonability

In the post from yesterday, I mentioned that today I was going to go to the guidance office to change my timetable a bit, and today I did indeed do so.

What exactly I wanted to change I will not describe in detail— for they're extremely complicated, and are full of reasons that would only make sense to myself— and I'll just tell you the main idea: I basically wanted to take one of my current courses online (instead of taking it during regular day school), and then replace that spot with a brand new course.

I was originally concerned about not being able to take a new course that I liked, for the courses that I liked may not fit into my schedule. It turned out, however, that I needn't have had such a concern, for there were actually quite a few courses for me to choose from.

Wednesday, September 7, 2011

First Two Days of School

Surprisingly, I don't have much to say about my first two days of school. What that means is, going to school didn't make me feel particularly happy and excited, and nor did it put me in a particularly bad mood.

I must say, though, that I was a bit disappointed by my teachers this year. Many of them are either not very good at teaching, or have reputations of being so. I felt that I was particularly unlucky, because whenever a course had several different classes, my teacher would always be the "worst" of all the possible teachers.

But perhaps fortunately, tomorrow or sometime this week I'll have to change my schedule a bit because of the summer course that I took. And if things go well, I can possibly have different (and better) teachers for some of my courses.

That's all I really want to say about these two days of school. And I hope that I will be happy about my time table change.

Tuesday, September 6, 2011

Stoichiometry Note #4: Molar Ratios

Previous: Molar Mass                                                               Next: Limiting Reactants

What are molar ratios? Well, they are comparisons between the quantities of (some or all of) the products and reactants in a chemical reaction. To make this more understandable, let's look at the reaction between iron (III) and oxygen gas:
4Fe + 3O22Fe2O3

In this reaction, we can say that every 4 atoms of Fe plus every 3 molecules of O2 makes 2 molecules of Fe2O3. We can also say that every 4 moles of Fe plus every 3 moles of O2 makes 2 moles of Fe2O3. Or, we can say that every 4 million atoms of Fe plus every 3 million molecules of O2 makes 2 million molecules of Fe2O3.

See how the ratio between Fe, Oand Fe2O3 is always 4: 3: 2 no matter how we change the units/quantities? Yes, indeed, 4: 3: 2 is the molar ratio between Fe, Oand Fe2O3! It's the ratio between the quantities used or produced in a "perfect reaction."

And, as you can see, the molar ratio is very easy to obtain—we basically take the coefficients of the products and reactants in a balanced equation, and put them together!

Now, let's use the molar ratios in another problem (answer is in white, in the brackets):
  • How many moles of O2 is needed to react with 8 moles of Fe so that 4 moles of Fe2O3 can be produced? Answer: ( ) moles

And a slightly more complicated problem:

Monday, September 5, 2011

My Summer (August) Plan: Failed

At the end of the July, I made a post about what I wanted to accomplish during the rest of summer vacation. And I miserably failed.

Here's the details (normal font=goal, bold=reality):

Stoichiometry Note #3: Molar Mass

Previous: Converting Moles to Molecules                                          Next: Molar Ratio

What is molar mass? Well, the idea is very simple— it's basically the mass of one mole of a specific atom or molecule. For example, oxygen has a molar mass of 15.999 grams per mole, and hydrogen has a molar mass of 1.0079 grams per mole. The symbol of molar mass is a capital M.

Finding the Molar Mass of an Element:
To find the molar mass of an element, you'd have to look it up on the periodic table. In the periodic table below, the molar masses are displayed below the symbol of each element:

click to enlarge


Calculating the Molar Mass of a Molecule
To calculate the molar mass of a molecule, you have to first find the molar mass of each individual element. Then, you have to multiply each molar mass by its element's subscript. After, add the values together and the molar mass of the molecule will be obtained. For example, to calculate the molar mass of water (H2O):
  1. Find molar mass of each element:
    • Oxygen : 15.999
    • Hydrogen :1.0079
  2. Multiply each molar mass by the subscript of the element (H2O1):
    • Oxygen: 15.999×1= 15.999
    • Hydrogen: 1.0079×2= 2.0158
  3. Add the results together:
    • 15.999+2.0158= 18.0148 grams/mole
Hopefully that's clear enough.

Internet Problems



This post was written yesterday, but I couldn't post it because my Internet connection didn't work...

Today my Internet connection had some problems, again. From 10 o'clock in the morning to 6 o'clock in the evening, I simply couldn't access anything on the Internet!

This problem is getting quite irritating, for it now arises at least once a week, and each time it can last from a few hours to a few days!

Really, what's wrong with Rogers? It's understandable if the Internet connection just stops working every few months. But every few days? That's far too frequent. At this rate, we should be getting some refunds!

EDIT: And when I was typing the post, it stopped working again! It's now 8:30, and let's see when it will work again...

EDIT: Didn’t work at 12 o’clock…

Saturday, September 3, 2011

Big Mouth


Some people just can't be trusted with secrets, for they simply can't control their mouths. Even if they have promised that they wouldn't tell anyone about the secrets, they eventually would.

I personally had one very unpleasant experience with one of these people.

About a few months ago, one of my friends suddenly asked me what my previous name was (I changed my name when highschool began). I didn't want to tell him— or anyone— about it, because I simply didn't like the name and didn't want people to associate me with that name. However, he kept pressing me about it, so eventually I told him, under the condition that he wouldn't tell anyone else.

But then a few weeks after, he suddenly started telling people what my previous name was. I gave him a warning glance, and simply denied what he said. However, he didn't take my cue, and kept telling people that he was sure what my previous name was. I was furious. If you could remember my previous name so clearly, why couldn't you remember your promise?

Windows Media Player: Shuffling Problem


I noticed that even when you have pressed the "shuffle" button in Windows Media Player, it still always starts with the first song in your list. In other words, Windows Media Player only starts shuffling the songs after the first song is played.

This is extremely annoying, for you don't always want to start with one particular song, especially if that song isn't one of your favourites.

So to solve this problem, I simply created a one-second media file, and made it the first item in my list. This way, this file would always be played first, and then one second later I would have a completed shuffled list.

If anyone wants to try this method, and doesn't know how to create an empty file, you can download one here.

Friday, September 2, 2011

Never Let Me Go by Kazuo Ishiguro

100 best english language books never let me go kazuo ishiguro

I didn't have high expectations of this book, for before I read it my mother had told me that this book was slow-paced and boring. And as I rarely liked slow-paced books, I really thought that I would probably toss this book away after about twenty pages.

However, after reading the first few pages, I was already drawn to the first-person narration, the extremely elegant prose. The narrator described the events in a calm but compelling manner, and I was stunned by how the Author, Kazuo Ishiguro, linked the events so beautifully together, transitioning from one event to another in such a smooth fashion.

Thursday, September 1, 2011

Blogger: Line breaks All Messed Up

Yesterday late at night, I suddenly noticed that blogger's posting page looked different. I remember how the "preview" button was gone, and how you the taskbar had fewer icons.

Then, I went to my Blogger page, and I noticed that my most recent post looked strange— the line breaks weren't working properly! At some places where there were supposed to be a line break, there were none, and on other places, the amount of line breaks got doubled! I quickly fixed the line breaks for that post and then went to sleep.

This morning, when I woke up, I noticed that my most recent post was reverted back to its messed-up state! Then I looked at my other posts, and found out that most of their line breaks were messed up too! I noticed that posts with pictures were especially likely to have this problem.

So I spent an hour going through (many of) my posts and fixing the line-break problems.

*sigh* Why do strange problems have to arise everyday?

Looking Back at Grade 10 Mathematics

I have always been good at math, and it has always been my favourite subject because it has few assignments and a lot of quizzes and tests that I can easily do good on. Also, math has always been my strongest subject, and it has almost always been the subject that I got the highest mark in (the time that I didn't, it was the teacher's fault...).

This year, however, was different. There were a lot of assignments from the class, most of them stupid and meaningless (see Stupid Assignments and What's the Point?), and it was very painful for me to finish them. Also, this year, the tests were not easy any more. Not because the material got harder, but because the teacher added so many extra things to the standard tests, making the tests a lot more time-consuming to finish (see relevance). I also became confused about the extent to which I should show my work (see Obvious? It's Subjective).

As you can see from the number of posts that I have made because of math class, I was very... stressed out about it. And as a result, I didn't like the subject as much as I used to. I still liked the actual classes (for there was one girl who was very funny), but thinking about "math" began to be less pleasant than before.

Interestingly, despite all this, math still ended up being my best subject. In fact, this math mark was the highest that I have ever gotten! Personally, I think I should have gotten 1-3 percent lower, for the teacher lowered the   denominator for many tests, but who cares...

As for the things that I have learned from the class...there was really only one new thing— trigonometric functions. All the other things, such as quadratic equations, I have learned before, and they were merely review for me (even though I did get better at them).

I hope grade 11 math will go well.

Go back to intro and a list of all posts in my grade ten reflection series

CS106A Computer Methodology: Files Now Available for Download

I have added a new page named CS106A Assignments that contains the list of problems that I have completed for the course. There, you would be able to download the source code files quite easily.

So why did I decide to do so? Well, on the pages that I explain the problems one by one (example), I wasn't able to get the page anchors to work (stupid Blogger...), and as a result it became quite troublesome to get to the sections at the bottom of the page. Also, the SyntaxHighlighter would sometimes not work for certain codes (the codes would mess up), and it'd look ugly if I were to post the codes without them being highlighted by the Syntax Highlighter.

Anyway, if you want to download the files, don't hesitate to do so!

Wednesday, August 31, 2011

CS106A Programming Methodology Problem Solutions: Assignment 2

EDIT: Source code files now available for download!
For full problem descriptions, click here.

Assignment two has a total of six problems, and the problems are considerably harder than those in assignment one. This is partly because of the introduction of the graphics program, and partly because of the introduction of return methods (for it creates a lot more possibilities for program decomposition). On the bright side, in this assignment we are allowed to use variables as well as various keywords (e.g., "break"), making it a lot easier to program.

Anyway, without further ado, I'll get to the problems:

Problem 1: Quadratic (Quadratic.java):
For this problem, you have to ask the user for the coefficients of a quadratic equation. Then, using the quadratic formula, your program should output the solutions. Or, if the equation has no solution, then your program should output a line saying so.

click to enlarge

This problem is very straight-forward.
//File: Quadratic.java
// --------------------
//This program is a stub for the Quadratic problem, which finds the
// roots of the quadratic equation.

import acm.program.*;

public class Quadratic extends ConsoleProgram {

	
	private void userInput() {
		//Get user input:
		println("Enter coefficients for the quadratic equation ");
		a=readInt("a: ");
		b=readInt("b: ");
		c=readInt("c: ");
	}
	
	private void printSolutions() {
		int  discriminant=b*b-4*a*c; //calculates number inside the root
		double firstSolution, secondSolution;

		//Display appropriate messages based on whether there are solutions
		if (discriminant<0){
			println("This quadratic equation has no real roots.");
		} else {
			//Calculate solutions
			firstSolution=(-b+Math.sqrt(discriminant))/(2*a);
			secondSolution=(-b-Math.sqrt(discriminant))/(2*a);
			//Output solutions
			println("The first solution is: "+firstSolution);
			println("The second solution is: "+secondSolution);
		}
	}
	public void run() {
		userInput (); //get the coefficients
		printSolutions(); //output message
	}
	
	//Private instance variables
	private static int a,b,c;

}



Problem 2: Find Range (FindRange.java)
 This program reads in a list of integers, one per line, until a sentinel value of 0 (which could be easily changed to some other value) is entered. Then, the program would output the largest and smallest integers from the list, excluding the sentinel. If the very first line of input contains the sentinel value, then the program should indicate so. And if the second line of input contains the sentinel value, the program should output the first integer as both the largest and the smallest integer.

click to enlarge

Although the program itself is simple, it is quite easy to make some logic errors. In fact, I had to fix my code a couple of times, for it failed a few certain cases.

//File: FindRange.java
//--------------------
//This program is a stub for the FindRange problem, which finds the
//smallest and largest values in a list of integers.


import acm.program.*;

public class FindRange extends ConsoleProgram {

	private static final int SENTINEL=0;
	
	//Intro: description of program
	private void intro () {
		println ("This proram finds the largest and the smallest numbers.");
	}
	
	//Gets user input until sentinel is entered
	private void userInput () {
		int input;
		while (true) {
		    input=readInt ("? ");
		 
		    //Exits when sentinel is entered
		    if (input==SENTINEL) {
			break;                 
		    }
		 
		    //Update values of maxNum and minNum if appropriate
		    if (input>maxNum||maxNum==SENTINEL) {
			maxNum=input;
		    }

         if (minNum>input||minNum==SENTINEL) {
			minNum=input;
		    }


		}
	}
	
	private void printResults() {
		
		//If the first input is the sentinel, then the boolean expression will
		//be false and no values will be output. If not, then the largest and
		//smallest numbers will be output
		if (minNum!=SENTINEL) {
		    println ("smallest: "+minNum);
		    println ("largest: "+maxNum);
		
		} else {
		    println ("No value was entered.");
		}
		
	}
	public void run() {
		intro(); //outputs program description
		userInput(); //gets a list of numbers from user
		printResults(); //Outputs the largest and smallest nums
	}
	
	//Private instance variables:
	private static int maxNum=SENTINEL, minNum=SENTINEL;
}




Problem 3: Hailstone (Hailstone.java)
 This program is extremely simple. You first take an integer from the user, then,
  • if the number is odd, multiply the integer by 3, then add one to the product
  • if the number is even, divide it by two
You then repeat this process until the resulting number is 1. At this point, the program will output the number of steps that the process took.

// File: Hailstone.java
//--------------------
//This program is a stub for the Hailstone problem, which computes
//Hailstone sequence described in Assignment #2.

//A while loop will do...	

import acm.program.*;

public class Hailstone extends ConsoleProgram {


	public void run() {
		int num;
		int count=0 ;//The number of steps it takes
		num=readInt("Enter a number: ");
		
		while (num!=1) {
			if (num%2==0) {
				print (num+" is even so I take half: ");
				num=num/2;
			} else {
				print (num+" is odd, so I make 3n + 1: ");
				num=num*3+1;
			}
			println(num);
			count++;
			
		}
		println("This process took "+ count+ " to reach 1");
	}
}



Problem 4: Target (Target.java)
 For this program, you basically have to draw three filled ovals centered in the screen:

// File: Target.java
// ------------------
//This program is a stub for the Target problem, which displays
//a target by adding concentric circles to the canvas.

//The only thing problem is that the final size might be off by one pixel because
//of rounding

import java.awt.Color;
import acm.graphics.*;
import acm.program.GraphicsProgram;

public class Target extends GraphicsProgram {

	private static final double INCHES_1=1, INCHES_2=0.65, INCHES_3=0.3;// the three radii
	
	public void run() {
		//Specify the radius (in inches) and color for each circle:
		addFilledCricleToCenter (INCHES_1, Color.red);
		addFilledCricleToCenter (INCHES_2, Color.white);
		addFilledCricleToCenter (INCHES_3, Color.red);
	}
	
	//This method adds a filled circle (with specified color and size) to the center of the canvas
	private void addFilledCricleToCenter (double radiusInInches, Color col) {
		int radiusInPixels= convertToPixels(radiusInInches); //convert radius to pixels
		int diameter= radiusInPixels*2; //calculate diameter
		int startX= (getWidth()/2)- radiusInPixels;  //The leftmost x-location of the circle
		int startY= (getHeight()/2)- radiusInPixels; //the topmost y-location of the circle
		
		//create filled circle with the appropriate attributes, and add it to the canvas:
		add(fillOval(startX, startY, diameter, diameter, col));
		
	}
	
	private int convertToPixels (double inches){
		return (int)(Math.round(inches*72));
	}
	
	//This method creates a filled oval with the appropriate color, location and size
	private GOval fillOval (int x, int y, int width, int height, Color col) {
		GOval oval= new GOval(x, y, width, height); //Create oval with the appropriate size and loc.
		oval.setColor(col); //Change colour
		oval.setFillColor (col); //change colour
		oval.setFilled(true); //make it a filled circle
		return oval;
	}
}



Problem 5: GraphicsHierarchy (GraphicsHierarchy.java)
This program should output something similar to the image below:


The diagram should always be centered in the screen regardless of the width and height of the boxes. Also, the texts should be centered in the boxes. This was probably the program that I worked the longest on, for I am pretty slow at centering objects. It also took me quite a while to simplify the code and make it more general. But besides that, there wasn't any complicated logic needed to code this program.
//
// File: GraphicsHierarchy.java
//----------------------------
//This program is a stub for the GraphicsHierarchy problem, which
//draws a partial diagram of the acm.graphics hierarchy.


import acm.program.*;
import acm.graphics.*;

public class GraphicsHierarchy extends GraphicsProgram {
	
	private static final int BOX_HEIGHT=50, BOX_WIDTH=200;
	private static final int VERT_DISTANCE=40, HORI_DISTANCE=50; // The horizontal and vertical distance between any two adjacent boxes
	

	public void run() {
		assignValues(); //Assign values to the variables that hold the coordinates of the boxes
		
		drawBoxes();
		drawLines();
		
		addLabel("Program", centerBoxX, topBoxY);
		addLabel("ConsoleProgram", centerBoxX, bottomBoxY);
		addLabel("GraphicsProgram", centerBoxX-(BOX_WIDTH+HORI_DISTANCE), bottomBoxY);
		addLabel("DialogProgram", centerBoxX+(BOX_WIDTH+HORI_DISTANCE), bottomBoxY);
	}
	
	private void assignValues() {
		//the console window will only be created after the run method is called, and before that, the height and width will both be
		//zero. Therefore, to get the following three variables to have proper values, the values must be assigned in a method.
		topBoxY=getHeight()/2-(BOX_HEIGHT*2+VERT_DISTANCE)/2;
	    bottomBoxY=getHeight()/2+ VERT_DISTANCE/2;
		centerBoxX=(getWidth()-BOX_WIDTH)/2;
	}
	
	//Add the labels. StartX and startY are the coordinates of the top-left corner of the rectangle that they're in
	private void addLabel(String labelText, int startX, int startY) {
		GLabel lab= new GLabel (labelText, startX, startY); //Create label
		lab.move ((BOX_WIDTH-lab.getWidth())/2,(BOX_HEIGHT+lab.getAscent())/2 ); //move to center	
		add(lab); //add to canvas
	}
	
	//Draw the lines
	private void drawLines() {
		//All three lines branch out of one point, and startX and startY are the coordinates of that point
		int startX=getWidth()/2;
		int startY=(int)((getHeight()-VERT_DISTANCE)/2);
		
		//Draw the three lines
		for(int i=-1; i<=1; i++) {
			add(new GLine(startX, startY, startX+i*(BOX_WIDTH+HORI_DISTANCE), startY+VERT_DISTANCE));
		}
		
	}
	
	//Draws the four boxes
	private void drawBoxes () {
		//The box at the top:
		add(new GRect(centerBoxX, topBoxY, BOX_WIDTH, BOX_HEIGHT));
		
		//The boxes at the bottom
		for (int i=-1; i<=1; i++) {
			add(new GRect(centerBoxX+(BOX_WIDTH+HORI_DISTANCE)*i, bottomBoxY, BOX_WIDTH, BOX_HEIGHT));
		}
	}
	
	//Private instance variables:
	//These are the variables that hold the coordinates of the boxes. See "assignValues" method for more info.
	private static int topBoxY;
	private static int bottomBoxY;
	private static int centerBoxX;
}


Problem 6: Pyramid (Pyramid.java)
With the specified brick width, brick height, and number of rows, the program should output a pyramid like the one below, centered in the screen.

// File: Pyramid.java
// ------------------
// This program is a stub for the Pyramid problem, which draws
// a brick pyramid.


import acm.graphics.*;
import acm.program.*;

public class Pyramid extends GraphicsProgram {
	
	private static int BRICK_WIDTH=18;
	private static int BRICK_HEIGHT=10;
	private static int BRICKS_IN_BASE=35;
	
	public void run() {
		
		//Draw the rectangles row by row, from the bottom row to the top row
		for (int i=BRICKS_IN_BASE; i>=1; i--) {
			int yLocation=getHeight()-(BRICKS_IN_BASE-i+1)*BRICK_HEIGHT-1;
			fillRow (yLocation, i);
		}
	}
	
	private void fillRow (int yLocation, int numOfBricks) {
		int startX=(getWidth()- numOfBricks*BRICK_WIDTH)/2; //the x-Location of the leftmost brick
		//Use for loop to draw the bricks
		//!!!Code continued at the bottom because of the syntaxHighlighter's glitch!
This is the rest of the code:
for (int i=0; i<numOfBricks; i++) { add(new GRect(startX+i*BRICK_WIDTH, yLocation, BRICK_WIDTH, BRICK_HEIGHT)); } } }

I Hate Computers...


Arr!! Why do computers have to be riddled with errors, glitches and bad designs!? After I started using the new computer, I began to pay close attention to its various details, trying to fix any problem that I spotted and change any settings that seemed inconvenient or illogical. And I found that I probably spent at least one and a half hour a day finding solutions for these problems!

Five days ago, I spent hours trying get Microsoft Word to work. On the same day, the icons for certain files stopped displaying correctly, and it took me one to two hours to fix that problem. On the next day, I spent one or two hours just to change the colour of the taskbar. Yesterday, I had to to spend one hour before bed to fix a directory problem. And today, I spent nearly three hours to get the video thumbnails to display correctly, and one hour to find a way to edit the properties of certain glitched files!

Really, why couldn't the developers make the interface a bit more user-friendly, and make more effort to ensure that the system worked without glitches? It is just unacceptable that so many problems arose in just a few days! Even worse, all these problems were difficult to fix, and they all had some obscure solution!

I am exhausted by all the Internet-searching, program-downloading, registry-editing, and rebooting needed to fix the problems. Arrrrrgggg!!

Monday, August 29, 2011

I'm Back (again)

For the past four days, I was away from home, for my family went to another city to help my sister get ready for university.

During those days, I did have access to the Internet, for my family actually brought a laptop. However, I didn't get very much time on the Internet— during the day we would be busy doing other things, and during the night my parents would need the computer to look up for various information— so I couldn't update the blog.

Now that I'm back, I'll be updating the blog again. :)

Thursday, August 25, 2011

The Children of Men by P.D. James



The Children of Men by P. D. James was a wonderful book. After reading the first page I was already drawn to the setting— a world with no fertile man, and therefore no children as well.

Because of this lack of posterity, the world was much different. People no longer cared for technological innovations— except for technologies that will bring pleasures or extend people's lives; most students ended their educational career at the undergraduate level; a form of public suicide called the Quietus emerged; and many people began to have dolls and/or cats as substitutes for children. Also, people no longer cared about political reform—the world was going to end soon anyway— and as a result Britain was ruled by a dictator.

Anyway, the main character, Theodore Faron, by chance got involved with a small rebellion group, and later found out that one of the members of the group was pregnant. He then went on a mission to try to protect this woman so that the baby could be delivered before the woman fell into the hands of the dictator.

Problems with Microsoft Word


Yesterday afternoon I finally finished reading The Children of Men by P. D. James, and decided to use the night to update this blog.

Unfortunately, a terrible thing happened which stopped me from doing so— Microsoft Word 2000 stopped working! Every time I tried to open the program, it would freeze when the program license thing was being displayed. In other words, it would stop responding even before a blank document was opened.

Actually, it would be wrong to say that Microsoft Word had stopped working, for I wasn't even sure if it had ever worked... Yes, that's right— the computer was only a few days old and I have never created a word document on it before. And since I wasn't even sure if it had ever worked, it was hard for me to tackle the problem— I couldn't tell whether it was an installation problem, a compatibility problem (Word 2000 on Windows 7), a licensing problem, or some other type of problem.

Monday, August 22, 2011

The Left Hand of Darkness by Ursula le Guin


I was very excited to read The Left Hand of Darkness, which was partly because that I really liked the author's—Ursula's Le Guin's short story The Ones Who Walk Away From Omelas, and partly because the title sounded extremely interesting. Also, the novel had quite a good reputation, so I was sure that I was going to like this book.

But unfortunately, the novel disappointed me— I did not like it very much.

Friday, August 19, 2011

Should I Transfer?


Today it was finally confirmed that my family would be moving. Not to another city or country, just to another location in the city.

So a question arose: Should I transfer to another school because of the change in location? From my new home, it would take me about twenty minutes by bus to get to my current school. That's not bad at all, but it's worse than the twelve-minute walk that the new close-to-home school would require. Also, I should mention that the new close-to-home school is a very good and popular school which you can't get in unless you live nearby, and this adds another incentive for me to transfer.

However, obviously there are still a lot of reasons for me to stay at my current school, and therefore I have decided to make a detailed comparison between the two schools. For the comparison, I shall call the new close-to-home school school B for simplicity.

Wednesday, August 17, 2011

Looking Back at Grade 10 History

Before the start of second semester, I did not look forward to having history at all. Not only did the subject not interest me, the prospect of having tons of essays and other creative assignments was also unpleasant. Furthermore, I had heard that it was very difficult to get a high mark in history class, so this was one more reason for me not to look forward to the class.

Then, second semester started, and my lack of interest soon turned into strong dislike.

I remember how frightened I was after we spent the first two classes just to introduce ourselves to each other, and the third class to do a group presentation (which was unmarked). It was dreadful to think about how future classes would be, because the first three classes were already filled with my top three dislikes about a class—group work, presentation, and wasting time.

Fortunately, things got better very soon. We began to take notes, and interactions between students became a lot less frequent. Sure, the classes were boring—a lot of the time the teacher was answering stupid questions such as "Where is the Atlantic Ocean?"—but at least it was bearable. Also, most of the things that we learned in the class were things that I did not know before, and this made me quite glad.

And, for some reason, we never did the "creative" assignments! We did not have to write a letter and dip it into tea to pretend that it was written sixty years ago, nor did we have to pretend to be women during WWII, trying to create shopping lists. I was extremely relieved that we did not have to do these assignments.

We did, however, have two major group presentations. But surprisingly, I did very well in both of them! I suppose it was because of the amount of time that I was given to prepare, as well as the group members with whom I did the the presentations.

And as expected,

Tuesday, August 16, 2011

The Handmaid's Tale by Margaret Atwood

The Handmaid's Tale is a famous dystopian novel written by Margaret Atwood. The story takes place in the Republic of Gilead, which is a totalitarian theocratic society that was formerly the United States. In this society, there is a large number of females that are sterile, and as a result there is a group of fertile women whose sole role is to reproduce. These women are the Handmaids.

The narrator of the book is herself a Handmaid, and through her accounts, we learn about the lives of Handmaids, which are quite dull and uneventful. We also learn about the other roles in the society, such as the Commanders, the Wives, the Aunts, and the Eyes. Furthermore, through the narration, we learn about the values and beliefs of the society, as well as what the society considers to be unlawful. In short, by reading about the narrator's life, we get to know how her society functions.

Unfortunately, I didn't particularly like this book. It wasn't bad, but it was a bit boring. To me the whole book was unexciting, and it just wasn't suspenseful. So I only finished this book because I was looking forward to some kind of surprise.

Also, for some reason, I just couldn't feel for the main character. I found her to be rather passive and detached, and many of her problems were those that I could not possibly face during my lifetime (for I am a male). In short, I simply didn't feel connected to the story or the characters, and as a result the book didn't leave a big impression on me.

Monday, August 15, 2011

CS106A Programming Methodology Problem Solutions: Assignment 1

EDIT: Source code files now available for download!
For the full assignment problem descriptions, click here.

Assignment one has four problems, and to be honest none of them is hard. Still, it took me quite a long time to complete all of them, for there were such strict restrictions on the operators and programming structures that I could use. For instance, I wasn't even allowed to have variables, do-while loops, or the ! and && operators! As a result, some of the solutions weren't as neat as they could have been.

 Anyway, here are my solutions to the problems:
 Problem 1: Collect Newspaper Karel (CollectNewspaperKarel.java)



This problem is extremely simple. As shown in the image above, you basically have to write a program that will let Karel pick up the beeper and return to his orginial position. The world will always be the same, so there's no need to include any if structure at all. Just a straight-forward program that directly tells Karel what to do.
import stanford.karel.*;

public class CollectNewspaperKarel extends SuperKarel {

 public void run() {
   moveToNewsPaper();
   pickUpNewsPaper();
   returnToStartingPoint();
  
 }
 
 //Karel picks up the newspaper
 private void pickUpNewsPaper() {
  pickBeeper();

 }
  
 //Karel returns to original position
 private void returnToStartingPoint() {
  turnAround();
  for (int i=0; i<3; i++) {     move();   }      turnRight();   move();   turnRight();     }    //Karel exits the room and gets to the newspaper  private void moveToNewsPaper() {   turnRight();   move();   turnLeft();      for (int i=0; i<3; i++) {     move();   }     }  }  


Problem Two: Stone Mason Karel (StoneMasonKarel.java)


This problem is also very straight-forward. You basically have to create a program that will make Karel fill up the columns (i.e., 1,5,9,13...).
import stanford.karel.*;

public class StoneMasonKarel extends SuperKarel {

 public void run() {
  repairCurrentColumn();
  while (frontIsClear()){
   repairNextColumn();
  }
 }

//Pre-condition: Karel is at the upper-end of a column, facing North
//Post-condition: Karel is at the lower-end of a column, facing east
public void backToOriginalPosition(){
  turnAround();
  while(frontIsClear()){
   move();
  }
  turnLeft();
}

//Pre-condition: Karel is at the lower-end of a column that may needs to be repaired, facing east
//Post-condition: Karel is at the same position, and the entire column is repaired
public void repairCurrentColumn (){
  turnLeft();
 
  while (frontIsClear()){
   if (noBeepersPresent()){
    putBeeper();
   }
   move();
  }
  //This is to repair the last bit of the column
  if (noBeepersPresent()){
   putBeeper();
  }
 
  backToOriginalPosition();
 
}

/*Pre-condition: Karel is at the lower-end of a certain column that has already
  been repaired, and there is an unrepaired column to the right
 *Post-condition: Karel is has moved to and repaired the adjacent column that is
  east of that certain column, and is at the lower-end of it
 */
public void repairNextColumn(){
  goToNextColumn();
  repairCurrentColumn();
}

//Pre-condition: Karel is facing east, at the bottom on a column, and there is another
//column to the right
//Post-condition: Karel has moved eastward, onto the next column
public void goToNextColumn(){
  for (int i=0; i<4; i++){
   move();
  }
}
}



Problem 3: Checkerboard Karel (CheckerboardKarel.java)


For this problem, you have to create a checker pattern for any given world (even a 1*1 square). Took me a little while to figure out how to decompose this problem.
import stanford.karel.*;

public class CheckerboardKarel extends SuperKarel {

 public void run() {
  finishRow();
  while (frontIsClear()){ //If there's a next row, then finish that row
   goToNextRow();
   if (frontIsClear()){ //In case that the world is a one column-world
    finishRow();
   }
   
  }
   
 }
 
 //Pre-condition: Karel is at a square where a beeper needs to be in place
 //Post-condition: The whole row that the square is in is now completed.
 public void finishRow(){
  putBeeper();
  
  //Put down a beeper every other step
  while (frontIsClear()){
   move();
   
   //If structure in place to ensure that
   //Karel doesn't run into a wall
   if (frontIsClear()){
    move();
    putBeeper();
   }
  }
  faceNorth();
 }
 
 //Pre-Condition: Karel is facing east or west
 //Post-Condition: Karel is facing north
 public void faceNorth (){
  if (facingEast()){
   turnLeft();
  }
  else{
   if (facingWest()){
    turnRight();
   }
  }
 }
 
  //pre-condition: Karel is facing north, with at least
  //a wall beside it
 
  //Post-Conidtion: Karel is facing east or west, with a wall
  //right behind it
                   
 public void turn (){
  
  //The following assignment
  if (leftIsClear()){
   turnLeft();
  }else{
   turnRight();
  }
 }
   
    
  
 
 
 //Pre-condition: There is at least one row above the row that Karel is currently in
 //Post-condition: Karel has moved onto the next row, to a space that needs a beeper
 //                (Exception: when it is in a one-column world, he may move by two rows
 //                instead)
 
 //How this method works:
 //Suppose Karel is at point K. If there is a beeper at point K, Karel will move to
 //point X. Otherwise, it will move to point Y
 //...........XY
 //............K
 
 public void goToNextRow(){
  if (noBeepersPresent()){
   move();
   turn();
  }
  else{
   move();
   turn();
   
   /*If this condition is not satisfied, it means that the world is only
   one-column wide. In this case, Karel will move onto the next available row
   (if there is one)*/
   if (frontIsClear()) {
    move();
   }
   else{
    //Move onto the next row if there is one
    faceNorth();
    if (frontIsClear()) {
     move();
    }
    
   }
    
  }
 }

}



Problem Four: Midpoint Finding Karel (MidpointFindingKarel.java)


The goal of this program is to be able to let Karel find and stop at the midpoint of any given width. The first time it took me more than 1.5 hours to finish all the coding, so I was beyond miserable when the whole file got accidentally deleted. Fortunately, the second time it only took me about 10 to 15 minutes.
import stanford.karel.*;

public class MidpointFindingKarel extends SuperKarel {
//My algorithm is quite simple. running the program and reading the comment lines
//should be enough for you to understand
 
public void run() {
  layBeepers(); //Put one beeper in each square in the row
  cleanUpBeepers(); //Alternately remove one beeper from each end. This way Karel will
         //be removing the beeper at the middle square last
  putBeeper(); //Put one beeper back in the middle square

}

//Put one beeper in each square of the row
public void layBeepers(){
  putBeeper();
  while (frontIsClear()){
   move();
   putBeeper();
  }
  turnAround(); //Turn around so that Karel is facing the center
}

//Only move if front is clear
public void moveIfSafe(){
  if(frontIsClear()){
   move();
  }
}

//Pre-condition: Karel is facing west or east
//Post-condition: Karel is facing south
public void turnSouth(){
  if(facingEast()){
   turnRight();
  }else{
   turnLeft();
  }
 
}

//Turn around, move one space (if possible), and then pick up the beeper (if possible)
public void turnAroundAndPickBeeper(){
  turnAround();
  moveIfSafe();
  if (beepersPresent()){
   pickBeeper();
  }
}

//The purpose of this method is basically to let Karel pick up a beeper from the opposite end
public void pickUpEndBeeper(){
  while (beepersPresent()){//Karel keeps walking until there isn't a beeper at his
                        //location or until he reaches the wall
   if (frontIsClear()){
    move();
   }
   else{
    pickBeeper();
    turnSouth();//Turning south is a signal for "already picked up a beeper)
   }
  }
 
  if (frontIsClear()){
   turnAroundAndPickBeeper();//Turn around and pick up the beeper located at the end
  }
  else{
   if (facingSouth()) //If Karel has already picked up a beeper, then he will
                   //simply change direction
   {
    faceCenter();
   }
   else{
    turnAroundAndPickBeeper();//If not, he will pick up the beeper at the end
   }
   
  }
  
}

//Let Karel face the center
public void faceCenter(){
  if (rightIsClear()){
   turnRight();
  }else{
   turnLeft();
  }

 
}

//Karel alternately picks up a beeper from each end. Eventually, Karely will stop at the
//middle square
public void cleanUpBeepers(){
  while (notFacingSouth()){
  
   pickUpEndBeeper();
   moveIfSafe();
   if (noBeepersPresent()){//If this is satisfied, it means that all beepers have been
                        //cleared
    //Move back to the middle square:
    turnAround();
    moveIfSafe();
    turnSouth();//Since no variable can be used, facing south is the only way
                //to break out of the while loop
   }
  }
 
}
}