Scott Winterbourne

Ranch Hand
+ Follow
since Jan 30, 2014
Scott likes ...
Eclipse IDE Java PHP
SQL Server DB developer getting back into Java.  Taking Java classes at UC San Diego in the Java Certification program.  Hoping to change my career path back to Java development very soon.
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
32
Received in last 30 days
0
Total given
15
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Scott Winterbourne

First, the assignment states that you need to assign the values to the "smallest", "middle", and "largest" variables. In your code you are not assigning any values, you are just printing them to the screen. You should do something more like this:

From the first IF statement, all we know is that input2 is larger than both input1 and input3. We don't know however between input1 and input3 which is larger or smaller. We just know what input2 is. The second ELSE IF we know that input2 is smaller than input1 and input3. Again we don't know from this statement whether input1 or input3 are bigger or smaller than eachother. Because of this, we can't print a final ascending order within each statement.

You will need to follow the above logic to finish assigning the variables for input1 and input3. then at the end, you can print the smallest, middle, and largest variable values like so:


Hope this helps. Let me know if you get stuck or need any further clarification.
2 years ago
What really helped me was practice practice practice. Not just with programming either. I did and still do a lot of puzzles and brain teasers such as sudoku or solving word problems and brain teasers.

Also go to codingbat.com and work through the coding problems there. Some of them have a solution you can look at. Try to solve the problem yourself. Then try to improve upon your solution. Then study the solution that was provided and figure out why they did it that way.

This was my experience anyway and it really helped me. Hope it also helps you.
4 years ago

Paul Clapham wrote:I would start out with a horizontal BoxLayout containing three panels. You can see the three panels there; the first contains the two check boxes, the second contains the X and Y entries, and the third contains the three buttons. The three buttons look like a vertical FlowLayout, and the other two... I don't know, I haven't done this for a while but you could try several options and see what works best for them.



This will absolutely work. Also for the first 2 panels in the BoxLayout containing the check boxes and the text fields, they can be achieved using the GridBagLayout inside the BoxLayout.

So a BoxLayout for the JFrame with 3 JPanels inside. The first 2 panels will have the GridBagLayout and the third will use a FlowLayout. By modifying a couple parameters here and there you can get it to look just like this.

Layout managers are very powerful and the preffered way to build a GUI in Swing as they handle a lot of issues such as screen and window resizing for you.
4 years ago

Campbell Ritchie wrote:Never try writing == false or == true.
Always write if (up)... or if (!up)...
That should prevent that particular error.



This is something I need to keep in mind for myself also. I tend to write == true or == false.
4 years ago

Campbell Ritchie wrote:I thought the javap tool displayed the bytecode, not the source code.


In fact the javap command does display the bytecode, not source code. If you use javap FileName, it will show you the bytecode of the class definitions. If you use javap FileName -verbose it will show you all of the bytecode for the class members as well.
4 years ago
I would suggest a couple things. First, if you have not already you may need to override the equals() method in your Product class. This will ensure the ArrayList.remove() method is properly determining if the objects are equal.

Second I would output the "id" parameter being passed into the removeFromCart() method on the controller and the Index of the object in the ArrayList to see if they are correct.

Like Tim said, it seems like an equality issue is which case you should have a look at the equals() method in the Product class. If the Product class does not have it's own equals() method, you should add one and override the one inherited from the base Object class.
4 years ago
On line 10 you have declared the variable "c" as an int. int is a primitive data type which does not have methods that can be invoked. It is just a number that was assigned to it.

On line 8 you have already read the user input as a String. Then on line 10 you parse the String to an int and then assign that int to the variable "c". Now all you have to do is to use the variable "c" in the while loop. No need to do any extra read() or assignment, Just ( c != -1 ) and your done.

With what I mentioned above, the variable "a" is not needed at all.
4 years ago
I'm no Swing expert but I think JOptionPane.ShowInputDialog() returns a String. Your "customerNameString" variable will contain whatever String the user entered. What do you need to parse from the input?

See the Documentation for this component and method.
4 years ago
The condition for the while loop is that (a != 1). the variable a is set before the loop starts by reading from the file. There is nothing inside the loop to tell it to stop and read more input from the file. Whatever the single int value is it read from the file, that is what it keeps using in the condition.

4 years ago
In your example, you have assigned the input stream to the variable "is". If the variable "is" is NULL, that means it does not point to an input stream object. Therefor if you try to call a method on a variable that does not point to an object, you will get a NullPointerException.

This is the reason to test if the variable is NULL before trying to call a method on it. An exception may have been thrown while the input stream was being created so the input stream object was never assigned to the "is" variable.



Hope this helps.
4 years ago
Your Tester class is looking okay. The first System.out.println(); (line 46) is redundant and not needed here.

The Circle class could use some work. Have a look at the Java Tutorials on proper declaration of a class, method and instance variable.

You actually had the constructor correct in your previous version of the code (lines 3 through 9 of the old code). All you needed to do with the Circle class was to declare a new instance variable called "radius" of type double. Then declare the diameter() method somewhere below line 9.

Here is an example of some class, method, constructor, and instance variable declarations:
4 years ago
I haven't been around too long but my posts go in spurts.

Registered: Thursday January 30th, 2014
Today: Wednesday July 9th, 2014
Days Elapsed: ~160
Number of Posts: 104
Posts per day: 0.69
Days per post: 1.44

I've been in a lull lately. Been doing a lot of work travel.
4 years ago
Here are a couple things to get you going in the right direction.

The project descriptions states to create a new METHOD within the Circle class called diameter. Right now on line 33 you are declaring diameter as a new class, not a method. Try refactoring line 33 so diameter is a method instead of a new class.

Second, you are using the variable "radius" in a few places in the Circle class. Consider declaring the radius variable as a private instance variable at the top of the Circle class definition.

This will at least get you going in the right direction. Once you have these changes complete, post the updates and we can help you with your progress.
4 years ago
Excellent, I'm glad you were able to implement the for loop.

Would you mind posting your updated code? Others that have similar questions might find it very useful to see the before and after.

Thanks,
4 years ago

Ulf Dittmer wrote:I would also note that in a moment of truly bad API design the Cloneable interface does not contain the clone() method.



Hah indeed. The clone() method is inherited from Object.

Ulf Dittmer wrote:
Also, in my experience, the use of clone() in application code is exceedingly rare. It's much more common that a class has a constructor that takes an instance of the class as parameter, and then proceeds to create a clone of that instance.



Can you show an example of this? I don't quite follow how that works. Not to hijack this thread from the OP, sorry.
4 years ago