BestJewSinceJC 700 Posting Maven

It seems like you already figured out how to get the Characters from the ArrayList and compare them to see if they are the same. Now all you need to do is write a for loop that prints from 1 . . n where n is the number of elements in your ArrayList. But once you get to the index where the Characters are that you were supposed to compare, you need an if statement to decide whether to print out the Character itself or whether to print out the index.

P.S. Masijade wasn't being rude, just straightforward. You seem to have the basic idea down, so if you know how to use a for loop and an if statement, you should be able to do this.

BestJewSinceJC 700 Posting Maven

Other things you should be aware of:


1. The two statements inside of your constructor do not do anything. You assigned inputMile equal to itself and then you assigned outputKm equal to itself. I think you meant to set inputMile to inputField and outputKm to outputField.

private Chapter165(JTextField inputField, JTextField outputField) 
    {
    	          this.inputMile = inputMile; 
                  this.outputKm = outputKm;
    }

2. If you used an IDE, such as Eclipse, a lot of your errors would be made apparent to you right off the bat. For example, the only reason I noticed the logical error in your code above is because I pasted your code into Eclipse and it immediately pointed out that your statement didn't do anything.

3. For example, other things that Eclipse pointed out to me about your code: you declared a variable named "text" inside of your if statement, but you never used that variable. Same thing goes for your variable "milesKm", which you declared in two different if statements but never used in either one.

4. You have statements in your code such as
"double input = Double.parseDouble(outputKm.getText());". If you read the javadoc for that method, you will see that if you pass in a String which cannot successfully be parsed as a double, (i.e. I passed it the String "///"), then it will throw an Exception. Currently, this Exception will crash your program, rendering it unusable. So you will need to read about "try catch" so that you can …

george21 commented: Thank you for all of your help. You explained it very well. +1
BestJewSinceJC 700 Posting Maven

You created an inner class that implements ActionListener, and you defined the actionPerformed method for that inner class. But when you make the following statements:

Chapter165 listener = new Chapter165(inputMile, outputKm);
inputMile.addActionListener(listener);
outputKm.addActionListener(listener);

"listener" is an Object of the class type Chapter165. But in the Chapter165 class, you did not implement the actionPerformed method, and so, your code is not working as you wanted. If you get rid of that inner class, and put your actionPerformed method that you currently have in your inner class into your Chapter165 class, I think it will work.

P.S. if you wanted to do it like you have your code right now, you would need to change the code I posted above to this:

Chapter165 listener = new Chapter165(inputMile, outputKm);
inputMile.addActionListener(new ConvertListener());
outputKm.addActionListener(new ConvertListener());

If you don't understand why that is, feel free to ask questions. You can also read about inner classes and I think you should read about Listeners on sun's tutorials a little more.

BestJewSinceJC 700 Posting Maven

We don't do people's work for them. If you read the stickies, you'll notice that we're here to help people learn how to do things themselves. Also, since AVL trees are a data structure, I'm sure google already has the wonders you are looking for.

BestJewSinceJC 700 Posting Maven

What you want to do is draw two rectangles onto a window. What you're doing is creating two JPanels (which is essentially two different windows, not one), both of which have rectangles drawn inside of them, but you're putting the second JPanel on top of the first one - which is why you cannot see the first one. An analogy would be that you take two pieces of paper, draw a rectangle on each piece of paper, and then you put the second piece of paper on top of the first. Yeah, you drew two rectangles, but you can only see one.

To solve this issue, I'd paint the rectangles onto the same JPanel. You can use an Object to keep track of which coordinates you want to paint, and then in paintComponent, you'd paint those coordinates. Or you could set the coordinates (x, y, width, and height) and paint them, then set them again and paint again.

