BestJewSinceJC 700 Posting Maven

These are the two important pieces of code:

public int setCreditHrs()
{
       return creditHrs;
}

if(!student.setCreditHrs(hrs))

Mistakes:

1. As you can see, in the first piece of code, you have declared your method as "public int setCreditHrs()". What this means is that the method returns an int (where it says "int" before the setCreditHrs) and when you call this method, you cannot call it using an argument (the () have nothing in between them). So to call this method correctly you'd use student.setCreditHrs(). You said "student.setCreditHrs(hrs)", which is incorrect, because you are passing one argument to a method which was declared as taking no arguments. As an example, if you wanted to pass a float argument to your setCreditHrs method, the method would be defined as

public int setCreditHrs(float nameYouGiveItHere)
{
       return creditHrs;
}

And it would be called by student.setCreditHrs(someFloatHere).

2. Methods which are declared as "setWhatever" usually "set" the whatever to something. Currently, the method declaration you posted "gets" something (it returns something). So your method is named one thing, but it is doing another thing. An example of a typical set method:

public class Example{
float something; 

   public void setSomething(float otherThing){
      something = otherThing;
   }

}

3. if(!student.setCreditHrs(hrs)): This will produce an error since you can only use an if statement to check boolean values for true or false. So (the way you have your code as of your first post) something like if (student.setCreditHrs() == 0) will work, because "==" evaluates …

BestJewSinceJC 700 Posting Maven

Probably, do a google search for them. If you're talking about simple differentiation and integration (i.e. power rule) then it is trivial anyway, and so is chain rule for differentiation. Why don't you mention the specific formula you're trying to code and then show some progress or ideas etc on it.

BestJewSinceJC 700 Posting Maven

@bluerose

I think javaAddict conveyed that same point with his post. Please don't repeat people for the sake of posting (unless you're adding something to the discussion), otherwise, you'll become like adatapost.

BestJewSinceJC 700 Posting Maven

From what I remember, essentially, they both dynamically (while the program is running) allocate memory for your program, and the main difference is that calloc sets all the memory (that it allocates to your program) to zero's while malloc does not. So after calling malloc, the memory that was set aside for your program would still have whatever 0'1 and 1's were in the bits before, but for calloc, all those bits would be set to 0's.

BestJewSinceJC 700 Posting Maven

gcc -ansi -Wall


w00t w00t.

BestJewSinceJC 700 Posting Maven

We can't "give" you the code. In a BST, numbers greater than the value of the current Node are in its right child, and less than are in its left child. Therefore, if you're looking for a certain value/Node, just search logically until you hit that Node. Then return it.

BestJewSinceJC 700 Posting Maven

it was only the comment i'd not changed, it should return an int as the map is set up to have.....thanks for spotting that though! the file contains int,string,int so i shouldn't be using a double anyway.

so how do i put the values into the map knowing they are of the correct type?

As long as you change the variable that I mentioned previously to type "int", the line that you thought wasn't working should work. So declare "pitchTarget" as int, not as double, then tell me if you're getting an error.

BestJewSinceJC 700 Posting Maven

pitchTarget = lineScanner.nextInt(); // return the next token as a double
targetMap.put(taskNumber, pitchTarget); //this is the line that doesn't work

Your first line I posted doesn't make sense. The nextInt() method does not return a double, it returns an int. And your treeMap is declared as taking a K, V pair of Integer, Integer. So you won't be able to use TreeMap.put(integer, double)...

BestJewSinceJC 700 Posting Maven

You're creating a new Student Object, when what you want to be doing is getting the data from an existing Student Object. What exactly is students.keySet()? I don't know what "students" is, nor do I know what the keySet method does, so I can't help you until you post the relevant code.

BestJewSinceJC 700 Posting Maven

Huh? The main method is the method that runs automatically when you run a .java file, or when you click 'run' (or the corresponding button) in Eclipse or Netbeans or whatever editor you use. If this isn't the case, then tell me what method is running first in your code...

BestJewSinceJC 700 Posting Maven
for (String name: this.students.keySet())      // line 1
  {
    System.out.println("Student " + name + ":"); // line 2
    //this line should call the displayMarks() method from the class student, but whatever i try doesnt work
    System.out.println();
  }

In order to call a method of the class Student, you must use an Object of type Student. You are iterating through a Collection of Strings ("name" is a String) so you can't use it to call the Student class. Change your for loop to iterate over Students...

BestJewSinceJC 700 Posting Maven

