Monday, July 28, 2008

On your blog

Please write about the relationship between data structures and algorithms.

A data structure is a way of storing data in a computer so that it can be used efficiently, often allowing for the most efficient algorithm to be used. A well-designed data structure allows a variety of critical operations to be performed, using as few resources, both execution time and memory space, as possible.

What is the difference between a stack and a queue?

A stack lets you insert and remove elements from the top of the stack using what is referred to as Last In First Out (LIFO) order while a queue lets you insert data at one end and remove it from the other end using what is referred to as First In First Out (FIFO) order.

Pick two sorting algorithms and explain how they work.

Insertion sort - a simple sorting algorithm that sorts an array/or list via comparison. It is less efficient on large lists.

Selection Sort - a sorting algorithm, specifically an in-place comparison sort. It is inefficient on larger lists, and performs worse than the insertion sort.

Final Major Project

What are you working on or planning to do for your last project? Major project 5.

I am currently working on a GUI based application that calculates a person's gross and net pay based on hours worked and current rate of pay. It will also take into account overtime if the employee worked over 40 hours. I will also attempt to implement other things such as the tax based on the employee's state and their marital status and number of dependants.

Monday, July 21, 2008

Using recursion....

How could you use recursion to find the smallest value in an array? Don't write out Java code, just write out the pseudocode.

Create an array from which to pull values from.
Create a recursion method that compares two values from the array at a time.
Through process of elimination, only keep the least number of the current comparisons you are making, pairing values off after larger values have been eliminated until you are left with the smallest value.

Use paint to describe the steps in solving the Tower of Hanoi


Click on image to see sequence.

Friday, July 18, 2008

Blog Reaction - Sourceforge.net

Blog reaction:

I'd like you to pick another project using Java (search for Java), download it, and check out the source code. Put your reactions to the site (http://sourceforge.net/) and the code you downloaded on your blog.

I went to Sourceforge.net and started looking in the games section as I like video games. I looked at two in particular. One was Doomsday Engine and the other was Mega Mario. Doomsday Engine is an add-on to the original Doom games that updates the graphics. As interesting as this was, it did not include any source code. I then checked out Mega Mario as that based on a very popular game series, the Super Mario Bros series. Part of the code looks like this:

/********************************************************************
Mega Mario SRC
created: 2005/09/18
created: 18:9:2005 10:13
author: Jens Wellmann (c)
*********************************************************************/


#include "Global.h"
//#include
#define M_PI 3.141592654

#define JUMPS 12
#define STEP_DEFAULT 4

