BestJewSinceJC 700 Posting Maven

Inline documentation consists of comments in the code which are intended to clarify the overall logic of a program by commenting key points and mentioning their function. It makes the code easier to understand which in turn makes the code easier to maintain.

BestJewSinceJC 700 Posting Maven

I'm not sure what the android environment is, but if that is referring to the phone which I think it is, then check out Java ME. http://java.sun.com/javame/index.jsp

And then use the phone when testing.

BestJewSinceJC 700 Posting Maven

And keep in mind that from firstPerson's educated guessing you can derive a formula to always get the correct result without any guessing whatsoever, but again, I hope nobody wastes their time doing that for you.

BestJewSinceJC 700 Posting Maven

Yeah, it's simple enough, I already have it written. Just give me your teacher's email and your name and I'll send it directly to them and tell them it's you.

BestJewSinceJC 700 Posting Maven

Like I mentioned originally, I was aware that what S.o.S mentioned existed (and I agree with him that it is a better idea) if you want to learn XML in the future, or have any interest in continuing with it in any way. But the quickest way to do your current task would probably be the regular methods such as Scanner and Regex rather than learn how to use JDOM.

BestJewSinceJC 700 Posting Maven

Just google Serializable. Why would I bother to rewrite something that already has plenty of resources available? Especially when the available resources are written by people with more knowledge of the concept than I have?

If you want specific answers, ask specific questions. If you want me to write an article about Serializable, go away.

BestJewSinceJC 700 Posting Maven

Not that I'm going to help, because I'm not, but the origin of number systems has nothing to do with programming languages, so I don't understand your response, Seten.

BestJewSinceJC 700 Posting Maven

Very carefully. For example, if you use a regular expression, use a while loop to read in all of the text until it matches the beginning tag. Now that you matched the beginning tag, you know that the text you want to replace is next. Now skip over the rest of the text until you see the ending tag (also using a regular expression to find it). You can easily keep track of where you saw the beginning and end by doing that, and it doesn't really matter *where* in the file this occurs, as long as you've stored everything else. Once you see the ending tag, add that to the info to be written back out to file, and then add everything else after the end tag as well.

Edit: The index methods shown here show you how you can tell exactly where in the file the expressions were found. So if you use the Scanner class's nextLine() method, I think the way the XML file is formatted (with each tag on a different line, right?) will make your problem easier to solve. Just read in each line, use your regular expressions to search it. Since you already know what your tag is, though, it shouldn't matter what is inbetween originally... after you find the start tag just get rid of the rest of the line, put your text after the start tag, then add on the end tag, and write that back out to the …

BestJewSinceJC 700 Posting Maven

There are some sort of web services xml bindings for java, but it seems to me that you could just treat it as a plain text file, do a search for <JOBNAME> based on a regular expression, then do your editing and write everything back out to the file again.

BestJewSinceJC 700 Posting Maven

It can only do one operation (not two), addition is only one operation . . the reason it can only do one operation is because once the equal sign is clicked, you only scan through num1 and num2 and take an appropriate operation on those variables. In order to allow your calculator to take unlimited operations, when a button is clicked, you should add that button's text to an array. For example, if 2 is clicked, then +, then 3, your array would hold

Index | What it Holds
index 0 holds 2
index 1 holds +
index 2 holds 3

Now lets say + 4 + 5 is clicked, then it would hold

index 0 holds 2
index 1 holds +
index 2 holds 3
index 3 holds +
index 4 holds 4
index 5 holds +
index 6 holds 5

There is another way to do it where your calculator would constantly update the value it is displaying; for example, if you clicked 2 + 3 it would say 5, then if you clicked * 4 it would update to 20. This way is essentially exactly the same, except you're assuming that you've stored a "result" which computes up to a certain point in the array, then when the user keeps clicking more buttons, you add those to the array also, and you can (instead of recomputing the entire array), start from where you left …

BestJewSinceJC 700 Posting Maven

