Lucas Laws

Greenhorn
+ Follow
since Sep 13, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lucas Laws

Actually, thats good news. I'm looking for something gear toward OpenGL mostly.
13 years ago
Does your book cover a variety of platforms to develop Android games with, or do you focus mostly on, such as OpenGL, and just briefly mention what other options are?
If you cover multiple platforms, how in depth do you go into each of them?
13 years ago
Do you get into the widget side of Android? I'm really interested in making good widgets.
13 years ago
Nevermind that, realized that in trying to retain old code while experiemnted with something else, I renamed the class, and forgot to add this change down when I call the sort, since its a static method, class name is important.

Ok, so its getting the Vector just fine, thanks for that help. I'm off to debug, again.
17 years ago
I'm getting no output coming from the sort method whatsoever, which is what caused me to think I need to pass the vector.

Oh, and for this:



I forgot to clean everything up from me playing around trying to pass a vector, it should just be


[ November 01, 2006: Message edited by: Lucas Laws ]
17 years ago
So I fixed my code since yesterday, and right now it will compile, however its not doing what its intended to do.


Theres my code. Right now, all it does it takes the contents of PetRecords.txt, writes that to a Vector, and then writes that Vector to PetRecordOutput.txt. Its supposed to sort it before it writes the output, but it just isn't sorting. How can I pass my Vector to my sort method (which I think will solve my problem)? I tried doing this but java went crazy on me, so either I can't, or my syntax is crap. Help?

[ October 31, 2006: Message edited by: Lucas Laws ]
[ October 31, 2006: Message edited by: Lucas Laws ]
17 years ago
Ok, I'll move it out of main and try to work everything into a happy order then. Thanks.
[ October 30, 2006: Message edited by: Lucas Laws ]
17 years ago
I have checked for missing braces already, and everything lines up perfectly.
17 years ago
So, this is probably just something really minor that I'm missing, but I've racked my brain debugging this for awhile and havn't found a fix, so maybe you guys can help me out.

import java.io.*;
import java.util.*;

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

int arrayCount = 0;
int charValue = 0;

PrintWriter fileOutput = null;//create the PrintWriter object before the try{ so it will not die at the } ending the try

try
{
BufferedReader inputStreamCounter = new BufferedReader(new FileReader("PetRecords.txt"));
String line = inputStreamCounter.readLine();

while(line != null)//count the total number of lines being read from the file
{
arrayCount++;
line = inputStreamCounter.readLine();
}

inputStreamCounter.close();//close the stream so it can be reopened to write to the vector

BufferedReader inputStream = new BufferedReader(new FileReader("PetRecords.txt"));

Vector<String> petVector = new Vector<String>(10);

for(int x = 0; x < arrayCount - 1; x++)//gather data from file into the vector
{
petVector.addElement(inputStream.readLine());
}

for(int x = 0; x < arrayCount - 1; x++)
{
if(petVector.elementAt(x) == " ") //removes all whitespace lines from the vector
{ petVector.removeElementAt(x); }//makes name be at index 0 + 3n, age at 1 + 3n, and weight at 2 + 3n
}

public static void sort(int charValue)//create method to check value of letters in name to alphabetize.
{//recurve if name(0) == name2(0)

for(int x = 0; x < petVecor.size() - 2; x += 3)
{
if(petVector.elementAt(x).charAt(charValue) > petVector.elementAt(x + 3).charAt(charValue))
{
String vectorTempOne = petVector.elementAt(x);//copies the pet record from x to temporary variables
String vectorTempTwo = petVector.elementAt(x + 1);//to transfer x+3 to x, and x to x+3
String vectorTempThree = petVector.elementAt(x + 2);

petVector.setElementAt(petVector.elementAt(x + 3), x);//copying the record starting at x+3 to x
petVector.setElementAt(petVector.elementAt(x + 4), x + 1);
petVector.setElementAt(petVector.elementAt(x + 5), x + 2);

petVector.setElementAt(vectorTempOne, x + 3);//copying the record that was put in temp vars to x+3
petVector.setElementAt(vectorTempTwo, x + 4);
petVector.setElementAt(vectorTempThree, x + 5);
}

if(petVector.elementAt(x).charAt(charValue) == petVector.elementAt(x + 3).charAt(charValue))
{
charValue++;
VectorDemo.sort(charValue);
}
}
}

VectorDemo.sort(0);

fileOutput = new PrintWriter(new FileOutputStream("PetRecordOutput.txt"));

for(int x = 0; x < petRecord.size() - 2; x += 3)
{
fileOutput.println(petRecord.elementAt(x) + "\n" + petRecord.elementAt(x + 1) + "\n" + petRecord.elementAt(x + 2));
}
fileOutput.close(); //close the file stream when done
}

catch(FileNotFoundException e)
{
System.out.println("File PetRecords.txt not found.");
}

catch(IOException e)
{
System.out.println("Problem reading from file.");
}

}
}


