CSIT151007 May 2013 06:49 am

So, this blog entry will be my last for the semester for this class, hmm so where should i start…we have learned so much this semester that going into the details for everything would be like writing a Autobiography.
So i guess i will just discuss how the final project for our exam score went. First I will start off saying that for those of you who are reading this that you should not take this as “Oh so this is what the final exam will be!”With that being said lets begin!

As i mentioned in my previous post we had to create a interface application for what we wanted to do. Well the final exam was the same pretty much except we had to use the finch light sensor recordings and allow the user to save and load them.
Luckily, since i used the Jtable in my assignment i understood how to display the readings in tabular form(the condition for the final exam.) However, since we have to use the finch i had to figure out how to implement the readings in the table instead of asking what to put in the table through JOptionPane.This took more time for me to figure out then i really thought it would but after about a hour or so of writing down ideas of what might work i finally got it!

FinalExamDisign2As you Can see that i have the recordings setup in the table perfectly..the one issue i had which i wish i could have figured out is that when i set up the amount of recordings and the time to wait between them the program will wait the full duration then display them all at once instead of one row at a time. it is bothersome but i managed to get the program working so i guess i am satisfied.

Next, we had to have it setup to allow the user to pull up the file and display its results, this one i messed up on. i forgot to allow the user to name the file so there will always just be one file.FinalExamDisign3 This of course will effect my grade somewhat but once again i am pretty pleased with my results of it.

CSIT151028 Apr 2013 07:00 am

This weeks topic of discussion is the progress we have made on our GUI application! For my GUI application I chose to create a DKP tracker interface.Before I go any deeper let me explain what DKP means and the purpose of it.

Dragon Kill Points(DKP) is a Point System for handling item distribution.
These points are awarded to each guild member as they attend a guild raid. The current DKP of each member reflects his or her priority for loot. When a member “wins” an item, they lose a DKP amount that reflects the value of that item.
DKP allows for an unbiased comparison between guild members when decisions about loot are to be made based on attendance and recent items that have been awarded.The technically simplest method of dealing with DKP is to just have a list on the guild forums or a flat html file in which the standings are manually updated.

Okay, So now that I have explained what DKP is let’s move on to what I have accomplished this week with my program.
First I decided to go the extra distance and add more then just a interface for creating and storing the player names and their DKP. But first i will start with the layout of my playlist.

For this i chose to use the Jtable, for those of you who have also chosen to use a Jtable you have come to the realization just as i did. and that is that using a Jtable is much more complex then using a JTextArea. but in the end a Jtable looks much better if you using a table like format.

myGUIDKPas you can see that I use a Jtable to first Create the table. then in order to save it to a txt file i simply click the “Save Player List” button. Then if I want to see the table i click the “Load Player List” button. which then displays the names and their scores in the Jtext Area. I have been trying to figure out how to have it come out back into a Jtable instead but i haven’t been successful at it. there are also some bugs that i am working on but they aren’t so bad as to where it would make the task redundant.

As for the other two tabs i have created that you may notice at the top of the image “DKP Values” and “Calculate”  they are additional features to allow the user a quicker way of finding out what costs what and then using the calculate tab to figure out the DKP adjustments. They are both basic and simple coding so I see no point in going over them in great detail, but none the less I will post a image of them.

myGUIDKPVALUEsmyGUIDKPCALC

Well, that is that for now! So far this assignment has been my Favorite since now knowing how to create a GUI interface we should now be able to create applications for Android and so on.

 

 

CSIT151020 Apr 2013 11:36 am

Alright, so this week we are learning how to connect our interface to a text file and demonstrate that you can read the file successfully from your program. Seeing as this is simply a extension of last weeks topic you may notice some similier things.
Now with that out of the way, lets gets started. First we will discuss Files Input in Java:
Inputting data into a file in java is pretty simple really, all we have do is use the try-catch block. the following is the syntax for it:

try {
    code
}
catch and finally blocks . . .

Here is a example program for a better understanding:
public class WriteText{
	public static void main(String[] args){
		try {
			FileWriter outFile = new FileWriter(args[0]);
			PrintWriter out = new PrintWriter(outFile);

			// Also could be written as follows on one line
			// Printwriter out = new PrintWriter(new FileWriter(args[0]));

			// Write text to file
			out.println("This is line 1");
			out.println("This is line 2");
			out.print("This is line3 part 1, ");
			out.println("this is line 3 part 2");
			out.close();
		} catch (IOException e){
			e.printStackTrace();
		}
	}
}