You would just add "\n" to the String you are outputting whenever you want it to go to the next line. Is this even your code? That seems awfully simple to not know for such a complicated piece of code, so maybe I misunderstood your question.

BestJewSinceJC 700 Posting Maven

No. I literally mean post the method that is declared as "public static void main(String[] args)"... this is the method that is executed when you run your program.

BestJewSinceJC 700 Posting Maven

Yeah, it seems like your add method is trying to add a Node in sorted order... instead of just adding it at the end of the list.

BestJewSinceJC 700 Posting Maven

IntNode cur = head;
IntNode prev = cur;

Doesn't make any sense. You're essentially assigning cur = head, then prev = head. Do you mean to say:

IntNode prev = cur;
IntNode cur = head;


?????

BestJewSinceJC 700 Posting Maven

post your main method...

BestJewSinceJC 700 Posting Maven

by clicking the "mark as solved" blue link thats at the bottom of the last post

BestJewSinceJC 700 Posting Maven

Yeah, no problem. Mark the thread as solved

BestJewSinceJC 700 Posting Maven

I edited my post, re-read it. There is no way your file is just named "name". It would be named "name.txt" at the very least. And if it was not in the same directory as your .java file, you would need to specify the directory such as "C:/name.txt" or wherever it is.

BestJewSinceJC 700 Posting Maven

You probably aren't creating the FileReader Object correctly, due to having an incorrect pathname for the file. For example, if your file's name was name.txt, but it was located on the Desktop, you would have to use "C:/Users/yourUsername/Desktop/name.txt" where you have "name".

BestJewSinceJC 700 Posting Maven

There is no such thing as linux programming. Linux is an Operating System, not a programming language. As far as I know, the Linux operating system kernel is written in the C programming language.

BestJewSinceJC 700 Posting Maven

You should also create another thread and explain your problem in there.

Mark this thread as solved, go start a new thread, and post the specific problem you are having in there. You should at least be able to identify a portion of code that isn't working. At this point, when the thread is 3 pages long, the people who have been helping you probably don't remember everything about what problems you were having, the people who have been helping you probably don't know which problems you successfully solved and which remain unsolved, and the people who weren't helping you don't want to read 3 pages in order to figure out what is going on in here. I explain all of this only because you ignored my advice last time.

BestJewSinceJC 700 Posting Maven

To get the size of a file, you use file.length(). This tells you how many bytes the file is. Is that all you needed to know?

BestJewSinceJC 700 Posting Maven

http://java.sun.com/javase/6/docs/api/java/io/File.html#length(

That is the documentation for the File class. You are trying to use the length() method with an Object of the class FileReader, when in fact, the length() method is a method of the class File. Go back and re-read my original post to you. You're obviously pretty confused, so I'll give you some code examples to help. Typically we aren't supposed to give away code on daniweb, but considering the simplicity of this, I'm going to assume you gave it effort and are just confused by my explanation. I can't really explain it any differently, so maybe seeing the examples along with the explanation will clarify things:


This is how you do it with a FileReader. Remember, with a FileReader, you are reading through everything in the file, character by character, and incrementing a counter. The final value of the counter is how many characters were in the file.

while((int i = fileReader.read()) != -1){
counter++;
}

Now, below is a different way of doing the same thing. Below is how you do it with a File Object. You already created a file Object, so I'll use the one you created, and call it's length() method. The length() method for the File class tells you how many bytes are in the file. Since a character is usually represented by one byte, this also tells you how many characters are in the file.

