Saturday, January 27, 2007

Tools for starting Java Programming



Okay you're at my Java programming blog, Great! You probably didn't come here by chance, if you didn't, if you were just searching for help to Java introduction well, you got the right place.

First, to start programming in Java, you need the Java JDK, Developmental Kit, which could be downloaded at the Sun Java website, click on this link. I recommend you download the JDK6.

Then once you got that, you might want to download an editor and compiler, unless of course you want to use your command line environment to do all the compiler. I find that too much work. I use an editor and compiler call DrJava. Click on the link to go to the download site.

That's it. You're on your way to programming. For tutorials, you can find it at the Sun Java website.

If you want to play with simple codes I have on my website, just copy it and paste it to your editor and compile it.

Here's a good place to start on your way to learning Java and becoming a Java programmer. I found this E-book PDF on teaching yourself Java. Its great.
Has all the beginnings steps.

Have fun!

Friday, January 26, 2007

My most recent beginning code: PizzaCalculations

import java.util.Scanner;
/** @author Don Lam
* pizza parlor calculations
* */

public class PizzaCalculations {
public static void main(String []args) {

double initialBase= .05; // cost of pizza/square inch
double radius= 1; //radius of pizza
double costPizza= 1; //cost is Area*.05 or (input radius/2)^2 * pi
double area= Math.PI*Math.pow(radius/2,2);

System.out.print("Enter pizza size in inches: ");
Scanner input= new Scanner (System.in);

radius=input.nextDouble();
area= Math.PI*Math.pow(radius/2,2);
System.out.println("Your pizza size is: "+(int)radius);
System.out.format("Your area of pizza is: " + "%.2f%n",area);

costPizza=area*initialBase;
System.out.format("The cost of your pizza is $"+"%.2f%n",costPizza);

// Second calculation finding the cost for toppings

double toppingBase= .01;
double toppingCost= 1;
double amountTopping=1;

System.out.print("Enter the number of toppings");
amountTopping= input.nextDouble();
System.out.print("Enter topping size(pizza size) in inches: ");

radius=input.nextDouble();
System.out.println("Your topping size is "+(int)radius+" inches");
area=Math.PI*Math.pow(radius/2,2);
toppingCost=toppingBase*area*amountTopping;

System.out.format("Cost of that size with "+(int)amountTopping + " topping is $" + "%.2f%n",toppingCost);

//Finding the delivery cost

double miles=1;
double fuelCost= 1.89; //cost per one mile
double carTank= 54; //fuel efficiency
double t=2; //for round trip
double delivery= miles/carTank*fuelCost*2; //cost for round trip delivery with x number of miles
System.out.println("Enter number of miles to destination: ");
miles=input.nextDouble();
delivery= miles/carTank*fuelCost*2;
System.out.format("Cost for a round trip delivery for "+ miles +" miles" + " is $" + "%.2f%n", delivery);

//Calculating profit margin

double productCost=1;
double sellingPrice=1;
double profitMargin=(sellingPrice-productCost)/sellingPrice;
System.out.println("Enter cost of production: ");
productCost=input.nextDouble();
System.out.println("Enter selling cost: ");
sellingPrice=input.nextDouble();
profitMargin=(sellingPrice-productCost)/sellingPrice*100;
System.out.print("Your profit margin for sell at $"+ sellingPrice +" with production cost of $" + productCost + " is " + (int)profitMargin);
System.out.print("%");

//This is pizza Calculation Lab

}
}

This program is my third dealing with Java. This code introduces to taking user imports package, the import java.util.Scanner; and some Java arithmetic using Math.pow, and Math.pi. The if you compile the program it is suppose to be able to help you figure out how much your pizza would cost with a certain diameter, how much a delivery cost for the pizza would be based on 54miles per gallon efficiency. All the comments are provided in the code so it is very intuitive you're trying to figure it Java out for the first time. If you wish you can change the code around and make edits to it to find the cost of the pizza from wherever you want buy from.

I'm open to suggestions of making the code more efficient or complicated, as I say, this is only my third program.

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.

NCSU CSC News Channel

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