Win a copy of Rust Web Development this week in the Other Languages forum!

Daryl Cofer

Greenhorn
+ Follow
since Jun 20, 2012
Daryl likes ...
Eclipse IDE Ruby Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daryl Cofer

Storing your GUI components in an array adds a layer of obscurity if you are accessing individual components within the array.
The obscurity could be avoided perhaps, if you used enums to reference the indices of your button and panel arrays and would ONLY be effective if they are stored in a particular order and never re-arranged (seems like a nightmare to me).

I believe that you should only use arrays for operations that you perform to each component (ex: foreach loop to clear text on all buttons in an array). Otherwise, just reference them via their name.
7 years ago
Just like making an int[], you can have a GroceryItemOrder[]
7 years ago
Why do you need a switch statement there?
Switch statements are like an if-else statement. In this instance, case 0, 1, 2, 3, 4...12 are all calling the same setText method. You could do away with the switch completely and just have


Which simply says that if we found the key, set the text of the lcd to the key's label.
7 years ago
In your code you have this block:

What line 5 says is:
1. Take variable a
2. Subtract 1 from it
3. Store whatever that number is into a.

So basically the reason that a does not equal 10 at the end of your program is because it is being overwritten each time by line 5 in the code block above.
7 years ago
As far as the errors you are receiving goes, here are a few fixes:

1. The proper syntax to initialize a variable is: <type> <var-name> = new <type>(params);
That is why lines 20 and 21 are angry with you.


2. You have a catch block without a try block. These two go together. In your case, since you're just trying to prevent any and all errors from occurring(not best practice, don't get used to doing this) you should probably just wrap your whole main method inside the try/catch.

3. In your two methods at the bottom, it is complaining because it doesn't know what 'x' is. You can make this information available by passing in a value for x in the parameters or creating the variable within the method itself.


4. Your second while loop is trying to reference the variable 'input' which is out of scope.

This can be fixed by moving the Scanner initialization code up here:


5. You're not using the add and sub methods anywhere in your code so if you're going to use them, then put them to work. Otherwise they're better off just being deleted.
7 years ago
The LinkedList class already has a built in iterator anyway, so why would you want to make a new one?
If you want to go through the elements in your MyList class, you might want to look into making it iterable by implementing the Iterable interface.
7 years ago
When your iterator calls the next method, it checks to see if its expectedModCount is equal to the list's modCount it is iterating over. If these numbers don't match, the iterator thinks that the list has been modified and it throws the exception that you received.
7 years ago

No. Overloading may be done in the same class, and often it is. But it doesn't have to be. As in this example.



Would it only be considered overloaded in class B since B inherits A's printNumber?
7 years ago
Are you asking how to run your application from the command prompt?
7 years ago
In order to test your code with println, you're going to have to create a Main class and inside it put a main() method.
The class and method signature should look like this:



That should get you on the right track to debugging your code and making sure it works as intended.
7 years ago
Taken from the Java API:

public class StringIndexOutOfBoundsException
extends IndexOutOfBoundsException
Thrown by String methods to indicate that an index is either negative or greater than the size of the string. For some methods such as the charAt method, this exception also is thrown when the index is equal to the size of the string

So it looks like the length of your String could potentially be 0.

Why don't you try printing the length of the String in question to the console before you call the charAt() method?
7 years ago
In Java, every class that you create is derived from the Object class.
The Object class defines the toString() method. Until overridden, the toString method will return the hashCode for your object.
In your case, you need to override the base (Object) class' toString() method inside your Bank class.

In most instances, the toString() method inside your class will return a String representation of your object.
For instance, if you had a class called Closet that kept track of the number of shirts and pants that was in it, your toString() method might look something like this:

7 years ago
You could also try to surround the problematic code with a try/catch. This will execute any of the code within the try block and if an exception is thrown: catch it, print a message and continue executing the code after the catch block is completed.

Links:
Try block
Catch block

Hope this helps!
8 years ago