Thursday, May 1, 2008

Homemade JVM

It seems that the author was trying to create his own, but limited, Java Virtual machine(JVM). He seemed to be torn between working with another project he had going called Morpheus and the JVM. His coding was above anything I have done or seen so far. It was an interesting read and I tried following along with how he broke down each section. Still though, it is quite a bit to digest at my current level. If there is a JVM available, not sure why someone would want to build another one from scratch. Guess he liked the challenge.

Tuesday, April 29, 2008

Final Project update

My final project is based on a choose-your-own-adventure format. I am under the gun to get it finished before the class is over...no pressure. I am working out the details right now and hopefully I will have it coded before time runs out. That's all for now.

Coding using NotePad

/* Using simply notepad (and without looking on the Internet) create a program that will keep track of a car's mileage, mph, gas in the tank, and the known sum spent on gas. You will create methods to simulate driving a certain distance. The program must calculate the miles driven and the gas left in the tank. The same method should also allow for the user to enter in the price of gas, which will be kept in a variable.
Download this. Open it with BlueJ.
*/
import java.util.Scanner;
public class CarSimulator{ private int mileage = 0; private int miles_per_hour = 0; private int gasTank = 0; private double gasTotal = 0; private double gasPrice = 0; private int miles_per_gallon = 0; public CarSimulator(int mpg, int gas_in_tank) { miles_per_gallon = mpg; gasTank = gas_in_tank; }
public double getGasTotal() { Scanner in = new Scanner(System.in); System.out.print("Please enter the price of gas: "); gasPrice = in.nextDouble(); gasTotal = gasPrice * gasTank; return gasTotal; }
public int distance() { mileage = miles_per_gallon * gasTank; return mileage; }
public int gasLeft() { gasTank = gasTank - (int)mileage/gasTank; return gasTank; }
public static void main(String[] args) { CarSimulator vehicle = new CarSimulator(25, 16); System.out.println("The distance you can travel is " + vehicle.distance() + " miles."); }}

Sun Developer Quiz

Not a bad quiz. I got 7 out of 10 questions right. Gives me a chance to gauge where I am learning Java. I'd recommend that people try the quiz.

Thursday, April 24, 2008

Recursive Examples

public class RecursiveArray {
static double temp = 0;
public static double max(double[] array, int n)
{
if (n == 0)
return array[0];
else if (array[n] < array[--n])
temp = array[n];
n -= 1;
return temp;
}
public static void main(String[] args)
{
double[] array = {23.4, 45.9, 5.3,77.3, 5.4, 8.5, 45.6};
System.out.println(max(array,4));
}
}

Tuesday, April 22, 2008

Final Project

I would like to make choose-your-own-adventure game that allows the person to choose from several endings. Just a quick idea...more to come.

Recursion Diagram