Hello all =)
I'm working on a rather "simple" programming project this time. I believe I have a firm idea how I want to do it but not sure how to program it exactly. Here's what I'm trying to do:
My small program will take in a string argument, "yabba dabba dabba do" for instance. The output after running the program will eliminate duplicate words and add parantheses to each end, i.e. "(yabba dabba do)" will be the result. I know you can probably do this using the Vector class easily but I'm not allowed to use it, rather I have to create my own methods called "insert" and "toString".
Here is my code thus far (not much):
What I was thinking for the "insert" method would be like this (pseudo-code of course)...
Now I could be going about this the wrong way, I've been racking my brains because I can't seem to figure out how to create a substring in the temp string of just the recently recorded set of consequtive characters or word. Can anyone give me an idea of how to do that? Or am I making this way too hard and there is a better way to go about it?
Thanks,
Jisoo22
I'm working on a rather "simple" programming project this time. I believe I have a firm idea how I want to do it but not sure how to program it exactly. Here's what I'm trying to do:
My small program will take in a string argument, "yabba dabba dabba do" for instance. The output after running the program will eliminate duplicate words and add parantheses to each end, i.e. "(yabba dabba do)" will be the result. I know you can probably do this using the Vector class easily but I'm not allowed to use it, rather I have to create my own methods called "insert" and "toString".
Here is my code thus far (not much):
Code:
// A mutable list of Strings without duplicates
class UniqList {
class Item {
String s;
Item next;
public Item( String _s, Item _n ) {
s = _s;
next = _n;
}
}
Item head;
public void insert( String s ) {
// Start of my code for this method
String temp = "";
for (int i = 0; i < s.length(); i++;)
if Character.isDigit(s.charAt(i)))
temp = temp + s.charAt(i);
else
if ( s.substring
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("(");
// Start of my code for this method
sb.append(")");
return sb.toString();
}
public static void main( String args[] ) {
UniqList l = new UniqList();
for (int i=0; i < args.length; ++i ) {
l.insert(args[i]);
}
System.out.println(l.toString());
}
}
What I was thinking for the "insert" method would be like this (pseudo-code of course)...
Code:
for (int i = 0; i < s.length(); i++)
string temp = "";
if a character at position i is a digit
concatenate it to temp.
else
since it's not a digit (rather a space)
compare the substring of the word that's
now been copied into temp and compare with
substrings of equal length in the full s string.
if there is no match
leave it in the temp string
else there is a match
rid it from the temp string
Now I could be going about this the wrong way, I've been racking my brains because I can't seem to figure out how to create a substring in the temp string of just the recently recorded set of consequtive characters or word. Can anyone give me an idea of how to do that? Or am I making this way too hard and there is a better way to go about it?
Thanks,
Jisoo22