int counta=0;
cPlayer::cPlayer(int LEFT,int RIGHT,int UP,int DOWN,int B,int A,int _speed_jump_height)
{
x = 200;
y = 3000;
incincible = 0;
Surface_R[0][0] = LoadIMG(DATADIR "gfx/characters/small/player1r.png");
Surface_R[0][1] = LoadIMG(DATADIR "gfx/characters/small/player2r.png");
Surface_R[0][2] = LoadIMG(DATADIR "gfx/characters/small/player3r.png");
Surface_L[0][0] = LoadIMG(DATADIR "gfx/characters/small/player1l.png");
Surface_L[0][1] = LoadIMG(DATADIR "gfx/characters/small/player2l.png");
Surface_L[0][2] = LoadIMG(DATADIR "gfx/characters/small/player3l.png");
Surface_R[0][3] = LoadIMG(DATADIR "gfx/characters/small/downr.png");
Surface_L[0][3] = LoadIMG(DATADIR "gfx/characters/small/downl.png");
Surface_R[1][0] = LoadIMG(DATADIR "gfx/characters/big/player1r.png");
Surface_R[1][1] = LoadIMG(DATADIR "gfx/characters/big/player2r.png");
Surface_R[1][2] = LoadIMG(DATADIR "gfx/characters/big/player3r.png");
Surface_L[1][0] = LoadIMG(DATADIR "gfx/characters/big/player1l.png");
Surface_L[1][1] = LoadIMG(DATADIR "gfx/characters/big/player2l.png");
Surface_L[1][2] = LoadIMG(DATADIR "gfx/characters/big/player3l.png");
Surface_R[1][3] = LoadIMG(DATADIR "gfx/characters/big/downr.png");
Surface_L[1][3] = LoadIMG(DATADIR "gfx/characters/big/downl.png");
Surface_R[2][0] = LoadIMG(DATADIR "gfx/characters/fire/player1r.png");
Surface_R[2][1] = LoadIMG(DATADIR "gfx/characters/fire/player2r.png");
Surface_R[2][2] = LoadIMG(DATADIR "gfx/characters/fire/player3r.png");
Surface_L[2][0] = LoadIMG(DATADIR "gfx/characters/fire/player1l.png");
Surface_L[2][1] = LoadIMG(DATADIR "gfx/characters/fire/player2l.png");
Surface_L[2][2] = LoadIMG(DATADIR "gfx/characters/fire/player3l.png");
Surface_R[2][3] = LoadIMG(DATADIR "gfx/characters/fire/downr.png");
Surface_L[2][3] = LoadIMG(DATADIR "gfx/characters/fire/downl.png");
K_LEFT = LEFT;
K_RIGHT = RIGHT;
K_UP = UP;
K_DOWN = DOWN;
speed_jump_height = _speed_jump_height;
K_B = B;
K_A = A;
STARPOWER_OVER = 1;
walkcount = 0;
walkcount2 = 0;
walkadd = 1;
y_speed = 0;
x_speed = 0;
JUMPcount = 400;
dead = 0;
STARPOWER = 0;
stat = 0;
W = 38;
H = 42;
Aed=0;
Bed=0;
invincible=200;
}
#define CAMRANGE 300
#define CAMRANGE_H 200
void cPlayer::movecam()
{
if(cam_x>0&&xcam_x+WIDTH-CAMRANGE)
cam_x = x-WIDTH+CAMRANGE;
if(ycam_y+HEIGHT-CAMRANGE_H)
cam_y = y-HEIGHT+CAMRANGE_H;
if(cam_x<40) cam_x =" 40;">16000 - WIDTH)
cam_x = 16000 - WIDTH;
if(cam_y<40) cam_y =" 40;"> 4000 - HEIGHT)
cam_y = 4000 - HEIGHT;
}
void cPlayer::update()
{
if(invincible)
invincible--;
if(x<100) x =" 100;">15500)
x = 15500;
if(y > 4000)
this->die();
movecam();
if(!touch_now)
down_touch = LEVEL->posValid(x+3,y+3+H) + LEVEL->posValid(x+W-3,y+3+H);
else
down_touch = 1;
top_touch = LEVEL->posValid(x+3,y) + LEVEL->posValid(x+W-3,y);
left_touch = LEVEL->posValid(x+x_speed-1,y+H/1.25) + LEVEL->posValid(x+x_speed-1,y+H/4);
right_touch = LEVEL->posValid(x+W+x_speed+1,y+H/1.25) + LEVEL->posValid(x+W+x_speed+1,y+H/4);
touch_now = 0;
if(LEVEL->posValid(x,y+3+H)==33(LEVEL->posValid(x+W,y+3+H)==33))
if(!right_touch)x+=3;
if(LEVEL->posValid(x+20,y+3+H)==32(LEVEL->posValid(x+W,y+3+H)==32))
if(!left_touch)x-=3;
if(bonus_activ<0)>BonusCheck(x+5,y,x+W-5,y);
else bonus_activ--;
if(y_speed>=0)
{
if(!down_touch)
{
y += y_speed;
if(y_speedButton_B)
{
max_speed = 8;
if(!Bed&&stat==2)///////NEW FIREBALL!!!!!!!!!!!!!
{
#define FIRESPEED 3
if(dir)
{
if(!FIREBALL[0]->init(x,y+35,FIRESPEED))
FIREBALL[1]->init(x,y+35,FIRESPEED);
}
else
if(!FIREBALL[0]->init(x,y+35,-FIRESPEED))
FIREBALL[1]->init(x,y+35,-FIRESPEED);
}
Bed=1;
}
else
{max_speed = 4;Bed=0;}
///JUUUUUUUUMP
if(keys[K_A]Gamepad->Button_A)
{
if(Aed==0&&JUMPcount==400&&down_touch)
{
jumpheight = JUMPS+abs(x_speed*1.4);
PLAYSOUND0(S_JUMP);
JUMPcount = 0;
}
if(JUMPcountdown)
{
if(!KeyDown_down)
{
y+=H-34;
H = 34;
walkcount = 3;
}
KeyDown_down = 1;
}
else
{
if(KeyDown_down)
{
walkcount = 0;
H = (stat==0) ? 42 : 75;
y-=H-34;
KeyDown_down = 0;
}
}
if((keys[K_LEFT]Gamepad->left)&&!KeyDown_down)
{
x_speed -= 0.2;
dir = 0;
MakeMyWalk();
}
else if((keys[K_RIGHT]Gamepad->right)&&!KeyDown_down)
{
x_speed += 0.2;
dir = 1;
MakeMyWalk();
}
else
{
max_speed = 4;
if(x_speed<-0.04) { x_speed+=0.05; if(!keys[K_DOWN]&&!Gamepad->down)MakeMyWalk();
}
else
if(x_speed>0.04)
{
x_speed-=0.05;
if(!keys[K_DOWN]&&!Gamepad->down)MakeMyWalk();
}
else if(walkcount!=3)walkcount=0;
}

if(x_speed>=max_speed)
x_speed = max_speed;
else if(x_speed<=-max_speed) x_speed = -max_speed; if(x_speed<0) x_speed =" 0;" x_speed =" 0;" x =" (int)x" y =" (int)y" 6 ="=">init(x/40,y/40 +1,0,-10);
STARPOWER--;
invincible = STARPOWER;
for(int i=0;iDEATHcount&&!GOOMBA[i]->dying && collision(&rect,&GOOMBA[i]->rect))
{
GOOMBA[i]->die();
}
for(int i=0;idead&&!TURTLEFLY[i]->dying && collision(&rect,&TURTLEFLY[i]->rect))
{
TURTLEFLY[i]->die();
}
for(int i=0;idead&&!TURTLE[i]->dying && collision(&rect,&TURTLE[i]->rect))
{
TURTLE[i]->die();
}
for(int i=0;idead&&!SPINY[i]->dying && collision(&rect,&SPINY[i]->rect))
{
SPINY[i]->die();
}
for(int i=0;idead&& collision(&rect,&KILLERBLUME[i]->rect))
{
KILLERBLUME[i]->dead=1;
SCORE->init(KILLERBLUME[i]->x,KILLERBLUME[i]->y,250);
BLOOD_GENERATOR->newBlood(KILLERBLUME[i]->x,KILLERBLUME[i]->y);
PLAYSOUND2(S_KICK);
}
STARPOWER_OVER = 0;
}else{
if(!STARPOWER_OVER)
{
if(nosound==2)
playMusic("megamusic.mid");
STARPOWER_OVER=1;
}
}
for(int a=0;a<5;a++) x="LEVEL-">EXITPOINTS[a].x - cam_x + 5;
tmp_rect.y=LEVEL->EXITPOINTS[a].y - cam_y;
tmp_rect.w = 10;
tmp_rect.h = 20;
if(LEVEL->EXITPOINTS[a].type == 1 )
if(!keys[K_DOWN]&&!Gamepad->down)
continue;
if(collision(&rect,&tmp_rect))
{
PLAYSOUND2(S_PIPE);
//rect.x = H =tmp_rect.x-10;
for(int n=0;n<30;n++)>BGCOLOR);
LEVEL->drawBackground();
if(LEVEL->EXITPOINTS[a].type == 1)//DOWN
PLAYER->y+=2;
else if(LEVEL->EXITPOINTS[a].type==2)//RIGHT
PLAYER->x+=2;
else if(LEVEL->EXITPOINTS[a].type==3)//LEFT
PLAYER->x-=2;
else if(LEVEL->EXITPOINTS[a].type==4)//UP
PLAYER->y-=2;
tmp_rect.x = PLAYER->x-cam_x;
tmp_rect.y = PLAYER->y-cam_y;
SDL_UpperBlit(PLAYER->Surface_R[PLAYER->stat][0],0,screen,&tmp_rect);
LEVEL->drawLevel();
drawGLscreen();
SDL_Delay(10);
}
LEVEL->loadLevel(LEVEL->EXITPOINTS[a].level,LEVEL->EXITPOINTS[a].startpoint);
}
}
}
void cPlayer::MakeMyWalk()
{
walkcount2++;
if(walkcount2 >= 10 - (int)(abs((int)x_speed)))
{
if(walkcount==2)
walkadd = -1;
else
if(walkcount == 0)
walkadd = 1;
walkcount+=walkadd;
walkcount2=0;
}
}
#define DELAYTIME 100
void cPlayer::changeStat(int staty)
{
if(STARPOWER)
return;
y-=40;
if(stat<=staty) { PLAYSOUND1(S_GROW); invincible = 0; } else { invincible = 400; PLAYSOUND1(S_SHRINK); } stat=staty; if(stat==0) { W = 38; H = 42; } else { W = 38; H = 75; GLIDDER->init(this->x/40,this->y/40,5,3);
GLIDDER->init(this->x/40,this->y/40,0,0);
GLIDDER->init(this->x/40,this->y/40+1,0,0);
GLIDDER->init(this->x/40,this->y/40+1,0,0);
GLIDDER->init(this->x/40,this->y/40+1,0,0);
}
}