Then I would say the OP is confused by the lack of a no argument constructor. The no argument constructor is only automagically present if the class does not provide any other constructors. I.e., since FileReader has other constructors, the compiler would not provide a no argument constructor automagically, and the only reason one would be there is if someone had explicitly written one.

BestJewSinceJC 700 Posting Maven

You aren't bothering me and I'm happy to help. Just in the future please explain in advance exactly what your restrictions are (I have to/only want to do this using arrays) and what your problem looks like- for example, it would have been hugely useful to know you had "Number, marks, name, nationality, average" for each group.

P.S. you could have had a class that looked like the following:

public class Student {
int number;
int mark;
String name;
String nationality; 
float average;


public Student(int number, int mark, String name, String nationality, float average){
this.number = number;
this.mark = mark;
this.name = name;
this.nationality = nationality;
this.average = average;
}

}

Then you would have only needed one array declared as Student[] students = new Student[100]; and you could have put the students in it by doing this:

//Assuming you already read in, from file, your variables (no, marks, name, nationality, and average)
Student stud = new Student(no, marks, name, nationality, average);

To read in the variables you'd need a slight change since I declared some of them as int, not as Strings... you'd need to use Scanner's nextInt() and nextFloat() methods to read in the int and the float. But overall, this would make your program much simpler. Either way, I'm glad you figured it out and I shouldn't have been so harsh.. Good luck with your exams & whatnot.

Oh, and if you wanted to print out the Students, you could further extend what …

BestJewSinceJC 700 Posting Maven

If you have qualms with the clarity of the writing in the book, or with a particular bug in the code in the book, then why not email the publisher? Of course, the writing might be clear to some people but not to others: your claim that it is unclear is important and perfectly valid, even if someone else thinks that it is clear.

BestJewSinceJC 700 Posting Maven

Why would you think that you came up with a "simpler way" than what I suggested when you don't even know what a class (arguably the most basic unit of OOP) is? Additionally, you not only dismissed my solution to the problem, but then asked another question without answering my question about your problem: to further explain the 3 groups of students. I obviously didn't ask that question for my own good, so the only plausible explanation is that anyone responding to your questions needs to know that information to properly help you. Again, I strongly suggest that you read about the topics I mentioned above, as they will make your project a lot easier to do and more correct. But if you insist on using arrays and only arrays, then at least specify these problem restrictions in advance, as well as explaining your project goals, requirements, and inputs thoroughly, so that people like me don't make the mistake of wasting 20 minutes trying to help you only to be told that you've found a "simpler way".

BestJewSinceJC 700 Posting Maven

Anything that relies on the core Java classes rather than things like Networking. If I had your same concern I'd just do school projects from lower level Java classes. You're unlikely to find truly interesting projects, but they are designed to help you learn design.

For example, this project is a decent one for learning good design. It is basic enough that you won't get confused and bogged down by things like networking but that you can learn some important things about design. I wouldn't recommend trying to do the other projects on that page though, they aren't hard, just stupid.

BestJewSinceJC 700 Posting Maven

Yes; use Serializable. (Assuming all you want to do is save your JList and restore it when you restart, you can use Serializable to save your Objects, then you can easily restore them into the JList).

BestJewSinceJC 700 Posting Maven

I rarely need to use two dimensional arrays and I have *never* needed to use a three dimensional array. If you create an Object that represents one student, then you can use a one dimensional array and store a bunch of Students in it. You mentioned having three student groups. In order to properly design a program, you need to consider how these student groups are related, and how they are different. For example, since they are student groups, I am assuming they have certain things in common (typical students all have transcripts for example, and all have to pay tuition). So where does this knowledge fit into a Java program? Well, it helps you to design classes that make sense. If you don't know about Java classes, Java Objects, and inheritance, I suggest you start getting familiar before trying to do this program. The basic idea is that you can design a Student class and you can store in it everything you want to about a Student. Then you can create an array (1 dimensional), create a bunch of Students, and put the Students in the array. If you want to, you could make your Student class be the parent class, and then you would have the three following classes: "public class StudentGroupOne extends Student", "public class StudentGroupTwo extends Student", "public class StudentGroupThree extends Student".

