Friday, September 2, 2011

Cast down your integers where you are

Today we completed our review of casting numeric types.  We learned that when an explicit cast is involved, the cast operation performs first, then any mathmatical operations.  (This was the key to Wednesday's homework.)
We then started a review of code comments and escape character sequences, such as carriage return/line break (\n), double quotes (\"), single quotes (\'), tab (\t), and backslash (\\).
During class we discovered several online Java compilers - one of which we actually used in class.  I thought it was pretty neat.  The idea of being able to write and debug code on my iPad sounds pretty cool to me.  Among the tools that we found these stood out as being very promising:
One last note... During your X period today I wrote this little number.  Thought I'd share it with you all.  Feel free to compile it and see if it runs.  Have a good weekend.

import java.lang.*;
public class Program {

  public static class CompSciTeacher {
    public static String MoodDescription;
    public static int MinutesToCalmDown;
  }

  public static class CompSciClass {
    public static boolean wasChattingOnline = true;
    public static boolean isGoingToGetLotsOfHomeworkNextWeek;
 
}

  public static void main(String[] args) {
 
    if (CompSciClass.wasChattingOnline) {
        CompSciTeacher.MoodDescription = "poor";
        CompSciTeacher.MinutesToCalmDown = 5;
        CompSciClass.isGoingToGetLotsOfHomeworkNextWeek = true;
        System.out.println("The Computer Science class was chatting online.");
    }
    else {
    System.out.println("The Computer Science class was not chatting online.");
    }
   
    System.out.println("The Computer Science teacher is in a " + CompSciTeacher.MoodDescription + " mood.");
   
    if (CompSciTeacher.MinutesToCalmDown > 0) {
    System.out.println("It\'s going to take about " + CompSciTeacher.MinutesToCalmDown + " minutes for him to calm down.");
    }
   
    if (CompSciClass.isGoingToGetLotsOfHomeworkNextWeek) {
    System.out.println("Ouch.  Don't plan on seeing that new movie next week.");
    }
    else {
        System.out.println("Have a good weekend!");
    }
  }
}

1 comment:

  1. Dear Joshua,

    I wanted to thank you for posting the url of the site I been working (browxy.com) and also about the quote "very promising". :)
    I was developing it in my free time and weekends and due to positive feedback decided to add more features.
    On Nov 25th, released a new version with many features (save code, run interactive programs, compile and run applets and a feature to publish a program to a standalone public url). I'd love if you can give me some feedback to continue developing it. The idea of the project is a free service for everyone and a platform to teach programming and try stuff

    Thanks a lot
    David

    ReplyDelete