Friday, January 26, 2007

Java straight from the classroom

So. I'm taking Java this semester. For some odd reason I seem to be the slowest one in creating programs in class. Yet for even more enigmatic reasons, I seem to enjoy that.

I am Don, my first computer, hmm don't remember what it was. Old I know, it had two floppy disk drive, one huge and one for the small normal size one that now has also become obsolete in the computer world. heheh. Imagine back to time of sneaker net what a hassle it must have been.

Java class for me is a really exciting and fun class. Every time I am there, I always expect something new and challenging. Mostly fun to work with. I usually never finish my lab in class, but I like bringing the classroom back to my dorm and messing with it.

So here's whats up with my postings, when I have time, I will post up notes I taken from my first Java introduction course and along with it I will post snippets of programs that I have created myself.

If you're new to Java I think you will find these notes and program helpful. However, If you're an intermediate or advance programmer please feel free to make recommendations and post changes to the programming or notes.

2 comments:

Anonymous said...

Hey, dude. I think I've seen you in my class, have I not?

Anonymous said...

First lab in class was a bit unusual. We had to to evaluate the arithmetic. Instead of doing such, I thought we had to declare it Java and write a code to represent it in the computer.

The next lab, they went over, all was ask was to evaluate the math to find the answer. Testing your arithmetic logic and order of operation!

Me and instructions. Doesn't get along very well. And the fact that I'm too stubborn to ask people for clarification makes it even worst.

Here is my first program, called Arithmetic
public class Arithmetic {
public static void main(String[] args) {
/*one example of doing
arithmetic in Java*/
double lengthOfSide = 7.5;//this is in inches
double areaOfSquare = lengthOfSide * lengthOfSide;//this is in inches-squared
System.out.println("The area of a square with sides of length " + lengthOfSide + " is " + areaOfSquare);
//put your calculations here

/*excercise 1 finding Cost of purchase of 15.75 with NC tax of 6.75% */
double taxPercent = .0675;
double purchasePrice = 15.75;
double priceAndTax= taxPercent*purchasePrice+purchasePrice;

System.out.println("Cost of $15.75 dollar purchase with tax is $" + priceAndTax);

/*excercise 2 find area and circumference of a circle (in inches) given diameter 20 inches
Pi*diamter=C and Pi*radius^2=Area */

double PI=3.14;
double givenDiameter= 20;
double r= givenDiameter/2;
double rSquare= r*r;
double circumference = givenDiameter*PI;
double area= PI*rSquare;

System.out.println("Circumference is "+circumference + " inches");
System.out.println("Area is "+area + " inches");

/*The Center for Disease Control defines a person's Body Mass Index as
Weight/Height-squared
where Weight is a person's weight in kilograms and Height is the person's height in meters. */


double inchesHeight= 59;
double inchesNMeter= .0254;
double poundWeight= 106;
double poundNKilo= 0.45;
double kiloWeight = poundWeight*poundNKilo;
double meterHeight = inchesHeight*inchesNMeter;
double heightSquare= meterHeight*meterHeight;
double bodyMassIndex= kiloWeight/heightSquare;

System.out.println("My body mass index is "+bodyMassIndex);

/* Excercise 4 Investigate the speed of light and calculate how far light travels in one nanosecond? Give your
answer in inches.*/

double LIGHTSPEED = 3E8;
double nanoNSecond= 1.0E-9;
double iNMeter= 39.37;
double iPerNano= LIGHTSPEED*iNMeter*nanoNSecond;

System.out.println("Light travels "+ iPerNano + " inches in a nanosecond");

/* You are buying apples from the local grocery store. You can by apples in either a one dozen bag,
for $4.99, or individually, for $0.50 an apple. Find the lowest price for buying 29 apples.
(Hint: The modulo operator will be very useful) */

double d= 4.99;
double i= .50;
int apple= 29;
int dozen= 12;
double rApple= apple%dozen*i;
double nR= apple/dozen*d;
double cheapPrice=rApple+nR;

System.out.println("Cheapest price for the apple is $"+cheapPrice);

//Java programming is getting so cool!
}
}



NCSU CSC News Channel

The Weather Channel: Your Local Weather Outlook--Raleigh, NC (27608)