Thursday, October 27, 2011

Challenge 025

An instance variable is defined in a class in which each object has their own separate copy. All instances are within a constructor function and can be assigned a unique value without modifying the values of other copies of the instance variable.

In this class, there are three instance variables. These three specific instance variables are name, gender, and yearOfBirth. Each of these instance variables contain a copy value.

Two addition instance variables for this code could be weight and shoe size.
The code for these are as follows:

public class Person
{

private String name;
private String gender;
private int yearOfBirth;
private int weight;
private int shoeSize;


public Person()
{
name = "unknown";
gender = "other";
yearOfBirth =0;
weight = 0;
shoeSize = 0;
}

public Person(String n, String g, int year, int weight, int shoeSize)
{
name = n;
gender = g;
yearOfBirth = year;
weight = pounds;
shoeSize = inches;

}


//BOOM!

Challenge 024

The statement in question should be inserted right before the last curly brace on the code. However, the statement in question should read Person person1 = new Person(name, "female", 2000);. She skipped the statement all together. when you aren't sure of the name, you should input the code name because in the previous section of code, it tells us that name = "unknown". The gender "female" must be inserted next because the code must be written in order (name, gender, 2000) because the public Person(String n, String g, int year). Female is also written in quotes because it is a string. Lastly, 2000 is inserted as an int value because she defines person1 as born in the year 2000. This will help Lauren define person1 without error

Wednesday, October 26, 2011

Challenge 023

Constructors are awesome!!!

Constructors give you the option to alter the bug within certain parameters. You can click on the frid to construct or manipulate and actor (bug).

info.gridworld.actor.Bug(java.awt.Color) is a constructor. When clicking on this constructor inside the world, you are able to change the parameters of the bug. For example, you are able to change the color of the bug. You are also able to alter the bug by clicking it and getting a list of constructors. From here, you can move the bug to a specific coordinate location on the grid, you can alter the color, turn the bug, etc.

Since you are able to click on each individual box in the grid, it leads me to assume that there are as many constructors as there are squares in the grid?

Tuesday, October 25, 2011

Challenge 022

import info.gridworld.actor.ActorWorld; //First you need to import all the gridowrld files
import info.gridworld.grid.Grid;
import java.awt.Color;
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;

public class GWTest {
public static void main(String[] args) {
ActorWorld Overgrown = new ActorWorld(); //This names and creates the world in which the bugs are a part of
Bug Yellow = new Bug(Color.YELLOW); // This creates a bug that is yellow
Yellow.setDirection(Location.SOUTHWEST); // This sets the bug to be pointed in the southwest direction
Location Y = new Location(5,4); // This sets the yellow bug to the grid coordinate (5,4)
Overgrown.add(Y, Yellow); // This adds the yellow bug to the grid
Bug Magenta = new Bug(Color.MAGENTA); // This creates a bug that is yellow
Magenta.setDirection(Location.SOUTHEAST); // This sets the bug to be pointed in the southeast direction
Location M = new Location(5,5); // This sets the magenta bug to the grid coordinate (5,5)
Overgrown.add(M, Magenta); // This adds the magenta bug to the grid
Bug Blue = new Bug(Color.BLUE); // This creates a bug that is blue
Blue.setDirection(Location.NORTHEAST); // This sets the bug to be pointed in the northeast direction
Location B = new Location(4,5); // This sets the blue bug to the grid coordinate (4,5)
Overgrown.add(B, Blue); // This adds the blue bug to the grid
Bug Green = new Bug(Color.GREEN); // This creates a bug that is green
Green.setDirection(Location.NORTHWEST); // This sets the bug to be pointed in the northwest direction
Location G = new Location(4,4); // This sets the freen bug to the frid coordinate (4,4)
Overgrown.add(G, Green); // This adds the green bug to the grid
Overgrown.show(); // THis allows you to view the world
}
}

Wednesday, October 12, 2011

Challenge 019

int result = 13 - 3 * 6 / 4 % 3;

This string gives you an output of 12.

you follow order of operations so:

3 * 6 = 18
18 / 4 = 4.5 ; since result is declared an integer, 4.5 is truncated to simply 4
4 / 3 = 1 with a remainder of 1 ; because of the % , this results in a value of 1
13 - 1 = 12

12 is the result and remains an integer.

Monday, October 10, 2011

Challenge 018

(1) double answer = (double) 13/5; will give him an answer of 2.6 because he is calling for the ddt of 13/5 which equals 2.6 because when you divide a double by an int, you get a double value.

(2) double answer = 13 / (double) 5; will give him an answer of 2.6 because we are naming 5 a ddt. When dividing an int by a double, you get a ddt answer.

(3) double answer = 13.0 / 5; will give him an answer of 2.6 because you again are dividing a double by an int, resulting in a double answer. When only 13.0 is stated, the compiler knows that this is intended to be a ddt.

(4) double answer = 13 / 5.0; will give him an answer of 2.6 because you are again dividing an int by a double, resulting in a ddt. When only 5.0 is stated, the compiler knows that this is intended to be a ddt.

(5) double answer = (double) (13/5); will NOT give him an answer of 2.6 because you are taking the quantity (13/5) and then taking the result and making it a double, with a result of 2.0

Challenge 017

All of the follow statements are true.

(A) This statement is true because !A is true and according to Morgan's Law, ! (X && !Y) is the same thing as !B || C . Therefore, !B is true.


(B) This statement is true because it requires only A , B , or C to be true. These are all true because they start off false but are true because of the !.


(C) This statement is true because !( A || B || C) means that they are all true because you distribute the ! within the parenthesis. While only one need to be true, they all are.


(D) This statement is true because after distributing the ! to each variable, all of the variables become true. The && calls for all of the variables to be true, so this statement is true.


(E) This statement is true because either A , B , or C need to be true. !A is true so this statement is true.

Challenge 016

System.out.print("\\* This is not\n a comment *\\");

The output of this statement is:

\* This is not
a comment *\


The \\ is an escape character which basically means that when two back slashes are inserted, only one is outputted when it is in a String[] statement.. The quotation tells the compiler to output the statement within itself. The reason that it is two separate lines is because of the \n . This tells the compiler to move the following characters to the next line.

Challenge 015

I) double x = 14.7;
int y = x;
System.out.print(y);

