I need help with some homework. I need to create a linked list of all file names in a directory that end with .class. Can anyone help?
CANEHDN said:I need help with some homework. I need to create a linked list of all file names in a directory that end with .class. Can anyone help?
class LinkedList {
class Node {
int data;
Node next;
Node(Node next) {
this.next=next;
}
Node getNext() {
return next;
}
}
Node start;
}
import java.io.*;
import java.util.*;
public class ClassFileLister
{
public static void main(String[] args)
{
for (String name : new LinkedList<String>(Arrays.asList((new File(args[0])).list(new FilenameFilter() {
public boolean accept(File directory, String name)
{ return (name.endsWith(".class")); } }))))
{
System.out.println(name);
}
}
}
import java.io.*;
import java.util.*;
public class ClassFileLister
{
static class ClassFilenameFilter implements FilenameFilter
{
public boolean accept(File directory,
String name)
{
return (name.endsWith(".class"));
}
}
public static void main(String[] args)
{
String desiredPath = args.length > 0 ? args[0] : ".";
File desiredPathFile = new File(desiredPath);
String[] classFileNameList = desiredPathFile.list(new ClassFilenameFilter());
LinkedList<String> classFileList = new LinkedList<String>(Arrays.asList(classFileNameList));
for (String name : classFileList)
{
System.out.println(name);
}
}
}
CANEHDN said:I know what they are. This is card game program we're writing and each card has to be written as it's own class. It's a pretty big project.
rand0m3r said:maybe he meant each card is an object.
rand0m3r said:maybe he meant each card is an object.
CANEHDN said:Have you guys ever heard of Munchkin? We're writing a networking game of that. We decided to make each card it's own class because of the all the different things each card can do. We figured it would be easier to do it that way.
CANEHDN said:We will be scanning every card and having the images display. We will also have door cards and treasure cards. But in order to have full effects from each card the best way to do it is each card have it's own class.
savar said:Hey man, I guarantee you that its not the best way. I took a look at the game and perused the rules quickly. 168 cards!?! 168 classes is a *huge* application, especially for some intro CS students.
Agreed. A single "Card" interface (to be implemented a few times) and a good set of data will be much cleaner and much more educational than brute-forcing 160+ classes.SilentPanda said:But to the OP... seriously... listen to what others have said about not making 168 class files.
CANEHDN said:Our card class which all monsters will inherit from will have the similar traits such as level ups and downs but when it comes to the special things that a lot of cards have you have to do something else. This also makes it easier when adding new cards such as the expansions. You won't have to go and change code already written.
bousozoku said:Then again, what project is more frequently maintained than a beginner's project?
SilentPanda said:There's nothing more fun than looking at code you wrote "in your early years" and remembering... "it took me 3 weeks to read in a text file?"
Not to mention that it's just offensively ugly. Good design, though, is beautiful.bousozoku said:Poor design = waste of effort later.