Posts

Showing posts from August, 2013

Young Coders: Week 3 Problem

EDIT: Just one extra Candy Challenge problem this week!  The full Candy Challenge = the following problem + two Candy Challenges from previous classes.  For those of you who have finished all the previous Candy Challenges, pick two problems from Week 2's 3,4, and 5, and try to solve them iteratively (with loops),  instead of recursively.  Write a toString() method for our Queue class that prints out its elements.  For example,  public static void main(String[] args) {    Queue animals = new Queue();           animals.enq("Tiger");     animals.enq("Pig");     animals.enq("Zebra");          System.out.println(animals);  } will give us {"Tiger", "Pig", "Zebra"} , not the hashCode() we have now (something like Queue@56ee20fe).  (An example: Look at the outline of a toString() method we wrote in the Pet class.) 

Young Coders: Week 3 Notes

Image
Yesterday, we learned about classes and some data structures.  Classes A “specification” or “blueprint” that says how to construct an object. Here is the Pet class we made:  public class Pet {  //fields  public String name;   public String color;  public int legs;   public int speed;   private int pinNum;   //constructor  public Pet (String name, String color, int legs, int speed) {    this.name = name;    this.color = color;    this.legs = legs;    this.speed = speed;     pinNum = 1111;   }  //methods  public int getPin() {   return pinNum;    }  public void setColor(String color) {    this.color = color;   }  public void exercise(int increase) {    speed += increase;      color = "red";   }  public void sleep() { ...

Interactive Data Story of Forbes Top 100 Celebrities

Image
When looking at the  table of "The World's Most Powerful Celebrities" , compiled by Forbes, it is hard to get insights like the relationships between celebrities and the factors they are ranked by.  I decided to create a project  using D3.js  to do some exploration.  In the project I tried to find how the celebrities' social networking power related to their marketability. I grabbed the data from  Forbes . I added categories (Actors, Actresses, Athletes, etc) so certain groups can be compared with each other. Hovering over the points revealed their names and jobs. (Labels by each point would be too cluttered.)  Here is the story from the data ...

Young Coders: Week 2 Problems

Candy Challenge! Finish at least 3 out of 5 of the following problems correctly to win candy/chocolate. Email your solutions to me, plus two or three of your favorite types of candy/chocolate. 1) Using a Scanner, read in 10 integers into an array. Print out “positive” if most of them are positive. Print out “negative” if most of them are negative. Print out “balanced” if five of them are positive and five of them are negative. (Assume none of the integers are zero.)  2) Read in 5 integers into an array using a Scanner. Print out the numbers shifted left by one.  For example, {1,2,3,4,5} becomes {2,3,4,5,1}  (EDIT: Please solve 3, 4, and 5 recursively!)  3) Create a method called power that takes two parameters: base and exp. It returns the value of base to the exp power. For example: power(2,3) = 8 power(5,3) = 125 power(4,0) = 1 4) Create a method called remove that takes one parameter: a String. It returns the same String, except all the ...

Young Coders: Week 2 Notes

Image
Loops, Arrays, Methods, and Recursion Loops If statements are one way to control how your program flows. Loops are another way. When you need the computer to execute code over and over, use loops! We looked at two types of loops.  A while loop won’t stop until its condition(s) is false. public class WhileLoop1{     public static void main(String[] args) {        int i = 1 ;        while (i <= 10 ) {          System.out.println(i);           i++;        }     } }

Young Coders: Week 1 Problems

Candy Challenge! Finish at least 3 out of 5 of the following problems correctly to win candy/chocolate. Email your solutions to me, plus two or three of your favorite types of candy/chocolate. If you have any questions about the problems themselves, ask in the comments below this post. 1) Read in two Strings using a Scanner. Print them out in an alternating pattern. For example, if the user inputs “hot” and “cold”, print out “hotcoldhotcold”. 2) Read in a String using a Scanner. Print out the first three letters. If the String’s length is less than three, just print out the String. 3) Read in a String using a Scanner. Print out the second half of the word. For example, if the word is “hooray”, print out “ray”. Assume the word’s length is an even number. 4) Read in a String using a Scanner. Print out the word without its first and last letter. For example, if the word was “computer”, print out “ompute”. ...

Young Coders: Week 1 Notes

Image
We started out by learning how to declare and initialize a variable in Java:  We then looked at if statements: 

Parallel Summing Without Threads

Image
Calculating the sum of an array of numbers is a simple task:       sum = 0;        for each number in an array           sum += number;  However, summing is an important primitive function of databases and other applications, and needs to be sped up when the size of the array increases to a huge number such as 100M+. Using threads is probably the first impulse since this is such an easily parallizeable problem. But for a smaller array, such as one containing 10 numbers, multi-threading will make a summing function slower than the naive version because of the extra resources used. So, how can a summing function be implemented so that it is always faster than the naive version? To answer that question, let's first understand how the machine works.  Memory Hierarchy