It is also important to point out that this also has “Exception Handling”  in the code above. so lets go over that as well.
Exceptions and Exception Handling:

An Exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program.When an error occurs within a method, the method creates an object and hands it off to the run time system.
The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred.
Creating an exception object and handing it to the run time system is called throwing an exception.

After a method throws an exception, the run time system attempts to find something to handle it. The set of possible “somethings” to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack.

The run time system searches the call stack for a method that contains a block of code that can handle the exception. Which this block of code is called the exception handler. so yeah there you have it. I know that’s a lot of information just to understand what a exception handler is/does.

 

CSIT151016 Apr 2013 03:13 pm

Okay so this week we will be covering a few things:

  • Files Input in Java
  • Exception Handling
  • Nested classes
  • Assignment Design Discussion
  • String Handling Functions

Lets first start off with Nested Classes:
A Nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private.

Static nested classes do not have access to other members of the enclosing class. As a member of the OuterClass, a nested class can be declared private, public, protected, or package private. (Recall that outer classes can only be declared public or package private.)

So naturally the Syntax is pretty straight forward:

class OuterClass {
    ...
    class NestedClass {
        ...
    }
}

Exception Handling

What is a Exception exactly?An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions.

My GUI Application

For our assignment this week we were told to create a basic interface for the application we will be creating over the next couple weeks.

 

CSIT151030 Mar 2013 11:20 am

Okay! so this week we are learning about the following:

  • Inheritance

  • Interfaces

Alright, so first off lets start with inheritance. Classes can inherit member variables and methods from other classes. Some languages allow classes to inherit from multiple classes This is known as “multiple inheritance“. 

However, Java is not one of these languages.Java classes form Hierarchical tree structures where each class can have at most one parent class( or Super-class)

The Bicycle Class that we discussed about a lot last week is a great example of a super-class. because there are many different types of Bicycles.
These different types of Bicycles would be called the Sub-classes.  here is the Basic Syntax for creating a sub-class:

class-name extends super-class() {

}

So for if we wanted to create a mountainbike sub-class we would do the following:

class MountainBike extends Bicycle(){

}

Well, that pretty much covers the basic concept of Inheritance. So now let’s discuss Interfaces.

Interfaces:

As you should already know, objects define their interaction with the outside world through the methods that they expose.In its most common form, an interface is a group of related methods with empty bodies. So that means methods form the objects interface!

An interface declaration consists of:

  • modifiers
  • the keyword interface
  •  the interface name
  • a comma-separated list of parent interfaces (if any)
  • and the interface body.

The ”interface body” contains method declarations for all the methods included in the interface.a method declaration within an interface is followed by a semicolon, but no braces! The reason for this is because an interface does not provide implementations for the methods declared within it.

As you may or may not have noticed that the methods in the interface body do not have a access type in front of them. The reason for this is simple and important: All methods declared in an interface are implicitly public, so the public modifier can be omitted.

There are many great examples out there for this, but since we have already discussed the Bicycle class I will be using it as the main example for the sytanx:

interface Bicycle{
// wheel revolutions per minute

void changeCadence(int newValue);

void speedUp(int increment);

void applyBreakes(int decrement);

As you may or may not have noticed that the methods in the interface body do not have a access type(public,private,etc…) in front of them. The reason for this is simple and important:
All methods declared in an interface are implicitly public, so the public modifier can be omitted.

CSIT151009 Mar 2013 11:39 am

This Week we are Covering what Classes are and how to use them. First off, Classes are the building blocks of Java programs.
Of which are composed of two things:

  • Methods
  • Member Variables

Member variables are the data the defines what a class is. And Methods define the code for a class and defines what a class can do.

The Syntax for defining a class is:
class class-name [extends super-class] [implements interface] {
member-variable-defintions;
// These define the data for the class – what the class is

method-definitions () { // These define the code for the class – what the class can do

}

}

Declaring Member Variables

There are several kinds of variables:

  • Member variables in a class—these are called fields.
  • Variables in a method or block of code—these are called local variables.
  • Variables in method declarations—these are called parameters.

 

Field declarations are composed of three components, in order:

  1. Zero or more modifiers, such as public or private.
  2. The field’s type.
  3. The field’s name.

 Constructors

Constructors are special methods that are called when an object is created. they usually initialize the method variables for the class and get the object ready for use.

It is Important to Remember that:

  1. Constructors have the same name as the class
  2. they do not have a return type.
  3. Constructors can also be overloaded, Just like how you can overload a method to allow for differing number of parameters

The following is the basic syntax of a defining a constructor:

