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

Thread Tools

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 12:52 AM.

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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360