Wednesday, June 27, 2012

Still Counts in Base 2

So one week done with the Java CS 55 course. We've reviewed some things that I never understood which are doubles. Double in Java is a decimal number. But when you add two doubles, you usually get a formatted number like such: 2.00 + 3.00 = 5.0000004

I wasn't sure why but I did some digging. Double is where the computer assigns the decimals as though in base 2, so 2^-6th would be something like a fractional decimal to count in which gives us the 0.00004 at the end of a double arithmetic. So it was odd when I'd arrive with a simple program adding two double numbers and get a sum. Thankfully in Java there's a class called DecimalFormat in the java.text.* package which allows me to force a specific format of the decimals as a method.

Like so:

public static void main(String[] args)
{
DecimalFormat f= new DecimalFormat("0.000");
String numStr1 = JOptionPane.showInputDialog("Enter an Integer");
double n1 = Double.parseDouble(numStr1);
String numStr2 = JOptionPane.showInputDialog("Enter an Integer");
double n2 = Double.parseDouble(numStr2);
double total = n1+n2;
System.out.println("Total is "+total);
System.out.printf("Total is %6.2f\n", (n1+n2));
System.out.println("Total is "+f.format((n1+n2)));
System.exit(0);

This will give you three outputs, one is the unformatted normalized total, second is a float like total printed (something in C you can do all the time), and finally the formatted output.

I guess that also includes the code of the post. Till next time :)

Thursday, June 21, 2012

So the First Two Years Don't Count?

Well. It seems like it's been an eternity since I started this blog, let alone the countless attempts at continuing it. While my mom is long gone (4 years in July), my journey through college hasn't ended. Not the slightest.

Last post was done in 2009. Lets get back up to speed. I'm no longer a Chemical Engineering Major. Nay. I was enjoying the labs much more, however, to do anything NEW I would have to redesign the experiments. That takes too much time. I got bored of memorizing these interesting bits and pieces of chemistry, even Organic Chemistry was fun to an extent. I got tired of it though. I didn't see myself doing what I was doing in the lab every day.

What did I do? I did the worst thing you could do in college, switch majors in an entirely different field: Computer Science. Why Computer Science? My dad is a computer scientist at JPL (Jet Propulsion Laboratory for those who don't know the acronym), he's been working there as long as I've been living on Earth. He told me to take the intro CS class at SMC. I did last Fall. It was pretty boring as I knew pretty much 80% of the material covered in the course before stepping in the door. I continued with it because the introductory course is always boring or severely limited in what depth the materials are taught.

Winter 2012, CS 50 C Programming. All I can say is this: Where were you in high school?! I didn't imagine that something so difficult for others to understand to be blatantly easy for me to understand. I mean who wouldn't want to make things easier in terms of repeating the same thing over and over but with different inputs by writing a simple method to do everything being done? Make a new header file with methods to be called upon and you're pretty much set! This class was very short. 6 weeks short and I had difficulties in getting my mind to class. I endured it though.

Today, June 21, 2012 - I'm retaking my Java CS 55 course because I don't accept B's anymore. Although I did receive a B in my 3rd semester of Japanese (Reviewing for the Fall semester as I'm continuing on to Japanese 4), I can't say that I worked my butt off to learn everything well and do the best I could. Although this is technically not a class I'm registered in, I'm sitting in the Java class to keep my mind on things and not melt away as almost everyone does during the summer.

So Java, a language released in 1996 by Sun Microsystems (acquired by Oracle in 2009), is the first Object Oriented Programming language that I'm learning. What was the first language you ask? Technically it was AppleScript. I used to get away with playing games on my PowerMac G5 by writing scripts to disable various processes or programs that my dad installed to prevent me playing said games. Of course though, whichever script (the applications my dad used were most likely scripts) he used ended up being terminated faster than the script could start up and read the list of applications to be  prevented from opening. Reasoning behind this was that my script was about 9 lines long, it's really fast to execute, no end, and the processor never had to do anything but check that the process called "whateverapplicationpreventornamedhere" was forced to quit.

My dad was annoyed but impressed at the same time, the applications couldn't keep up with my scripts and there was no way to just prevent the script from activating faster than the application could catch it.

I digress. So today I'm writing yet another attempt to reboot a blog. I find it relieving to write these thoughts out. And possibly to keep a log of my journey through the forever evolving environment of Computer Science.

Program of the day:

public class Exercise6 {

public static void main(String[] args)
{
System.out.println("Plesae enter a number between 0 and 1000");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
int lastDigit = number % 10;
int remainingNumber = number / 10;
int secondLastDigit = remainingNumber % 10;
remainingNumber = remainingNumber / 10;
int thirdLastDigit = remainingNumber % 10;
int sum = lastDigit + secondLastDigit + thirdLastDigit;
System.out.println("The sum of all digits in "+number+" is "+sum);
}
}

Saturday, May 15, 2010

Revitalization

So after three years of starting this blog, I think I have finally realized my error in starting. I wasn't determined what I wanted to do with it! Now I have a separate blog for Japanese and I feel as though that I want to have a blog of just for myself.

Considering that there are many blogs out there that just specialize in people's life story, I guess it is a good point ot have a blog like my mom's, a blog with witty stories and interesting posts that connect to my life. With that said, I am ready to venture on into the undiscovered country of the internet (for me) and maybe even start something.

Just for your information, my other blog is available at:
http://thenewjapanesestudent.blogspot.com/

Thursday, August 20, 2009

A new way of life

Ok so... here we go:
One year ago my mom passed away, and now this year I'm going to college.
Big whop.
However this is what i like about attending SMC:
1) My schedule is perfected to a point that i have an entire days to spend time doing things i couldn't before
2) I now have a PS3 to play (no not the ps3 slim (i don't like it at all)) except i really am thinking about getting the full backwards compatible ps3
3) My classes are going to be hard and i'll have plenty of time to study for them
4) I'll finally get a job as a tutor and be able to go out with my own money

So yes this year is going to be interesting.

Sunday, December 2, 2007

A Quote from Edgar Allan Poe

Here is one of my favorite quotes from Edgar Allan Poe's
The Murders in the Rue Morgue
"To deny something that is, and to explain something that isn't."

Wednesday, November 21, 2007

Elephant joke

How do you kill a blue elephant?
Shoot it with a blue pistol.

How do you kill a pink elephant?
Tie its trunk, wait until it turns blue, THEN shoot it with the blue pistol.

Tuesday, November 20, 2007

Oops...

From Anarchic Universe:
"Son's coca-cola catapulted to computer. To Apple soon. Take care."

Yes, I accidentally spilled the coca-cola on my mom's computer keyboard.