  access class-name (Parameters) {

 Body-of-Method

}

For example,the Bicycle class has one Constructor that Requires 3 Parameters:

Public Bicycle(int startCadence, int startSpeed, int startGear){

gear = startGear;

cadence = startCadence;

speed = startSpeed;

}

CSIT151008 Mar 2013 11:38 am

Alright so this week we discussed methods and how to implement them for our finch robots.
First off, i would just like to point out that this is quite possibly the most interesting week we have had so far on our assignments.

Anyways, lets begin going over what all we have discussed and what all we have been instructed to do this week shall we?

Methods: are a means whereby a set of statements can be executed using a single command, this is known as ”calling a method”
A series of statements can be organized within a method and then used as if the functionality that they describe is a part of the programming language itself. So we have actually been using methods this whole time!

But why exactly would we use a method?
Think of a method as being a “Index” of a book. it helps you find and understand the program. but for those of you who do not follow that i will go ahead and just describe  why methods are used directly from this weeks lecture notes:

  • Methods provide a way to enhance the ease, usability and power of a programming language.
  •  They are also the primary means of breaking large problems into a series of smaller tasks.

Alright with that out of the way I can move on to this weeks assignment we were instructed to do!

to show how much we have learned with our finch robots we are instructed to  create a command processor system to direct Finch actions using the following commands:

  •  Show
  • Speak
  • Move
  • Turn
  • SetLED
  • Buzz

AND the commands should each be handled in their own methods  as follows:

  • show - ask which sensor is to be shown and display the information in a dialog box
  • speak - ask which sensor is to be shown and speak the relevant data
  • move - ask which wheels to move and for how many seconds
  • turn - ask which way to turn and how much (in degrees)
  • setLED - allow input of the rainbow colors and a duration in seconds
  • buzz - allow input of frequency and duration in seconds

but in order to handle all this we are also to create 3 support methods:

  1. getDuration
  2. getSensor
  3. getNumber

the support methods are what the commands are going to jump to in order to receive/handle the users input. for example:

the option show will jump to ”getSensor” in order to handle what sensor the user wants to see.

well that is all I have for this weeks post! I hope you enjoyed reading and will continue to enjoy my future posts on the following weeks left of this semester!

CSIT151003 Mar 2013 08:44 am

Alright, so this week we have begun to learn how to use arrays. which i find to be pretty interesting and a little bit more
easier to understand then the previous material.the best part about an array is that you can rewrite a program that would say take tons of line of code into a array hence saving space and making things easier to read.

Here is how you create a array:

int[] anArray = new int[8];

