Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-16-2005, 07:26 PM   #1 (permalink)
Crazy
 
[Java] Simple programming with arrays & file IO

I'll cut to the chase. I have an assignment to do and no time to do it. The reasons aren't important. A wife, a daughter, etc, etc. I took 2 years off of school, and came back to learn that C++ is now Java. I'm in an upper level class and I can't catch up. It's like knowing all the verbs and nouns in a language, but I can't make a fucking sentence.
If you have some time, I could use the help. Money could be involved. I can speak how to solve the problem, but I can't code it. I'm looking for the solution, and a hand with the syntax.
__________________
I'd rather regret what I did do than what I didn't.

Last edited by dr_lubin; 02-24-2005 at 03:15 PM..
dr_lubin is offline  
Old 02-16-2005, 07:30 PM   #2 (permalink)
Crazy
 
The madness came to a boil, and made a mess on the stove.
__________________
I'd rather regret what I did do than what I didn't.

Last edited by dr_lubin; 02-24-2005 at 03:16 PM..
dr_lubin is offline  
Old 02-17-2005, 05:36 PM   #3 (permalink)
Crazy
 
Location: Salt Town, UT
I wish I could help you, I could write this little thing as a PHP class in probably under half an hour, but I don't know java. (I have been hired twice to write java for companies as a junior programmer, both times, I converted the company to PHP, it was all web-work so it didn't really matter.)

What I would do is have the library class read in the file one line at a time.
Each line it will parse the line and create a new book class, and temporarialy hold it somewhere.
Then in that parsing function, I would create a array (or vector, as you crazy java people are prone to do) of chapter classes, and then go through and initialize each one.
After that, I would store that array of chapter classes into the book class, and add that book class (the one you were holding onto earlier, remember) to an array of books in the library class.

I wish I could help you on the vocabulary, but as I've said, I'm not a java programmer.
Rawb is offline  
Old 02-17-2005, 08:39 PM   #4 (permalink)
aka: freakylongname
 
Chamaeleontidae's Avatar
 
Location: South of the Great While North
Don't have time tonight to play with this... Here's something to get you started....

*****The Library Class*****

import java.io.*;

class Library {
// you might have some instance variable(s)

public void save(File outfile) throws IOException {
// this should probably save the library!
String tempOut = "";
PrintWriter pwriter = null;

if (outfile == null) {
throw new IllegalArgumentException("File is null.");
}
if (outfile.exists()) {
// prompt to overwrite file
}
if (!outfile.isFile()) {
throw new IllegalArgumentException("File is a directory: " + outfile);
}
if (!outfile.canWrite()) {
throw new IllegalArgumentException("Can not write File: " + outfile);
}

tempOut += "content that you want to print out.";

try {
// Create the file
pwriter = new PrintWriter(new FileWriter(f));

// Write to the file
pwriter.println(tempOut);

// Close the file
pwriter.flush();
pwriter.close();

} catch (Exception e) {
e.printStackTrace();
return;
}

}

Library(File infile) throws FileNotFoundException, IOException {
// this might actually load some data!
if (infile == null) {
throw new IllegalArgumentException("File is null.");
}
if (!infile.exists()) {
throw new FileNotFoundException ("File does not exist: " + infile);
}
if (!infile.isFile()) {
throw new IllegalArgumentException("File is a directory: " + infile);
}
if (!infile.canWrite()) {
throw new IllegalArgumentException("Can not write File: " + infile);
}

BufferedReader input = null;

try
{
//use buffering
//this implementation reads one line at a time

input = new BufferedReader( new FileReader(infile) );
String line = null; //not declared within while loop
while (( line = input.readLine()) != null){

// process line

}

input.close();

}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex){
ex.printStackTrace();
}

}

public String[] getBooks() {
// this method might return real data somehow!
String[] titles = {"Fix the getBooks method!"};
return titles;
}

public String getLongestBook() {
return "Fix the getLongestBookMethod!";
}

public String getShortestBook() {
return "Fix the getShortestBookMethod!";
}

public String getShortestChapter() {
return "Fix the getShortestChapterMethod!";
}

public String getLongestChapter() {
return "Fix the getLongestChapterMethod!";
}

public String[] getByAuthor(String name, boolean fuzzy) {
String[] titles = {"Fix the getByAuthorMethod!"};
return titles;
}

public int getNumberOfBooks() {
return 1;
}
}
__________________
"Reality is just a crutch for people who can't cope with drugs."
Robin Williams.
Chamaeleontidae is offline  
Old 02-17-2005, 09:11 PM   #5 (permalink)
Psycho
 
When do you want it by, and how much?
insidious_machinae is offline  
Old 02-18-2005, 03:36 PM   #6 (permalink)
aka: freakylongname
 
Chamaeleontidae's Avatar
 
Location: South of the Great While North
You would also need to post the data file, so we can see the format.
__________________
"Reality is just a crutch for people who can't cope with drugs."
Robin Williams.
Chamaeleontidae is offline  
Old 02-18-2005, 08:20 PM   #7 (permalink)
Crazy
 