Anyway, I hope that is helpful but it is hard to discuss it abstractly - if you know nothing about Objects and classes …

BestJewSinceJC 700 Posting Maven

It does seem very unclear. What do you mean by the recursive definitions? What does recursion have to do with a linked list, other than possibly traversing it (and still, why would you use recursion to do that?)

BestJewSinceJC 700 Posting Maven

This seems like a fairly simple (conceptually) program to me, although actually implementing it could be quite tricky. You need a typical client server setup (and I'm assuming your server will only accept one connection at once); Java sun has a tutorial I read in the past that is pretty simple. I'll link you to that but I wouldn't consider the problem you face right now a problem that will really help you with your design skills... if you want to learn good design in Java, you are better off doing other projects that might seem more simple, but actually lend themselves to good design more easily. And I'd love to help you become better with design but it can't be taught lecture style, if you want to get help with design, you should plan out a project, post your ideas including classes, methods, etc, and ask for criticism - there are a lot of experienced java programmers here who'd be glad to help.

http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

P.S. when I say this project doesn't really lend itself to good design, I only mean that I think it is a pretty small project which doesn't involve a lot of classes or a lot of methods, and additionally it involves networking, so it would be harder to learn design on a project like this than it would on a traditional style project.

BestJewSinceJC 700 Posting Maven

I definitely saw this exact same question answered here on daniweb in this forum within the last 6 months. It seems pretty obvious why you're getting that error (since, in fact, the error itself explicitly says why you're getting it); how to solve it is a different story. Why don't you search the forum?


edit: for example, this thread has some of the same search terms in it. Why don't you check it out.
http://www.daniweb.com/forums/thread168656.html

BestJewSinceJC 700 Posting Maven

Strangely, I always get java updates as well that seem unnecessary (not that that is what you were complaining about). I tell my Vista OS to accept the updates but it seems to ignore me, and periodically, it keeps asking me to update again with what seems to be the same update I already accepted.

BestJewSinceJC 700 Posting Maven

Haha, thanks. Pretty odd that I never thought of that one. Now I feel stupid.

BestJewSinceJC 700 Posting Maven

Well I figured it out, uname is the command I was looking for.

BestJewSinceJC 700 Posting Maven

I'm wondering where to find what values system() accepts. For example, I want to list the server's OS type. I already did man system, did not find it very useful. And google is returning a lot but nothing relevant.

BestJewSinceJC 700 Posting Maven

Good idea

BestJewSinceJC 700 Posting Maven

From what you posted strncpy looks fine

stncpy(something, "whatever", 7);

note the string "whatever" is nine characters....or maybe you should use

stncpy(something, "whatever", strlen("whatever"));

Ok, it just seems strange compared to how easy it is in Java. Anyway, did you mean 8 characters, because from the docs it seems like the null terminator is not included (and whatever by itself is 8 chars).

BestJewSinceJC 700 Posting Maven

Nevermind my last question, I just realized that I can just redirect the output to the socket (assuming this is possible which I think it is) and that should work.

BestJewSinceJC 700 Posting Maven

Like I said, I looked through the Strings.h header file and documentation but I am sure that there is a better way to do it. I wanted to know what that better way is. So it doesn't really matter whether or not it works, but what the best way to reset the string is. Anyway, I give help here far more than I ask for it. Do you think I don't do any programming myself, and just pop in and ask questions once every 3 months when I actually program something? No, I program constantly, I just seldom ask questions because I can usually figure out on my own, so why not give me the benefit of the doubt and just either A) answer the question or B) don't respond to the thread.

Thanks :)

P.S. I'm currently attempting to figure out how to issue system commands on my server such as pwd and ls, then return the results to my client, but I cannot find any useful references, so if you want to help with that, please do.

BestJewSinceJC 700 Posting Maven

Hey guys, simple question that I don't see anything on in the String.h library and I can't remember from my C class 3 years ago. I have the following declaration:

char something[100] = "whatever";