  • the first part(int[]) is the array type which can be an int,double,String, etc..
  • the second part(anArray) is what you want to name your array.
  • and then the last part(new int[8]) is where you create the “memory slot” of the array. having the number “8″ within the brackets is just saying the array will have 8 slots of memory.

It is also worth pointing out that arrays and loops(for-loops to be exact or atleast to my understanding) go hand-to-hand.

So for example:
int[] Apples = new int[10];

int seeds = 10;

for (int i = 0; i < 10; i++) {
Apples[i] = seeds;
seeds += 10;
System.out.println(“There are ” + Apples[i] + ” Seeds” + ” in Apple # ” + i);

}

This code will first create the Array “Apples” with  10 slots. Then create a Variable that is a integer called  ”seeds” that is initialized with a 10.

We then create a for loop where the initialize the integer “i” to 0. after that we have the condition-while-true, which is i < 10. This is saying as long as “i” is less than 10 we will repeat what is in the loop body. then finally we have the loop-update statement, which is i++,This is saying i = i + 1.

now that we have created the for-loop we can now move on to the loop body. I will go through this step by step:

Apples[i] = seeds; — means that we are assigning the array “Apples” to the integer seeds that is controlled by “i”(the variable i is in the for-loop).

seeds += 10; —-means that we will be adding 10 to seeds on each loop repeat. so for the first loop it would be just 10 seeds, the second loop would be 20 seeds. since we are adding 10 (Once again “seeds+=10″ is saying seeds = seeds + 10.)

and then finally we have:

System.out.println(“There are ” + Apples[i] + ” Seeds” + ” in Apple # ” + i);

This is where we print out how many seeds are in each apple. the output should look like this :

There are 10 Seeds in Apple # 0
There are 20 Seeds in Apple # 1
There are 30 Seeds in Apple # 2
There are 40 Seeds in Apple # 3
There are 50 Seeds in Apple # 4
There are 60 Seeds in Apple # 5
There are 70 Seeds in Apple # 6
There are 80 Seeds in Apple # 7
There are 90 Seeds in Apple # 8
There are 100 Seeds in Apple # 9

Remember, having the “i” outside the square brackets means that that is the # of the loop process it is at (#1,#2,#3, etc…) Where as having the “i” inside the square brackets means that it is what value the array is at in the current “memory slot”.

 

with that being said i’d like to discuss the three assignments we have this week.
for the first assignment we were instructed to have our finch read in the light values on its left light sensor only for thirty seconds in 3 second intervals and after doing so have it calculate and display the average,high and low of the readings.  this assignment, as mentioned on the sheet, can be used without an array.however we were to do this without using an array first. so basically this first assignment is to show us how an array can be used.

for the second assignment we have is a little more challenging. from my understanding we are to create a program that allows a user to input a number of students first names and the exam score they are wanting to see. so for this it seems we have to use two arrays and then compare them together.

Now for the last assignment. I have been working on this one this morning and so far I have not ran into any “road blocks”. the assignment is to assign the finch 10 movements as well as the duration of the movements and after those movements have been completed we prompt a menu that has three choices. this is very close, if not the exact same concept as the do while assignment we had in week four. just combined with the assignment we had during week three.

 

 

CSIT151015 Feb 2013 03:01 pm

 

Alright, so this week we are finally starting to discuss loops and what we can make the finch do with them! But before I get to the assignments this week I will discuss this topic a little bit more in better detail!

Types of Loops:

 

The While Loop

While_Loop

 

Do-While

Do_While

 

For-Loop 

For_Loop

 

 

 

 

 

 

 

 

Even though each of these three loops may be coded differently, You can always change them. In other words, a “While-Loop” can always be turned into a “Do-While Loop.”

The Break Statement:

This week we also discussed the Break statement, Even though we used this in the last weeks assignment we didn’t discuss the main objective of a break command.

So, a break statement is mainly used for when you want to break out of a code(like a switch statement.) However, you will also commonly see these used in loops.

The Continue Statement:

The continue statement is a little bit more difficult to understand, at least for me anyways.

The continue statement doesn’t break out of the code like break does. it instead “jumps” over statements in certain conditions. As for in a loop, the continue statement causes execution to skip to the end of the loop and begin a new iteration.

Adding a Loop to our switch statement

Okay, so for our first homework assignment this week we were instructed to add a 5th menu option in our switch statement that would end the program and to also have the program repeat(or loop) until this option was chosen.
This was much easier to handle then what it seemed it would be at first. it all just came down to looking at our program like a actual “menu” and then just adding the loop..of course I realize reading this doesn’t fully help someone understand how it is done..but that is basically just the way I do things so I guess what I am getting at is finding your own way to see things helps so much with programming!

The Animal Finch:

I personally enjoyed this one the most. having it move around objects and backing up and turning around when it runs into a wall was pretty cool.
it did take some messing around to get the whole thing working together as a whole. but that is what this assignment was all about anyways!

 

CSIT151007 Feb 2013 01:25 pm

Alright so this week we discussed a couple interesting materials. they are pretty simple to understand compared to last weeks work..or well at least for me. for this weeks blog I will only discussing three of them. those are the following:

  • Conditional Expressions
  • If statements
  • Switch statements

Conditional Expressions 

Alright, so a quick run down of what a Conditional Expression does is that it can compare variables and constants. It can also do the same for numbers, however you have to use comparison operators. I won’t list all of them but here are a couple comparison operators:

  • <  (less than)
  • >  (greater than)
  • ==  (equal to)
  • !=  (not equal to)

Of course you can also create more complex conditional expressions with some other operators. but I will not go into that.

If statements

Next on the list are the If statements. These were the most important things we covered this week that we would need to understand in order to do our finch assignment(which i will discuss later on in this blog.) there are a couple types of if statements that we covered. those are the following:

  • if statement
  • if-else statement
  • chained if statements
  • nested if statements

the First two “If-Statements” are pretty simple..however chained if  and nested if statements can quickly give me a head-ache.

switch statements

alright, now for that last one on the list, switch statements. switch statements can be used to express a chained if statement that compares a single variable to a group of constants. In most cases, if you ask me, a switch statement looks much cleaner and easier to read. Again, I could type out a full example of such but looking them up via google would be best!

The finch programming assignments!

alright, now I can get to finch progress I have made for this weeks assignment so far! the first program we were instructed to write was simple and quick to code. all it needed were if -else statements to work.

The second program we have to code is somewhat more complex then the first.It requires us to use switch statements in order to handle the selection of the user.

Next Page »