Another approach that could possibly work (but I'm not sure if it will) is to make the JPanel non-opaque. http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.html#isOpaque%28%29 .. to try that approach all you'd have to do is set the top JPanel jpanel.isOpaque(false).

majestic0110 commented: Nice explanation! +3
BestJewSinceJC 700 Posting Maven

James is right - you can create the JLabels in the class definition, but nothing further. In the future, you should use an array if you have any type of collection of Objects like you do above. For example, this code will do the same as yours does, but in a few lines:

JLabel[] blocks = new JLabel[100];
for (int i = 0; i < blocks.length; i++){
    blocks[i] = new JLabel();
    blocks[i].setOpaque(true);
    blocks[i].setBackground(MyBlue);
}
BestJewSinceJC 700 Posting Maven

This isn't a website for hand holding. The information is readily available. Look it up. Figure it out.

BestJewSinceJC 700 Posting Maven

WorkThread should not be running on the EDT. This indicates that WorkThread is not running in a separate thread - so the new Thread was not set up properly. Look up how to create a separate Thread on google. You should also look into Swing's WorkerThread class.

toucan commented: Good troubleshooting skills. +2
BestJewSinceJC 700 Posting Maven

This is one of the most - amusing? - threads in a while.

BestJewSinceJC 700 Posting Maven

I'm not knocking adatapost's suggestion - he gives great suggestions - but his suggestion might be a little too advanced for what you're doing right now. Either way, you might want to explain exactly what your assignment is, because "naming Nodes" doesn't make sense to any of the three people who have commented here and we like to consider ourselves good java programmers :)

kvprajapati commented: I agree. +10
BestJewSinceJC 700 Posting Maven

you didn't use code tags. read the stickies. all of them. completely.

BestJewSinceJC 700 Posting Maven
JButton Reset = new JButton("Reset"); 
    centerpanel2.add(new JButton("Reset"));

Should be:

JButton Reset = new JButton("Reset"); 
    centerpanel2.add(Reset);

Again, follow coding conventions - it should be named "reset" not "Reset" - this would have made it easier to see this mistake. Anyway, simple mistake, your program should work now. You added the actionListener correctly, but you then created a completely different JButton which didn't have the actionListener attached. Anyway, what you should get out of this is to avoid assuming your problem lies in one area, always investigate all possibilities.

MasterGoGo commented: Fixed my problem +1
BestJewSinceJC 700 Posting Maven

Correct me if I'm wrong: What you are trying to do is compare the first column of file 1 to the first column of file 2. So let's say you put all of the Strings from column 1 of file 1 into an ArrayList. Now, let's say you put all of the Strings from column 1 of file 2 into another ArrayList. This gives you the following variable declarations, if I were you, I would make them class variables (so declare them inside the class, preferably right under the class name):

public class yourBeanInfoClassIForgotTheNameOf{
ArrayList<String> file1Column1 = new ArrayList<String>();
ArrayList<String> file2Column1 = new ArrayList<String>();

//Blah blah blah, your methods go here
}