Thank you immensely - to all who took the time to share information.

My goal is still to learn - and code contributions and pointers are greatly appreciated. However, I'm not going to pass by the opportunity of an individual willing to code for cash. After all, I'm on route to become a business man and when that day comes - I will be paying someone to write my code... why not do it now as well?

I would like to post a zip with both java files, the dat, and the doc. I have no web space to post it at... what's the best way?

And Rawb - you said exactly what I thought myself. I agree that that is exactly what I *need* to do, but I don't know how to build it. That's where my money *needs* to go.
__________________
I'd rather regret what I did do than what I didn't.
dr_lubin is offline  
Old 02-18-2005, 09:08 PM   #8 (permalink)
aka: freakylongname
 
Chamaeleontidae's Avatar
 
Location: South of the Great While North
Your ISP may provide tools and a location for a Private web page. If not, there are some sites that will give you free trial, and then low monthly fees, and one that appears to be free... e.g.
http://www.100webspace.com - 100 MB free hosting... be sure to select "Use a subdomain" on the signup page, or domain registration will be charged.
http://www.1and1.com - 6 months free, 25GB is $5 per month there after.
http://www.xdrive.com - 15 days for free, 15GB is $10 per month there after.
http://www.50megs.com - 250k max file size may be an issue, but 50MB is free.

Or you can PM me, and I will send you an address you can email the zip to.

What is the timeframe that you have for the project?
__________________
"Reality is just a crutch for people who can't cope with drugs."
Robin Williams.
Chamaeleontidae is offline  
Old 02-19-2005, 01:01 AM   #9 (permalink)
Insane
 
Kalibah's Avatar
 
Location: Padded Playhouse
if you do pay anyone would you be opposed to sharing the code? Im getting into java now- and deconstrution is the way I learn best
Kalibah is offline  
Old 02-19-2005, 06:39 AM   #10 (permalink)
Crazy
 
Quote:
Originally Posted by Kalibah
if you do pay anyone would you be opposed to sharing the code? Im getting into java now- and deconstrution is the way I learn best
No problem.
The deadline is the 28th, but I'd like it by the 25th to spend the weekend studying it.
__________________
I'd rather regret what I did do than what I didn't.
dr_lubin is offline  
Old 02-20-2005, 12:34 AM   #11 (permalink)
Psycho
 
My main concern is that if you're not coding this program yourself, how do you expect to advance any in your java competence? After only a year of classes in java, this program is relatively simple to me. It shouldn't take more than a few hours. 4 at maximum.
insidious_machinae is offline  
Old 02-20-2005, 11:19 AM   #12 (permalink)
Crazy
 
Quote:
Originally Posted by nwlinkvxd
My main concern is that if you're not coding this program yourself, how do you expect to advance any in your java competence? After only a year of classes in java, this program is relatively simple to me. It shouldn't take more than a few hours. 4 at maximum.
I have no interest in knowing any more than I need to - my degree is in management and IS... so I would be in charge of appointing people to do these tasks. If you can code this in 4 hours - please do. I'll reward you. I'll shake your hand even.
__________________
I'd rather regret what I did do than what I didn't.
dr_lubin is offline  
Old 02-20-2005, 11:48 PM   #13 (permalink)
Dreams In Digital
 
SiNai's Avatar
 
Location: Iowa
Man.. That's lame. If you need some help, get something in code and come back with something more specific. Even if it's nothing you're gonna be doing.. It's just dishonest- asking people to do your homework for money.

If I could, I would recommend "Java In a Nutshell" by David Flanagan. Its everywhere- you shouldn't have a problem finding it. There's tons of free help on the internet, too, if you're stuck on some specific part of the library, try java.sun.com for its APIs- thats saved me countless times.

" I'd rather regret what I did do than what I didn't. " Ehm..
__________________
I can't seem to remember now
What it was like- to live life, before you.. symbiont
SiNai is offline  
Old 02-21-2005, 12:25 PM   #14 (permalink)
aka: freakylongname
 
Chamaeleontidae's Avatar
 
Location: South of the Great While North
Quote:
Originally Posted by Kalibah
Im getting into java now- and deconstrution is the way I learn best

You might want to look into download deCafe or any of the other Java decompilers. There are enough sample Java apps and applets on the web to look at to see how things tie together...
__________________
"Reality is just a crutch for people who can't cope with drugs."
Robin Williams.

Last edited by Chamaeleontidae; 02-21-2005 at 12:28 PM..
Chamaeleontidae is offline  
Old 02-21-2005, 07:18 PM   #15 (permalink)
Psycho
 
I'm going to have to agree with SiNai, and so I retract my offer to code this for you. Use the http://java.sun.com API and you should be able to do this.
insidious_machinae is offline  
 

Tags
arrays, file, java, programming, simple


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 11:47 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76