Carey Brown

Saloon Keeper
+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
Forum Moderator
Carey Brown currently moderates these forums:
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Carey Brown

I don't see anything in the requirements that stipulates the order of the final array other than all evens must come before all odds. Seems like a modified bubble sort that swaps odd numbers with even numbers would do the trick without a loop for shifting the array contents.
IN: [1, 3, 3, 4, 5, 8, 0]
OUT: [4, 8, 0, 1, 5, 3, 3]
15 hours ago
Describe the problem you are having. Does it compile? Does it work? What output do you get?
19 hours ago
It doesn't seem to me that a bunch of else-if's should be an issue. If you end up with gobs of different classes to instantiate then you might need to examine your design to see if there would be a better overall approach. You could replace the else-ifs with a switch statement which might be cleaner.

There might be a way with Java-8 to do it with functions and a hash map but I'm not strong enough in that area to make a reccomendation.
1 day ago

Ammar Pehilj wrote:Yes my bad. I changed the play() method in the album class to print this.playlist instead of getPlaylist. Thank you. I am aware of that, it was among the first things we learnd, but I prefer having them in separate files,
it is easier to browse.

I wasn't necessarily advocating that you put it all in one file. When you ask for help in forums it is often easier to help you if there's only a single file to cut-n-paste and if you tweak one class then all the code stays together. When you post multiple changes to various bits and pieces we're no longer sure they're in sync.
2 days ago
I cut-n-pasted your code into a java file and I did not get null, so I'm not sure where the problem was introduced. You should not need a play() method in KidsSongs.

Here's the file I used. Note that you can put multiple classes in a single .java file as long as only one is public and that one matches the file name.
2 days ago
"this" appears frequently in constructors because often there is a parameter name that is identical to a field of the class and "this" clarifies that you are specifically referring to the class field and not a local variable.

Often people just get into a bad habit of adding "this" when it is unnecessary. Those should be removed.
2 days ago
The first thing you could do to make it clearer is add proper indentation. Then it would be obvious that setArea() is a method just like main() (maybe you already determined that but indentation would make it jump out at you). So, yes, setArea() appears after the place where it is called in main(). The order of methods inside a class makes no difference.
2 days ago
"other_name" is a local variable and here you are assigning it to itself which does nothing. To assign the local variable to the class variable you need to put "this." in front of the name. Like:
The Java naming convention is to use camel-case to identify word boundaries, so your other_name variable should be named otherName.
4 days ago
Kavya, when posting code please enclose the code in "Code" tags. To do this, use your mouse in the edit window to highlight the entire listing and then click on the Code button just above the edit window.

You should never close a Scanner object created form
4 days ago
LocalDate.of() is similar to a constructor in that it results in the creation of a LocalDate object. It is static because it does not need a "this" object to operate on.
4 days ago
You could do it with "parallel" arrays. That is, two arrays of the same length where the firstArray[n] is related to secondArray[n]. In your case: points[n] is related to names[n]. Then you'll need to write a sort method that takes two arrays and sorts both arrays based on the values in the first array. A bubble sort, while not very efficient, is easy to implement. So you'll end up writing this method:
In the sort method is a section that swaps two array elements. You'll have to tweak it so that both the elements in the points array and those in the names array get swapped identically.
6 days ago
Ah, you want to sort the names by decreasing number of points.
You'll want a class that has name and points as fields. Then parse the input creating a List or an array of those class objects. Then create a comparator that will sort the List/array in descending order by points. Then iterate through the List/array printing out the name of each person.
6 days ago

Input: Anna**,Zeevan***,John*,Mike**** "...
Program will output:  Mike,Zeevan,Anna,John

So, you just want to strip off the asterisks?
6 days ago