void cPlayer::draw()
{
if(STARPOWER)
{
SDL_LockSurface(screen);
for(int i=100;i<100+starpower/2;i++) x="100;x<110;x++)">newBlood(x,y);
return;
}
if(down_touch)
{
if(dir)
{
SDL_UpperBlit(Surface_R[stat][walkcount],0,screen,&rect);
}
else
{
SDL_UpperBlit(Surface_L[stat][walkcount],0,screen,&rect);
}
}
else
if(dir)
{
SDL_UpperBlit(Surface_R[stat][2],0,screen,&rect);
}
else
{
SDL_UpperBlit(Surface_L[stat][2],0,screen,&rect);
}
}
void cPlayer::die()
{
if(y < invincible =" 30;">reset();
PLAYSOUND1(S_DIE);
LEVEL->drawBackground();
LEVEL->drawLevel();
int speed = 8;
if(show_blood)
for(int i=0;i<200;i++)>oneNewBlood(x,y);
BLOOD_GENERATOR->oneNewBlood(x,y);
BLOOD_GENERATOR->oneNewBlood(x,y);
BLOOD_GENERATOR->oneNewBlood(x,y);
BLOOD_GENERATOR->update();
drawGLscreen();
framerate();
}
else speed = 4;

for(int i=0;i=4)
ani = 0;
center_touch = LEVEL->posValid(x,y+2) + LEVEL->posValid(x+20,y+2);
down_touch = LEVEL->posValid(x+10,y+20);
x += x_speed;
y += y_speed;
if(down_touch)
y_speed=-5;
y_speed+=0.5;
rect.x = x - cam_x;
rect.y = y - cam_y;
if(center_touchrect.x<-30rect.x>WIDTH+50)
online = 0;
SDL_UpperBlit(FIREBALLS[(int)ani],0,screen,&rect);
if(BOWSER!=0)
if(collision(&rect,&BOWSER->rect))
{
BOWSER->hit();
online=0;
}
for(int i=0;iDEATHcount&&!GOOMBA[i]->dying && collision(&rect,&GOOMBA[i]->rect))
{
GOOMBA[i]->die();
online=0;
}
for(int i=0;idead&&!TURTLEFLY[i]->dying && collision(&rect,&TURTLEFLY[i]->rect))
{
TURTLEFLY[i]->die();
online=0;
}
for(int i=0;idead&&!TURTLE[i]->dying && collision(&rect,&TURTLE[i]->rect))
{
TURTLE[i]->die();
online=0;
}
for(int i=0;idead&&!SPINY[i]->dying && collision(&rect,&SPINY[i]->rect))
{
SPINY[i]->die();
online=0;
}
for(int i=0;idead&& collision(&rect,&KILLERBLUME[i]->rect))
{
KILLERBLUME[i]->dead=1;
SCORE->init(KILLERBLUME[i]->x,KILLERBLUME[i]->y,250);
BLOOD_GENERATOR->newBlood(KILLERBLUME[i]->x,KILLERBLUME[i]->y);
online=0;
PLAYSOUND2(S_KICK);
}
}