Basically I'm reading in a "Pet Record" from a file, which is just a name on one line, age on next line, and weight on the line after that. I then need to sort all the record by name alphabetically, and output it to a file. I can't debug the rest of it until I get this error fixed.

I'm getting an illegal start of expression on line 42 (which is my sort method).
[ October 30, 2006: Message edited by: Lucas Laws ]
17 years ago
Ok, thanks. I figured it was as much, but couldn't figure out how to fix it. I guess I'll read it in as a string and play with it that way, thanks.

I just changed my read() to readLine() and parsed it to an int, so alls well that ends well, thanks for the help.
[ October 11, 2006: Message edited by: Lucas Laws ]
17 years ago


Theres my code for this problem. I have it get its input from input.txt (and yes, I've tried using the full path to the file). The contents of the file are:

5
2
7

Just those 3 numbers, each on a different line. When I run the program however, it comes up with the numbers 53, 13, 10, and 50. Writing the output to another file works fine, based on the data the program got.

So, my question is, where the hell are those 4 numbers coming from and why aren't my 3 numbers getting fed in?

[ October 11, 2006: Message edited by: Joe Ess ]
[ October 11, 2006: Message edited by: Joe Ess ]
17 years ago
Thanks for the help. Aparently if you use nextInt() before you use nextLine(), its just skips any user input for the nextLine(). I switched them so the nextLine() happens first and everything compiled fine. Heres my final result.

Any tips on how to better code this are appreciated.

import java.util.*;

public class Count
{
static String numberOutput;
static int languageType, loopCounter, countTo, column;

static public String[][] count = {
{"One", "Two","Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"},
{"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"},
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}};

public static void myForLoop(String count[][])
{
for (column = 0; column < countTo; column++)
System.out.println(count[languageType][column]);
if (column == countTo)
System.out.println("This was For\n");
}

public static void myWhileLoop(String count[][])
{
column = 0;
while (column < countTo)
{
System.out.println(count[languageType][column]);
column++;
if (column == countTo)
System.out.println("This was While\n");
}
}

public static void myDoWhileLoop(String count[][])
{
column = 0;
do
{
System.out.println(count[languageType][column]);
column++;
if (column == countTo)
System.out.println("This was Do While \n");
}while (column < countTo);
}

public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Do you want the output in Arabic, Roman, or English?");
numberOutput = keyboard.nextLine();
System.out.println("Enter a number from one to ten.");
countTo = keyboard.nextInt();

languageType = 2;//defalt is 2, which will point to Arabic for output
if (numberOutput.equalsIgnoreCase("english"))//determines which language the output should be in and sets
languageType = 0; //and sets a variable to tell us which column of the array to index
else if (numberOutput.equalsIgnoreCase("roman"))
languageType = 1;
myForLoop(count);//fix me
myWhileLoop(count);
myDoWhileLoop(count);
}
}
17 years ago
Ok, well, I just made the variables static and that fixed that problem. Thanks.

Now I have a problem with the scanner. When I run it, I'm prompted for the first line correctly, but after it print the next question asking for input it just automatically runs the rest of the code and skips and user input. Any clue why its doing this?
17 years ago
then I end up with:

Count.java:44: non-static variable countTo cannot be referenced from a static context
countTo = keyboard.nextInt();
^
Count.java:46: non-static variable numberOutput cannot be referenced from a static context
numberOutput = keyboard.nextLine();
^
Count.java:48: non-static variable languageType cannot be referenced from a static context
languageType = 2;
^
Count.java:49: non-static variable numberOutput cannot be referenced from a static context
if (numberOutput.equalsIgnoreCase("english"))
^
Count.java:50: non-static variable languageType cannot be referenced from a static context
languageType = 0; ^
Count.java:51: non-static variable numberOutput cannot be referenced from a static context
else if (numberOutput.equalsIgnoreCase("roman"))
^
Count.java:52: non-static variable languageType cannot be referenced from a static context
languageType = 1;
^
Count.java:53: non-static variable count cannot be referenced from a static context
countTo.myForLoop(count);
^
Count.java:53: non-static variable countTo cannot be referenced from a static context
countTo.myForLoop(count);
^

Count.java:54: non-static variable count cannot be referenced from a static context
countTo.myWhileLoop(count);
^
Count.java:54: non-static variable countTo cannot be referenced from a static context
countTo.myWhileLoop(count);
^

Count.java:55: non-static variable count cannot be referenced from a static context
countTo.myDoWhileLoop(count);
^
Count.java:55: non-static variable countTo cannot be referenced from a static context
countTo.myDoWhileLoop(count);
^

How can I fix this?
17 years ago
Well, originally I had it inside main. Here is what I get at compile from that:

Count.java:18: illegal start of expression
public String[][] count = {
^
Count.java:23: illegal start of expression
public void myForLoop(String count[][])
17 years ago