Click to See Complete Forum and Search --> : Creating an Implementation? (Help)


soladragon
03-10-2008, 08:43 PM
Can anyone help me? any type of help at all.

I need to create an implementation called Pirate that just outputs phrases chosen randomly from a pirate.txt file, it must also include this code:

Talking pirate =new Pirate(“pirate.txt”);
System.out.println(pirate.talk(20));

Might output ‘avast ho pieces of eight’

:) thankyou

chazzy
03-10-2008, 09:10 PM
What if it just wraps java.util.properties?

soladragon
03-10-2008, 09:13 PM
I don't understand what you mean?

chazzy
03-10-2008, 09:32 PM
maybe i don't understand what you mean.

i think you're looking for some help in figuring out the problem. i proposed a solution, using java.util.Properties, which you might say you don't know what it is. i would then tell you to look up the javadocs.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html

soladragon
03-10-2008, 10:12 PM
Erm I think I see what you mean, but have no idea how ill include it... hmmm any ideas?

chazzy
03-11-2008, 06:41 AM
so now we're at the point where you ask me to write your homework for you, right?


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

public class PirateTalker
{
private Properties vocabulary;

public PirateTalker() throws Exception
{
vocabulary = new Properties();
vocabulary.load(new FileInputStream(new File("the path to your file goes here")));
/*
* The properties file should contain values like
* 1=YAARGH
* 2=SHIVER ME TIMBERS
* 3=SOMETHIGN ELSE A PIRATE SAYS
*/
}

public String talk(int position)
{
return vocabulary.getProperty(position+"");
}

public static void main(String[] args) throws Exception
{
PirateTalker talker = new PirateTalker();
talker.talk(1);
talker.talk(2);
}
}