Now, you have a few issues at this point. You need to read in your data into those ArrayLists, and you want to know whether or not what's in file1Column1 matches anything that's in file2Column1, but you also want to keep all of the other Strings (the ones that aren't in the first column) from the two files, and you want to know what column they were in so you can print them out later. Going back to where we declared our two ArrayLists, at this point, I'd probably make a small class to handle keeping the data together.

public class OneRow{
//This is the String from the first column
String firstColumn;
//This is the remainder of the row
ArrayList<String> restOfTheRow;
}

For example, if you had the following file:

book, chapters, pages
phone, plastic, …
kvprajapati commented: Great explanation. +5
KirkPatrick commented: You did a great job explaining in this post, appreciate the effort. I didn't fully understand it back when you posted it. Thanks again bud +2
BestJewSinceJC 700 Posting Maven

It also looks like you need to separate your logic into methods that each do one specific task. Right now your code is pretty hard to read and understand.

KirkPatrick commented: Thanks again for everything, hard to believe that you are also an intern. You're quite a few steps ahead of me, but im definitely glad to get the chance to learn and have such helpful fellows around to show me the right techniques +1
BestJewSinceJC 700 Posting Maven

Someone could easily come here and STEAL the code and claim it as their own.

I don't want anyone STEALING my code.

From now on I am NEVER posting here.

Daniweb is the WORST place for help anyways. I got it resolved myself. Great.

I am DONE with this forum and WILL NOT recommend it to my fellow students or anyone in the future.

I don't know which part of your post is more ignorant. I'm still dumbfounded that you have the audacity to waste people's time (James in this case) and then tell them that their help was not worthwhile. And I'm also wondering why you would post on a forum which primarily deals in programming questions and programming help, and expect those posts and those people's efforts to help to be erased just because of your selfishness. Furthermore, this site has 500,000+ members, and nobody cares if some bratty kid who expects quick solutions - not guidance - to his problems doesn't recommend the site to his friends. I'm sure there will be no shortage of kids who expect their homework done for them. [/irony]

VernonDozier commented: I agree wholeheartedly. +17
BestJewSinceJC 700 Posting Maven
public class SampleAudio{
	public static void main(String[] args){
	try
	{
	File f = new File("pathname.mp3");
	Player m_Player = Manager.createPlayer(f.toURI().toURL());
	m_Player.start();
	}
	catch (Exception e)
	{
		
	}
	}
}

The above code is JMF and actually works for playing an mp3. However, the quality is pretty bad, and it seems to occasionally mess up (either wrong rate or something like that).

Also, as far as the QT for Java download thing being crappy, yes, the directions I found on apple's site were definitely incorrect. But I just went into my build path under my project in eclipse, clicked configure, add external jars, and went under program files, quicktime, and found QT Java (its a zip file) under one of the folders there. Then I added that, so hopefully it will actually work.

VernonDozier commented: I have nothing to add to this topic, never having worked with sound, but I figured I'd +rep to cheer you up! :) +17
BestJewSinceJC 700 Posting Maven

Suggestion - You never called validate on the JFrame after removing the previous center panel and adding the new one. If you were to call validate, then call repaint, I think the call to the ZOrder method might not be needed. The reason for this suggestion is because calling validate causes the layout manager to re-lay out its components. If it re lays out its components, and there is only one component in the center, you should not have to set the Z order. The Z order is just the "Z" positioning of a Component, if you thing of an X-Y-Z axis graph, I think.

kvprajapati commented: I agree. +3
BestJewSinceJC 700 Posting Maven

It is, but I was suggesting that the center panel could have its own layout, and that layout could be a CardLayout. That way you could flip to the next frame simply by using the CardLayout's show method, and none of the repaint etc would be necessary. Since your project works now its kind of pointless though, but its a thought for the future.

VernonDozier commented: Good suggestion regarding CardLayout. +17
BestJewSinceJC 700 Posting Maven

It might be placed correctly, but the syntax is definitely wrong. You said if (whatever); <----- the semicolon should not be there. An example if statement:

if (i > 0 && i <100){
printf(whatever);
}

You need brackets.

Salem commented: Ah yes, the end of line semicolon "trap", always a perennial favourite :) +35
BestJewSinceJC 700 Posting Maven

Use a GridLayout. If you have 3x3 grid, that's 3 rows and 3 columns. So Gridlayout whatever = new GridLayout (3,3). Problem hopefully solved. And..

Good luck.

sciwizeh commented: That's what I suggested, he wouldn't have had to use gridbag if he had payed attention in the first place +2
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

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
if (stream != null) {
    stream.close();
}

return stream.read();

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

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

I don't understand the second half of your explanation, so hopefully this is useful to you. File class: http://java.sun.com/javase/6/docs/api/java/io/File.html

For example you can easily create a new file using the createNewFile method. There are plenty of useful methods in there.

BestJewSinceJC 700 Posting Maven

@OP ignore this, I am asking a question relevant to this thread rather than giving you advice here. .

Searching each generated word with a long list of existing words (which might be in thousands) is itself a time consuming task, but you can have the dictionary words put into an ArrayList and then compare each generated word using the contains() method of that class, so I guess this could be much faster than iterating over the words.

Don't you have a dictionary stored in alphabetical order? You don't need to compare anything to every possible word, just check alphabetically to see if it is there period. Right?

VernonDozier commented: Yes, the fact that it is an ordered list will significantly cut down the search time. +15
BestJewSinceJC 700 Posting Maven

public double getRestockingFee() // calculate restocking fee
{
return super.getValue() * .05;
}