And later in the program I call strncpy. After calling strncpy, at some later point I want to reset something to "whatever" again. Is this the best way to go about it? (If this even works, which I'll test in a second - but either way is there a better way?)

something[0] = '\0';
stncpy(something, "whatever", 7);

BestJewSinceJC 700 Posting Maven

Well, I gave him some reputation, and your gratefulness is probably enough anyway. After all, people don't usually help on forums because of all the money they'll make from it. :) But good luck on your project; sorry I couldn't be of more assistance, but I was in a rush and I didn't understand the full scope of your problem.

BestJewSinceJC 700 Posting Maven

From what I remember SwingWorker is used when you have a long running task that you need to run. The reason you'd use SwingWorker is to run your long running task in the SwingWorker thread so that the task does not block up your GUI, causing it to appear unresponsive. You can use the class from within a Swing application... as the name SwingWorker might imply. You might also be able to use it elsewhere. Also, I should note that asking these types of questions is definitely discouraged. I'm briefly avoiding studying for my computer algorithms test so I answered you but ask something more specific.

BestJewSinceJC 700 Posting Maven

I understand James' point about toString, and he is correct, but if I were you I would probably just write the toString method (without calling it toString though) and use it to get an ideal String representation for your list to display. I can't forsee problems with that in the future.

BestJewSinceJC 700 Posting Maven

You can definitely have a resource base in SVN.... but if you don't want to use SVN I've heard of google code, you might want to check it out.

BestJewSinceJC 700 Posting Maven

Yep, thanks for the reply.

BestJewSinceJC 700 Posting Maven

In case anyone was wondering, I emailed my TA about this (since I got no response here, which I thought would be much faster) and I received the following response:

Yes, it works as you said, but you have to check @$@$ four characters.
Another way is you use @@ to represent the real @ in the text, and if
you see a @ followed by a $, then you know it's the end of file.

I forgot to ask him what the advantage of this was, but it seems like there is no advantage to using @$ instead of just @. In any case, maybe I'm wrong, but there you have it.

BestJewSinceJC 700 Posting Maven

That piece of paper isn't nearly as necessary as the job ads would have you believe.

Yet how many people do you know who have a programming job who don't have some sort of degree or certification? I thought you were a manager of some sort - if so - would you actually consider someone for a job with no compelling experience (i.e. they have impressive projects to talk about) or a "piece of paper", or would you toss out that person's resume?

@Garrett - it doesn't matter what your motivation to learn programming is. Even if your motivation is to make a lot of money, you are still capable of learning. But regardless of what anyone says, it is much harder to learn without having somebody there to tell you what it is that you're supposed to be learning. I think joining some open source projects may be a good idea, but you should learn the basics first. Just hop on a good engineering college's class sites and start doing the projects to make sure you grasp the basics first. You can easily figure out what the basics that you're expected to know are by doing that. Then you can move onto harder stuff which would include Narue's suggestion.

BestJewSinceJC 700 Posting Maven

No problem, mark solved threads as solved

BestJewSinceJC 700 Posting Maven

In the mouse moved method, say "if(downA == false)return;" as the first statement in the method.

BestJewSinceJC 700 Posting Maven

If I was using @$ as my flag pattern (to signal the end of the data) what would I do if @$ was seen in the data? I would just stuff another @$ right after it in the sender and in the receiver, if I saw two consecutive @$ I would remove the second one (and not include it as part of the data) ... right? And what advantage does using these two bytes have over just using one byte such as 01111110?

Thanks.

BestJewSinceJC 700 Posting Maven

It takes a lot of dedication to come up with good problem sets, and you also have to be capable of personally solving the toughest problems. I'm not saying you can't do that, but I would just see if Sane doesn't mind if we use his problems over here and give him credit for them. (I'm assuming a link to PFO in this case is ok since it is a daniweb sister site?) programmingforums.org go check out Sane's problem sets, they are very good. I seriously recommend talking to him and seeing if he is ok with using them over here (I can't imagine he would mind - after all, they are for educational purposes to begin with).

BestJewSinceJC 700 Posting Maven

Sorry, that was probably too complicated...