And this is only for the player. There is coding for so many different aspects of the game. While I myself am not a programmer by nature, I do appreciate the work that goes into these games. These are not big time software developers that get paid to do this, these are everyday people who enjoy this sort of thing and do it for the love of their hobby.

Wednesday, July 9, 2008

Pretend your friend is a Java programmer . . . . .

Pretend your friend is a Java programmer who uses Netbeans. Explain to them how to connect a MySQL database to Java using Netbeans. What should they do?Be methodical with the steps.

First, I would advise them to install MySQL as without it you can not connect a non-existant databse to Netbeans. Once MySQL is properly installed, create a databse within MySqy to use with Netbeans. Once the database is created, open Netbeans and create a New Project. In categories, choose Java . In projects, choose desktop application and click Next.
Type in the name you want for this project and then select Database Application under the Choose Application Shell heading and click Next. Click the dropdown menu database connection and choose New Database Connection. A new window will open. In the Name drop down field, choose MySQL (Connector/J driver). In the Database URL field, type in jdbc:mysql://localhostport number/databaseName. In the User Name field type root and in the password field type in the password you created when you installed MySQL, then hit ok. Then click next. Then click finish and you're application is ready to begin.

Wednesday, June 25, 2008

Blog Post Comment


I would like you to comment on this blog post. Please give a summary of what the author is saying on your own blog.


Basically, if I understand correctly, this blog deals with how most data that he deals with is streaming versus traditional documents like Word, Excel, html, etc. He talks about how the streaming impacts the performance of his PC negatively and what can be done to minimize the streaming and improve performance. I'm not sure as I am not die hard into this stuff like the people responding to this blog are.