I'm personally very busy right now, so i apologize if you knew this already, but you are calling the method from your parent class when you use super.getValue() . . not the method from the class you are in. I just don't see a reason why you'd want to do that, considering you overrode the getValue method, is why I even mention it.

wedunnit commented: Great explanations and help! Problem solved! +1
BestJewSinceJC 700 Posting Maven

That's because scanToken = new Scanner(line); creates a new Scanner object based on the String, line, that you passed as the argument. Obviously, since line is a String, it is not an integer, and trying to read ints from it will not succeed. The first declaration of Scanner that you did Scanner scan = new Scanner(new File("Museum_Duguay.txt")); was the correct way to do it. Now all you need to do is use the nextInt() method to get the Integers from that file.

VernonDozier commented: I haven't given you rep in a while and you've had a lot of good posts lately. :) +15
BestJewSinceJC 700 Posting Maven

If you could read the forum rules by tonight, I'd appreciate it, unless you think someone is going to do your code for you.

http://www.daniweb.com/forums/announcement9-2.html

Salem commented: Damn straight. +30
BestJewSinceJC 700 Posting Maven

So you have an array of your numbers? I'm assuming they are integers? Then use

int result = array[index] - the mean;

Your first number is array[0], second number is array[1], and so on. If you had an array that was declared as int[] array = new int[3]; your 3 numbers would be stored at array[0], array[1], and array[2].

BestJewSinceJC 700 Posting Maven

Read
http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html

Particularly, where it defines what an abstract method is.

An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon). . .

Then compare that definition to how you have coded your method. You'll notice that you cannot declare a method "abstract" while also defining the method body. So either get rid of the "abstract" and the semicolon, or get rid of the brackets and the return picture.

Invalid:

abstract ImageIcon getPicture();
{
	return picture;
}

Valid:

abstract ImageIcon getPicture();

Valid:

ImageIcon getPicture()
{
	return picture;
}
Laidler commented: Helped me fix my abstract method error +1
BestJewSinceJC 700 Posting Maven

You managed to make the try catch block. Now all you have to do is System.out.println(variable nexocentric told you to output). Debugging is a very important part of programming, so you need to learn to do it. Debugging tools are very helpful, but I personally prefer print statements. If you put them in appropriate places, such as when you read a value into a variable, after a calculation is done on a variable, etc, then you will find your problem. Basically find the key points, logically determine what the value of the variables should be at those points, and use the print statements to see if they actually are.

nexocentric commented: Yeah, debugging is pretty important. Nice catch on the listener problem. +1
BestJewSinceJC 700 Posting Maven

By any chance do you go to umbc . . ? This just looks somewhat similar to a program they typically have students do (although the one they do is a lot more complicated, but that could be because you just started or omitted code, etc). Could also just be a common programming project.

Anyway,

CD mycd[]; declares a new array, but does not initialize it. Basically, what that means is that you declared an array, but did not set aside any memory for it to use. Had you initialized it properly, it would look like this:

CD mycd[] = new CD[NUMBER_OF_CDS]; where NUMBER_OF_CDS is an integer or a variable (of type int) that you declared. This declares an array of CD's. Lets say you had said CD mycd[] = new CD[3], then the compiler would set aside enough memory for you to hold 3 CD's. Think of it as looking like this:

[CD Number 1][CD Number 2][CD Number 3]. And the way you would put a CD into CD Number 1's space is by saying mycd[0] = *name of a CD Object goes here*.

In the first class that you posted, you created a new CD Object by saying CD myCd = new CD(whatever). But then you kept saying myCd = new CD(whatever), which basically overwrites the CD that you previously created. What you probably should be doing looks like this:

CD[] allMyCDs = new CD[NUMBER_OF_CDS_GOES_HERE];
CD aliceInChains = new CD(whatever);

VernonDozier commented: Good explanation. +14
BestJewSinceJC 700 Posting Maven

I think he wants to do something more like
int total = 0;
//where array is an array of strings
for (int i = 0; i < array.length; i++){
total+=Integer.parseInt(array);
}

Ezzaral commented: Yeah, I think you're right. +21
BestJewSinceJC 700 Posting Maven