An error occurs because we name x a DDT (Double data type) and in the next line, we are switching it to an int value when claiming y = x. In order to fix this, we need to change the second line to double y = x to produce the output of 14.7


II) double x = 14.7;
int y = (int) x;
System.out.print(y);

The output produced is 14. we claim x to be a DDT and then in the next line we are saying make the integer value of y equal to the integer value of x. This is basically truncating the 14.7 to produce 14. The ddt is simply canceled due to (int) x;


III) int x = 14;
double y = x;
System.out.print(y);

This set of statements produces a value of 12.0. Since y = x , then y =14. However, it is calling for a ddt which makes it a double. With a double comes a decimal. A zero is added because we already declared the y = 14 so .0 applied.

Friday, October 7, 2011

Challenge 013

When the bug is located in the Northeast corner of a bounded grid and facing North, it... turns 180 degrees(45 degrees at a time) and heads south. While the bug moves, it drops flowers behind it that turn darker and darker each time the bug moves one unit. When it reaches the south east corner, It turns -90 degrees and heads east continuing its behavior. when it reaches the south west corner, it heads north.

The bug continues to drop flowers that darken as the bug moves. The bug never leaves the boarder of the grid and continues traveling in a clockwise motion that is never ending and never gets interfered with.

Challenge012

All of these Statements output a result of 1234.

1) System.out.print(12 * 100 + 34)

This outputs 1234 because it is outputting what is inside the parenthesis. So, 12 * 100 = 1200 1200 + 34 = 1234


2) System.out.print("12" + 34)
The "x" tells the compiler to output the value that is enclosed within the quotations. so the compiler will automatically output 12 as the first value because it is the first listed. Then 34 is the next output because nothing is being added to 34. 12 isnt being added because it has already been outputted because it is within the quotations. so 12 then 34 [1234]


3) System.out.print(12 + "34")
This is similar to the 2nd output. it outputs only 12 because nothing is being added to it because 34 is within the quotations. since 12 is listed first, 12 is output with 34 following. 12 and 34 [1234]

Monday, October 3, 2011

Challenge 011

The reason that this will not compile is because the term static must be inserted after public and before double goFigure (int n). without the term static, goFigure is useless to use.

The output turns out to be 2.0 12. It is asking for the double data type so that explains why it is 2.0. It also says create a space when it say System.out.print(" " + n); and then to add n which we declared was 12. So you have the 2.0 print out and the 12 print out.

The next line tell us that n is equal to the amount of time that 7 goes into into. Keeping in mind that n previous was declared 12, 7 goes into 12 about 1 time with a remainder of 5. n = n % 7; since it call for n being an int earlier, 12/5 is rounded down to 2. It then calls for a double data type which turns it into 2.0.

Therefore, you have 2.0_12.

Sunday, October 2, 2011

Challenge 004

I like how He is not in favor of kids being taught things on an endless basis, but rather play with things and discover on their own. I thought that was worth stating because isnt that what we are doing in this experience?

I myself am not huge on the idea of evolution, but I found this video extremely interesting. I think it is a great idea to get kids involved with learning and ideas early. Playing games as a kid is never boring, and parents will never be disappointed when their child is learning. Its a win win situation. He then goes on to show us how they can use their imaginations by designing their own creature. He is all about "the player's imagination," which I think is great because isn't that how everyone we have seen on TED has came up with their idea? From imagination? You have to start somewhere and I think that an interactive game is a great place to start.

I 100% support Him when he talks about how he wants to focus on long-term thinking and how most of the problems in the world are amplified by short term thinking. I do see that we are now trying to look long-term especially when it comes to the Earth's ozone, atmosphere, and general health. For example, creating hybrids and trying to eliminate as many green house gases as we can is a great place to start.

Challenge 001

To start off, I think that Ray Kurzweil is a great speaker and tries to be somewhat inspirational which is what this generation needs. In my opinion, I think that the biggest debatable idea with all types of topics likes these is the ethics behind this. You will always get people that say yes and no. To me, the only thing that really matters is what the government has to say about it because if they say no, then its not happening; end of story. If they say yes, then ethic conversations will be held.

My problem with most of these videos is how they all say that they "have the tools." I think its great what they are doing, dont get me wrong, but I want to see it work. I want to see proof that they have created something to overcome disease and poverty. The idea is great, but I want to see it happen. I also think it is great about how he talks about how people see technology in the future as linear when it was really exponential. I personally didnt think about how technology will be absolutely vital in the future. Ray talked about analyzing the sequence of HIV. He then continues to talk about how they MAY be able to overcome all these problems.

I think what these scientists are doing is great, I just want to see it happen. I want to be able to complete a 15 minute olympic sprint without taking a breathe and want to sit in the bottom of a pool for four hours.