Tuesday, January 6, 2015

Tuesday, January 6th

Today was the first day back from winter break.  When I left school for the holiday, I ended doing strings. To tell the truth, I didn't do anything that had to do with coding over the pause. When I came back, I was a bit rusty with what I left off with: the strings, which I had only learned one or two classes before the class. For a while on my first problem, I was confused, so I needed Mr. Daly's help a lot.

But after a while I got the hang of it. I did a few string problems in Logic 1, and finished Logic 1 completely. After that, Mr. Daly taught me about Arrays. I think that I understand the general idea of what arrays are, but I'm not 100% sure exactly, which is why today I won't be doing a problem with arrays. Next class I will, once I have worked more with arrays, but for today I will just be showing a string problem:

With this next problem, I had a lot of trouble completing it. I needed Mr. Daly's help for this. I imagined that I would be using a lot of strings, but in fact I only needed a small part of the solution to be strings, and the rest was easy stuff that I knew beforehand.



Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off". 

public String alarmClock(int day, boolean vacation) {
 
  if (vacation)
   {
     if (day == 0 || day == 6)
    {
      return "off";
// if we're on vacation, and it's either day 0 (sunday) or 6 (Saturday), then we don't want the alarm to be on.
     }
      else
      {
     return "10:00";
// otherwise, if we're on vacation but it isn't the weekend, then we want to wake up at 10:00 during the week.
     }
  }
 
   else
// if we're not on vacation
   {
      if (day == 0 || day == 6)
    {
      return "10:00";
// if it's not vacation, and it is the weekend (day 0 or 6), then we want the alarm to wake us up at 10:00.
     }
     else
     {
     return "7:00";
// it's not vacation, and it's a weekday so we have work. wake up at 7:00.
     }
   }
}


So now I have learned what strings and arrays are. My goal for the end of the semester is a bit far fetched, but I will try to get as far as possible in completing both String 1 and Array 1.

No comments:

Post a Comment