Yeah, if you want a hello world program, I'll do it for $5

BestJewSinceJC 700 Posting Maven

Ok. I think I see a problem:


E temp = (E)data[top--];
data[top] = null;
return temp;

You set temp to the element at top, then you subtracted one from top, then you set top to null. What you should be doing is setting temp to the element at top, setting top to null, then subtracting one from top. (Which would look like):

E temp = (E)data[top];
data[top--] = null;
return temp;

Ezzaral commented: helpful :) +19
BestJewSinceJC 700 Posting Maven

If you want to do this Generically, consider this code as an example:

public class GenericNumbers<T>{

	private T number;
	private ArrayList<T> numbers = new ArrayList<T>();
	
	public GenericNumbers(){	
	}
}

If that does not make sense to you, read the two lectures on Generics found here (they are easy to understand):
http://www.cs.umbc.edu/courses/undergraduate/202/spring09/MiscPages/schedule.shtml

osjak commented: Helpful, thanks! +2
BestJewSinceJC 700 Posting Maven

This is not a homework completion service.

It depends. If he posts it in the 'paid projects' section it will quickly become one. ;)

peter_budo commented: Good idea, where did I out details to my PayPal ;) +17
BestJewSinceJC 700 Posting Maven

Your class is named Video. The Video class has a String and an int as data members. Your other class is VideoStore. It has an array of videos as its only data member. If you know how to create an array, then you should have no problems.

Video[] theVideos = new Video[howeverManyVideosYouHave];

If you wanted to make a class called Car, it might look like this

public class Car{
//The data members
public String color;
public int weight;

//The constructor
public Car(String theColor, int theWeight){
color = theColor;
weight = theWeight;
}
}

Now, consider a 'Car Dealership' where the Car Dealership typically has a lot of Cars...

public class CarDealership{
Car[] theCars;

public CarDealership(Car[] cars){
theCars = cars;
}
}
VernonDozier commented: Good examples +12
BestJewSinceJC 700 Posting Maven

A recursive method calls itself in order to come up with the final answer. Your method is returning count, which does not do what I just said. Your method should have the following parameters: currentIndex (the index the array just checked), count, array (your array). A recursive method also needs a base case to tell it when to stop the recursion. In your case, since you want to go through the whole array, counting the number of times 5 appears, where do you want to stop the recursion? Clearly, you want to stop when you have gone through the entire array.

To help you out, here is the pseudocode, or at least part of it:

count(currentIndex, count, array){
if currentIndex is at the end of the array, return count.
else if the next index has a 5, return count(currentIndex+1, count+1, array)
else, the next index does not have a 5, so return count(currentIndex+1, count, array)
}

It is a little sloppy but that is the general idea. You have to call the method for it to be recursive, and you have to have some mechanism that stops it from calling itself. In this case, when it is at the end of the array, it should stop calling itself, because it has no more indexes to look at.

darkagn commented: Good explanation of recursive calls with example pseudocode +4
BestJewSinceJC 700 Posting Maven

