Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 03-10-2007, 07:42 PM   #1
Beta Member
Join Date: Mar 2007
Posts: 1
Default Help writing Java programme?

Hi all,

Just found this forum, hoping someone will be able to help me out here. I'm trying to write a programme in Java. I've tried to write it myself but in all honesty I am completely lost with it, even though it seems like a fairly broad specification. Can anyone help me out?

Write a program that creates an ArrayList of Rationals and sorts them into increasing order. Use appropriate methods from the Collections Framework classes to sort the elements into increasing order.

Hopefully it isn't too time consuming; obviously if it is, forget it! Thanks very much to anyone who can help though.

spinback is offline   Reply With Quote
Old 03-12-2007, 04:30 PM   #2
In Runtime
Mal's Avatar
Join Date: Jan 2005
Posts: 221
Default Re: Help writing Java programme?

Personally I would use quicksort rather than methods from the collection class but if thats what you're required to use then you'll have to do it the long way.

I would suggest looking into the API specification at http://java.sun.com/j2se/1.5.0/docs/api/ that should help you figure out how to do your task. I take it the question was set by an educational institution, in which case you'll have to try your best on your own (being in the 2nd year of my degree I can assure you you'll have to learn it at some point and it WILL benefit you). For general tutorials on Java see my post (quite far backdated) on "How and where to learn Java/C++"

Mal is offline   Reply With Quote
Old 03-15-2007, 01:29 PM   #3
In Runtime
Daeva's Avatar
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: Help writing Java programme?

My only suggestion would be to convert the rationals to floating point numbers. for example:
1/2 = .5.

Then, you can put the decimal values in the array, sort them, and then convert the numbers back to the rational form when outputting. The array class has a method called sort() so you can check out the java api from the link above and play with that method to get it to do what you want. Alternatively, you may be able to store the rationals as strings, and not worry about the conversion. Just use an Integer.parseInt(rationalNumber); type setup and store the result in the array.
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
Daeva is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 02:10 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0