File file = new File("name");
System.out.println("Chars in the …
BestJewSinceJC 700 Posting Maven

All of the ways I mentioned are pretty easy, but the easiest way would be to make a File object (like you already did), and then use file.length(). file.length() returns the number of bytes in the file, which is the same as the number of chars in the file.

(Note: on some systems, chars may be two bytes, in which case, what I just said would be incorrect. Do a simple test with a small file and count it by hand to make sure)

BestJewSinceJC 700 Posting Maven

No, it does not, because Scanner's hasNext() method does not get the next character, or get anything for that matter. It tells you if the Scanner has any more tokens in its input, and it does not advance past any input. So you'd be sitting in an infinite loop (if there were actually tokens). A token is just matched by the delimiter pattern, which by default, is whitespace. So if you had the following:

blah deee weeee

The first token is blah, the second is deee, and the third is weeee. Anyway, I don't see why you don't just construct the file Object then use the File's length method to see how many bytes are in the File, which tells you how many characters are in the file. Here is the documentation I am referring to when I'm talking about Scanner and File. Although it is a good idea to get familiar with both, so you don't need to look it up.
http://java.sun.com/javase/6/docs/api/java/io/File.html#length()
http://java.sun.com/javase/6/docs/api/java/util/Scanner.html#hasNext()

Alternatively, you can either look up FileReader here on Daniweb (this will bring you to other threads where people had similar questions to the one you are asking), or you can look at this documentation: http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileReader.html . In particular, consider using the read() method of the FileReader class after you construct your FileReader object. It reads a single character at a time.

The modification of your program, one way or another, to produce the correct result …

BestJewSinceJC 700 Posting Maven

Linux is an operating system. Java is a programming language. Coincidentally, java should run the same on Windows and Linux (don't count on it) but if this was a C++ program, you would not have the same luck.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/javase/6/docs/api/java/lang/String.html

What do you think indexOf does? I can't really clear up the problem without knowing what you expect it to do and what it is doing.

BestJewSinceJC 700 Posting Maven

One test program is worth a thousand expert opinions.

(Not that I'm an expert, because frankly, I'm not. But it's the truth.)

BestJewSinceJC 700 Posting Maven

Personally, my first instinct would be to write a listener method that got the text, counted how many characters were there, and "refused to let more be entered" by setting the text back to whatever was previously there if the user entered too much. That would work, however, my first instinct would probably be a waste of time, because there are other available methods of doing the same with less effort and probably less code.


At this link, it describes that you should either use a JFormattedTextField (you're using a JTextField) or you should use a Document listener. It gives links to both. If you want to use a JTextField, stick with the document listener.
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html

Ezzaral commented: Good suggestion. +22
BestJewSinceJC 700 Posting Maven

Well, first of all, I'd make it Object Oriented. . so the board would be part of a class, and you could create a new board by creating a new Object of that class type. You would also need two types of constructors: one that took an existing board (so that your new Object's board would be the same as the previous board). And one empty constructor, which would create a blank board.

BestJewSinceJC 700 Posting Maven

I don't see how this is a question of what function you are using. Generate a pseudo-random number, then use the modulus operator to force your result to be between 0 and whatever. Then use addition to bring that result between 10 and 20.

BestJewSinceJC 700 Posting Maven

If you want to start a completely new game, then the ideal way would be to have Life set up as a class, and you'd simply create another Object of that class type. Alternatively, you could set all your variables back to blank/however they were initially. But if you're referring to somehow continuing a game already in progress, then nevermind what I just said. You should also create another thread and explain your problem in there.

BestJewSinceJC 700 Posting Maven
if (stream != null) {
    stream.close();
}

return stream.read();

Why would you close the stream, then read from it? ....

BestJewSinceJC 700 Posting Maven

I don't know that this is the best way to do it, but why not use a for loop that goes through the String[][] and setValueAt(Object, row,column) to update the JTable.

BestJewSinceJC 700 Posting Maven

Ok, well I stand corrected. My apologies.

BestJewSinceJC 700 Posting Maven

No, it doesn't. It causes an error because the code doesn't make any sense. Where else have you seen ()[] and brackets used interchangeably?

BestJewSinceJC 700 Posting Maven

Once you select the item in the combo box, it will appear in the JTable automatically, using whatever the default JTable code is, so you must have overridden a method or something. Anyway,

return rosterList.get(row)[col];

What does that do? Looks like it causes an error. If you go to your error message like Ezzaral said, let us know if it points to that line.

BestJewSinceJC 700 Posting Maven

Nobody is going to do your project for you. Either read the forum rules or go away.

BestJewSinceJC 700 Posting Maven

How do you plan on using that tool? Looks like more trouble than it's worth. If you have the skill to do this, then by all means. Otherwise code it up yourself. Keep in mind that exchange rates frequently change, so you should not just hard code the current exchange rates into your program. Instead, use a file or some way to easily store the exchange rates that they can be changed without recoding and recompiling your program.

BestJewSinceJC 700 Posting Maven

If you want to read from a file and count how many characters are in it, use FileReader or FileInputStream, not InputStream, since you cannot open a File with InputStream. Then use a while loop like they said, incrementing a counter for each byte you read. The final value of the counter is how many characters were in the file.

Also, note that FileInputStream is not recommended for reading characters. I'm not sure why, but a wild guess would be that it deals with the fact that chars in Java are 16 bits, but chars on your computer might be represented as 8 bits. This might be completely wrong, feel free to do some research on your own.

[FileReader] Convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate. To specify these values yourself, construct an InputStreamReader on a FileInputStream.

BestJewSinceJC 700 Posting Maven

From my assessment, the JPanel is sized according to the LayoutManager of the container that it is in. In this case, it is in the JFrame. So calling getSize from the JPanel's constructor doesn't make much sense. When it is still in the constructor, your JPanel isn't even finished creating yet, so how could it's height possibly be anything other than 0 unless you explicitly set it to something other than 0? And the JPanel also isn't visible yet, so its height will be 0. In any case, consider this code:

public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame = new JFrame();
		JPanel panel = new JPanel();
		panel.add(new JButton("what"));
		frame.add(panel);
		frame.setSize(200,200);
System.out.println(panel.getSize().height);
		frame.setVisible(true);
System.out.println(panel.getSize().height);
	}

This prints:
0
166

This example is meant to show you that if your panel is inside another Component, such as my panel being inside the JFrame, the panel will be resized according to the size of the JFrame. However, in your code that you are having trouble with, since your panel hasn't finished being created (and your frame has not yet been setVisible), the JFrame has not resized the panel yet. Therefore, its height is 0.

Now consider this piece of code:

public static void main(String[] args) {
		// TODO Auto-generated method stub
		JPanel panel = new JPanel();
		panel.setSize(0,166);
		System.out.println(panel.getSize().height);
	}

This is just meant to show you that one way the panel could have a height other than 0 is if you …

BestJewSinceJC 700 Posting Maven

Add a JLabel to your JPanel, then add a JTextField next to it. The user can type in the JTextField. The resources I gave you were definitely sufficient to accomplish this so until you post some code, I can't help you anymore.

BestJewSinceJC 700 Posting Maven

Did you try calling setSize on the JPanel, then calling getSize afterwards? Also, post your code.

BestJewSinceJC 700 Posting Maven

1) Is it possible to add 6 columns while the last column is a drop down menu that takes care of the last 10 textfields data which would be entered upon the submit button?

You can find code similar to this on the Java tutorials by looking up JTable stuff, but here is an example I wrote, slightly modified to fit your purposes. You'll notice that the TableColumn is attained by using getColumn(5), which means the TableColumn refers to your 6th column (which is what you requested in your explanation). Then that TableColumn's cell editor is set to be a JComboBox, which means when you click the column, the JComboBox will pop down, displaying whatever you put in it.

javax.swing.table.TableColumn column= jTable1.getColumnModel().getColumn(5);
        javax.swing.JComboBox comboBox = new javax.swing.JComboBox();
        //add your stuff in an ArrayList called list to the ComboBox as Strings. . 
        for (int i = 0; i < list.size(); i++){
           comboBox.addItem(list.get(i));
        }
        column.setCellEditor(new javax.swing.DefaultCellEditor(comboBox));
BestJewSinceJC 700 Posting Maven

Judging by the fact that you got the expected output, and not an error, it seems like a safe assumption, doesn't it? If you're concerned about it, run some tests on varying inputs. You'll probably find that it works fine. My guess is that the toLower() function uses the ASCII table to verify that something is a letter and acts appropriately (there are plenty of symbols that aren't letters OR numbers). Also, are you sure you can't look at the function's code yourself, by looking in some standard library?

BestJewSinceJC 700 Posting Maven

For the first window where you click to continue, you can look into the JOptionPane class. It has a lot of different options for creating windows quickly and easily. Alternatively, you can create a custom window by using that tutorial I showed you. Look for the tutorial on using buttons , and look at the code examples they have of where they made windows with buttons on them.

But the easiest way to do it is with JOptionPane, see here: http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
If you do a google search for JOptionPane and go to the Javadoc, you'll see all of the different ways you can create windows with it. One example is JOptionPane.showMessageDialog(null,"this is whats in the window");

BestJewSinceJC 700 Posting Maven

Oh ****, what a waste of time. I didn't even realize that this noob had upped an ancient thread.

BestJewSinceJC 700 Posting Maven

What do you mean "create the box"? Do you mean a button that the user can click on, or do you mean the window in which your content (the pictures saying buy it) is displayed?

Look into how to create and use JFrames, JPanels, Layout Managers, JButtons, and JLabels. You can start here. Feel free to ask some questions after getting an overview. http://java.sun.com/docs/books/tutorial/uiswing/components/index.html

BestJewSinceJC 700 Posting Maven

Agreed. There is also some order to which you need to malloc if I remember correctly. I don't remember the order though -- outermost dimensions [of an array] first? I'll look it up.