An example. . . (You can google Java WAV and a lot more will come up if this one doesn't work for you)
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml

This is probably a difficult read but it seems to have a lot of relevant and useful information.
http://java.sun.com/docs/books/tutorial/sound/sampled-overview.html

Ezzaral commented: Helpful links and a magnanimous spirit. +19
BestJewSinceJC 700 Posting Maven

You forced them to input a row between 1 and 3 and a column between 1 and 3. Your array has 3 rows and 3 columns. Arrays in Java (and most other languages) are indexed from 0 to (rows-1). Which means that your array's first cell is _board[0][0], and _board[3][3] is NOT a valid row or column.

In your makeMove method, you should convert rows and columns so that they can be used to index the array. Since the first row is indexed by 0, not by 1, all you have to do is subtract 1 from whatever the user inputs.

BestJewSinceJC 700 Posting Maven

http://www.daniweb.com/forums/announcement9-3.html

And try reading that thread in addition to posting what errors you got. We're more than happy to help if we don't have to spend extra time doing things we shouldn't have to (like formatting your code and pasting it into our editor to run it and see what errors we get).

Antenka commented: :D yeah, that would be more comfortable +2
BestJewSinceJC 700 Posting Maven

Every line starts with a String. So read it in. Then use a while loop to read in each integer on the line until -1 is the last integer you read in. Then repeat this process until you are at the end of the file.

BestJewSinceJC 700 Posting Maven

There are two obvious things you could do as far as how you're thinking about the section of the Seats.

Scenario 1:
Think of the section the seat is in as a property of the seat. (In other words, since the seat will always be in the same section, you could have a variable in the Seat class called section).

Scenario 2:
Think of the section the seat is in as a property of the Theater- not of the seat. In this case, your Theater class could have an array of seats for each section. This is what I would personally do, I think.

Ezzaral commented: Helpful and patient responses in this thread. +18
BestJewSinceJC 700 Posting Maven

I'm not sure I understand your class structure, so take this with a grain of salt. You could pass the MainFrame as an argument to AddClientPanel's constructor and then store the MainFrame in a static variable in the AddClientPanel class. AddClientPanel could have a get method that, using the static MainFrame variable, returns whatever info you need. (AddClientPanel is a class, right?)

MainFrame
AddClientPanel ... constructor takes MainFrame variable, then stores it in a static variable. Also has getter.
Other classes ... get Mainframe's info by using AddClientPanel's getter.

peter_budo commented: Thanx for reminder on statics ;) +14
BestJewSinceJC 700 Posting Maven

Oh, and I have read, but do not understand what, how, or the purpose of a no argument constructor.

What exactly is it? a method containing no body?

No, it is a constructor that had no arguments/parameters. The method can contain whatever body/code you want it to. A no argument constructor is just, for example, if we had a constructor with the method header: public Animal()

yeah, I'll begin writing and practicing these using what I know, but I still need to further understand private, no-argument.

So doing calculations would be something like:

public getDifference (int height){
 heightDifference = myAnimal2.height - myAnimal1.height;
 return heightDifference;
}

would that be correct?

You have the right idea. But keep in mind that if you actually wrote that exact code, Java would not know what 'myAnimal2' and 'myAnimal1' are. See my example of how to do it below.

Rewriting your code above so that it would work:

public getDifference(Animal a, Animal b){
int difference = a.height - b.height;
return difference;
}

And rewriting it again, so that it is even better

public getDifference(Animal other){
int difference = this.height - other.height;
return difference;
}

^ Note the 'this' again. 'this' refers to the Animal Object that called the method. If that doesn't make sense, consider the way that you actually would call the getDifference method. You would have some code like this:

Animal myAnimal = new Animal(2);
Animal otherAnimal = new Animal(1);

int theDifference = myAnimal.getDifference(otherAnimal);
System.out.println(theDifference); // Prints "1"

jasimp commented: Nice job helping him out +9
BestJewSinceJC 700 Posting Maven

Its cool, Antenka. Everybody makes mistakes. What I usually do before responding is quickly check the API to make sure my response coincides with what I see there.

Antenka commented: Thanks for correction and moral support :) +1
BestJewSinceJC 700 Posting Maven

^ That code looks wrong. Who modifies main to throw an Exception? Also, since his Exception is printing "Invalid ID", your code would print the same thing twice. And most importantly, when you declare a method as 'throws Exception' in the method header, the method that calls it has to handle the exception by using try/catch. So, for example, Mr.Diaz, see my code below

public static void checkNumber (int number) throws InvalidIDException{
-loop through the array, find out if the ID is valid
if ID is not valid, throw new InvalidIDException
else do nothing, since the ID is valid
}

main method{
   try{
    checkNumber(number);
    System.out.println("Valid ID!");
   } catch(InvalidIDException e){
      System.out.println(e.getMessage());
   }
}

Mr Diaz, please note that this line of code: System.out.println("Valid ID!"); will never be reached if checkNumber throws an Exception. That is because if checkNumber throws an exception, then the code in our main method will 'go' to the catch portion, and it will never execute anything after checkNumber(number). Otherwise, if there is no exception, it will do the print statement and it will never enter the catch portion.

quuba commented: Who modifies main...? - No one, thank you for assertive post. quuba +1