Win a copy of Rust Web Development this week in the Other Languages forum!

Logan Saturnius

Greenhorn
+ Follow
since May 27, 2004
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 Logan Saturnius

nevermind i got it working a different way
17 years ago
I had a go at it but i got the following error:
Esception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Assignment2prog2.alphabettwo(Assignment2prog2.java:57)
at Assignment2prog2.main(Assignment2prog2prog2.java:76)
I really really need help solving this
-thanks

17 years ago
Hi,

I've written a program that accepts a string of characters from the user as input and then filters it through an array (ASCII values of lower case alphabet) to find out how many times each letter occurs, but now I have reprompt the user to enter more input (in the form of a word) and then search the the users Original input to see how many times the word appears within it :roll:
I know that I will have to create another method to re-prompt the user for more input, but would I also have to create another method for another array containing the original string to search through? or there some easier way that im missing here.



-thanks
17 years ago
Ahh oops.. hehe i see now, i needed to take the close input file part out of the loop, and put it after all input is depleaded and the loop terminates.

Ok now I know i've probably been a bother asking all these questions and all, but i just got one last little question about this program

At the moment the output.txt file is recording the results ok, but since it is recording off the variable 'answer' (and 'answer' has the value of 'type') it's just recording the number of the option that was triggered by the switch (ie. 332103320321) Is there any way to make it record the whole line from the correct switch option?

-Thanks yet again for the help
17 years ago
Also if i wanted the output file to write the actual switch message instead of just the 'type' number how would i do it? cause at the moment its just printing "333333333333" etc. :roll:
17 years ago
cool! getting rid of the loop eliminated the first error

it goes through ok now, until just after the "Press any key to continue"
"Continuing on..." part
then it displays:

java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Assignment2prog3.main(Assignment2prog3.java:65)

-thanks
17 years ago
Argh,

I've got the program running but it seems to be catching like 2 or so exception errors and not displaying what i want it to

It seems to open the the file and stuff ok but runs into bother :roll:
It triggers the exception error in the tokenize() method, then displays the type of triangle, then triggers an I/O exception at the end and exits.
Im soooo gonna get this program running perfect today, even if it kills me hehe.

I've altered the code in my above post to show the program now.

once again, any help would be great ( you people rock )
17 years ago
Thankyou for your replies,

I fired the openread() method and opened the input.txt file straight from main, but I cant think how to set up the loop for reading the first line of the input file, going through the program displaying results etc, then when going through the loop again making it read the second line. ?
Sorry for asking such a question, its probably something really simple.
So tired, I guess I should'nt stay up for 2 days at a time. hehe

this is what code is now.



-thanks
[ June 02, 2004: Message edited by: Logan Saturnius ]
17 years ago
Hi,

The program compiles fine with no error's, but in some parts it is not doing what I want it to I'll post the code and then the problems im having.



Whenever the program starts it displays the intro and the "Opening File: "
part ok but then when it hits the while statement it returns the "There is no more input!" "This is a Valid, Scalene triangle" everytime.
Is it not finding the text file (input.txt) ?
I have both the input.txt and the output.txt doc's in the same directory as the the program and class files
My input.txt looks like this
30 40 20 \n
23 53 31 \n
11 11 11 \n
68 42 68 \n
24 54 15 \n
9 3 7 \n
And my output.txt file is only writing the number of the 'type' variable that was executed on the switch :/ ie. "333333333333333"

Any help would be great
-thanks
17 years ago
Thanks for the reply Marco

I put the return statement outside of the if/else statements and instead of having int type; i changed it to int type=0; then it worked

-thanks
[ June 01, 2004: Message edited by: Logan Saturnius ]
17 years ago
Hi again, thanks for the info! got method two working
(By the way im sorry that I keep posting like this, but im learning though hehe)

Anyway I had a go at doing the third method which calculates if a triangle is valid and what type of triangle it is (triggers a switch function in main) and I have 1 error, but I dont understand how its missing a return statement when i am returning "type"
Oh how i wish to do one method without an error!. :roll:
I'll repost the new code
-thanks

Prog3test3.java:41: missing return statement
{


[ June 01, 2004: Message edited by: Logan Saturnius ]
17 years ago
Ok I added "static void" to tokenize() and I added the java.util.StringTokenizer package at the top
my import list at top of source file looks like this

import java.io.*;
import java.util.StringTokenizer.*;
import B102.*; (This is just a JAR file from school that we use)

yet i still get the same following two errors on compile

Prog3test2.java:32: cannot resolve symbol
StringTokenizer st = new StringTokenizer(in);

Prog3test2.java:32: cannot resolve symbol
StringTokenizer st = new StringTokenizer(in);

-thanks
17 years ago
Thankyou so much for your replies! got the first method working properly.

Now I was going to start a new thread for another question, but since this one is still new i'll just post it in here.
I've had a go at another method of the program (Using StringTokenizer, and the Integer.parseInt() method, which i've kinda never used before).
This time I have 4 errors when I try to compile, that i cannot seem to fix. I'll post the errors first and then the code.

-thanks

Prog3test2.java:30: invalid method declaration; return type required
public tokenize(String in)
(I dont understand why i have to return something to the main, when all im doing is setting values to s1,s2,s3)

Prog3test2.java:32: cannot resolve symbol
StringTokenizer st = new StringTokenizer(in);

Prog3test2.java:32: cannot resolve symbol
StringTokenizer st = new StringTokenizer(in);

Prog3test2.java:43: cannot resolve symbol
tokenize(in);


[ May 31, 2004: Message edited by: Logan Saturnius ]
17 years ago
argh sorry, i had multiple command prompts up and must have written the wrong error, its saying

Prog3test.java:28: non-static method openread(java.lang.String) cannot be referenced from a static context
String in = openread("input.txt");

(but if i take away the the 'static' in the main function it brings this error instead.)

Prog3test.java:23: variable line might not have been initialized
return(line);


:[
[ May 31, 2004: Message edited by: Logan Saturnius ]
17 years ago
Hi,
I've been starting to go through my programs by doing one small part at a time so i dont run into as many errors :/
can someone please look over my open/read method?
im getting 1 error when i attempt to compile it ive marked in code where it is
it says this when i try to compile


Prog3test.java:28: openread(java.io.File) in Prog3test cannot be applied to (java.lang.String)
String in = openread("input.txt");
^
-thanks

17 years ago