Tuesday, June 17, 2008

In your own words to define...

Interface - An interface in Java is a group of related methods with empty bodies. That, to me, means that it is where a programmer has a starting point where they can begin to define objects and their behavior.

Abstract Class - In Java, it is defined as a class that is missing definitions for one or more methods. It is a class that is defined by a subclass where youcan define the class.

Inner Class - An inner class is nested within anotherclass.

Wednesday, June 4, 2008

Microsoft Free - One year later

http://blogs.ittoolbox.com/eai/madgreek/archives/microsoft-free-one-year-later-25078

The above is a link to an article named "Microsoft Free - One year later". This article is written by a gentleman named Mike Kavis. He writes about how he has switched from Microsoft products over to all open-source free software. He talks about how there are only a few programs that will not run on his operating system such as Microsoft Visio, an application used to create charts and diagrams. He talks about how he is happy with the switch. He also talks about how he has several computers at home and he does run Windows XP from time to time when he needs something that cannot run on Linux or Ubuntu. I say good for him. I would love to know what company he works for that they allow him to alter company property.

Wednesday, May 21, 2008

Find an article that interests you and write a few ideas about it

http://www.fsf.org/bulletin/2007/fall/antifeatures/

This article talks about antifeatures. Antifeatures, as defined in this article, is functionality that a technology developer will charge users to not include. One such example is with Windows NT Server versus Windows NT Workstation. Essentially, they are both the same program. However, Windows NT Workstation had many of those features disabled during installation when certain flags went up that the installation was for Workstation and not Server. In some cases, users can pay to have these features turned off. In other cases, they cannot.

Sunday, May 18, 2008

Put answers on blog or Google document before next class (Monday). Questions on page 74.

Exercise R2.1.Explain the difference between an object and an object reference.
An object is a value of a class type that consists of a state and related behavior while an object reference is a variable that contains the memory location of the object and allows access to that object.

Exercise R2.2.Explain the difference between an object and an object variable.
An object is a value of a class type while an object variable is a symbol that identifies a storage location that can hold different values.

Exercise R2.3.Explain the difference between an object and a class.
An object is a value of a class type while a class is a programmer-defined data type.

Exercise R2.4.Give the Java code for constructing an object of class Rectangle, and for declaring an object variable of class Rectangle.
Rectangle rectAngL = new Rectangle(0, 0, 15, 15)
Rectangle rectAngL refers to a new object variable that is being declared while new Rectangle(0, 0, 25, 25) refers to the object that is being constructed that is to be assigned to the variable.


Exercise R2.5.Explain the difference between the = symbol in Java and in mathematics.
The = symbol in Java is used to assign values and is always going to take the value to the right and assign it to the variable on the left, whereas in mathematics it is simply used to state that the expression on the left and the expression on the right are of equal value.

Exercise R2.6.Uninitialized variables can be a serious problem. Should you always initialize every int or double variable with zero? Explain the advantages and disadvantages of such a strategy.
Unless you are guaranteed to use user-inputted data for the variable, you should always initialize the variable to zero. The advantage would be that you are assured of where the value is explicitly stated and you have a point in the code in which you can trace back in the event of an error.

Exercise R2.7.Give Java code to construct the following objects:
(a)A rectangle with center (100, 100) and all side lengths equal to 50
Rectangle rectAngL = new Rectangle(100, 100, 50, 50);
(b)A string “Hello, Dave!”
Create objects, not object variables
System.out.println("Hello,Dave!");

Wednesday, May 14, 2008

Reaction to this quote

"Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do." - Donald Knuth

What I take from this quote is that the author believes the focus should be to teach others about programming so that they have a better understanding of what computers do.

Think about all the attributes and methods a plant nursery would need

OO ... Object oriented.

Most important attributes and methods a plant nursery would have.

Class
PlantNursery

Attributes:(String, int, or double)
Greenhouse - String
Soil (bags) - int
Plant Food (Quantity) - int
Gardening Tools - int
Cost - double
Seeds - int
Plants (name, type) - String
Plants (quantity) - int
Pesticide - int
Fertilizer - int

Methods:
Display the number of plants and their names
Display the feeding each plant receives
Calculate the growth rate

Calculate number of plants sold
Calculate profit based on plants sold versus cost of plant maintenance

Monday, May 12, 2008

First Blog

First blog at davidmisigoy.blogspot.com. What I hope to get out of this course is a working knowledge of java as in my line of work I have come across several instances of java and I would like to have some familiarity with it.