As another example, lets say you have an Address Book. The address book, for each entry, contains the person's name, their phone number, and their other information. Now you could use their name as the key and their Address Book entry as the value. So any time you want to know what John Smith's phone number is, you can look it up quickly by hashing John Smith, going to that index of the hash table, and checking for his address book entry.

BestJewSinceJC 700 Posting Maven

http://en.wikipedia.org/wiki/Hash_table

The linked list is only needed because if the hash function maps multiple keys to the same index, and you don't have some mechanism for letting two things go there, you're screwed.

After you read the wikipedia page above, you'll have a decent idea of what is going on, I think. If not, after you read that link, try to follow this example of why I used a hash table in a project:

I wanted to implement a tic tac toe game where the computer at first guessed randomly, but then got smarter and smarter the more times it played. Obviously, then, it needs some way to remember what its good moves are and what its bad moves are. So I created a few things:

1) A "snapshot" which consisted of a picture of what the board looked like on a particular turn, and whether the computer won or lost that game. This snapshot basically consisted of a series of X, O, and _ for each square of the board. As you can see, that makes my keys unique, because each turn has a different representation of X's and O's and _'s. My Snapshot Object also contained the # wins, # losses, and # ties that resulted after that Snapshot.

2. A hash function that took my snapshot sequence of X's O's and _'s and converted that to an index within a reasonable range. Then, I stored the Snapshot in the hash …

BestJewSinceJC 700 Posting Maven

I'll give you a small sample program to help you figure out the rest of this project on your own. If you don't show any effort though, you won't receive any more help.

LinkedList<Integer> list = new LinkedList<Integer>();
		list.add(2);
		int index = list.indexOf(2);
		list.add(index, 1);

P.S. I intentionally didn't do any error checking, but you should look at this link to see what happens if you search for something using indexOf which turns out isn't actually in your list. And you should read about the add method that I used to see why it does what you need it to do.

BestJewSinceJC 700 Posting Maven

1. Read about LinkedLists on wikipedia or elsewhere
2. Use Java's LinkedList class
3. To insert things in a linked list, consult the documentation's insert method
4. To figure out where you should insert a value, you can easily use a LinkedList of Integer Objects, then search for the Integer with the value of one thing (such as "1"), which will return the index where "1" is found... so you know 2 will need to be inserted one index to the right.

BestJewSinceJC 700 Posting Maven

The JVM? (I know what it is and does, but why are you mentioning it?)

And arrays always have to be defined in advance, so hypothetically, if you wanted to keep an instance variable for its length, no, you would not need to call array.length ever again.

BestJewSinceJC 700 Posting Maven

Use a JLabel to display the guessed-so-far word. If a letter hasn't been guessed correctly it should display "_" instead of the letter, which is why you'll need to space your word also (so the _ don't run together, looking like a line). Use a String internally in your program to remember the correct word. Use a keyboard of JButtons to display the letters a-z. Once the user clicks one, use jbutton.setEnabled(false) so they can't accidentally click the same letter again.

There are undoubtedly a thousand other ways to do this program but if you don't want to do it my way, then think a little for yourself, try to do the project, and tell us where you're getting stuck. If you want, you can propose specifics about how you plan to do your project and I'll tell you if it is going to work or not.

BestJewSinceJC 700 Posting Maven

Well. . even among the dedicated members, there is a lot of variation in skill here. Wouldn't it be better to have 3 different levels, similar to Sane's challenge at Daniweb's sister site, PFO?

BestJewSinceJC 700 Posting Maven

if you do things like removeAll() on a JFrame or JPanel, then after adding new panels, you might need to call revalidate() or validate(). I've told people that before and they've reported back success, so go try it and let me know. If that doesn't work, post all of your code so that I can run it and I'll help.

BestJewSinceJC 700 Posting Maven

Not only did you PM me about this issue, which is technically against the rules, but you didn't answer my question. Do you want the problems to be chosen from a list of problems which were previously created in advance, or do you want to "randomly" generate a problem?

BestJewSinceJC 700 Posting Maven

Java or Python