• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bubble sorts and Loops  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I am working on an assignment, and I can not figure out how to get the bubble sort to work. Also, when I out put the code, it will not print out the numbers just the grades. Can someone help me please?
Here are the requirements for the assignment:


• a class called “roster”
• attributes, which must be last names and numerical grades, and must also be parallel arrays
• an indefinite loop, which allows the user to manually enter five (5) names and grades and stores them in the array. Note: The loop must end either when the user specifies that they are done or when a maximum of five (5) values have been stored in the arrays, i.e., five (5) names and a corresponding grade for each name.
• an indefinite loop, which prompts the user to select a sorting criterion or to end the program, and must also use bubble sort. Note: The user may either select name or grade as the sorting criteria. The program must use bubble sort to sort that data according to the specific criteria and then use another loop to display the data. This process must continue until the user ends the program.


 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nana Mikamura wrote:Hello! I am working on an assignment, and I can not figure out how to get the bubble sort to work. Also, when I out put the code, it will not print out the numbers just the grades. Can someone help me please?

OK, well first, you have more than one problem, so deal with each one separately - and my suggestion would be to tackle the bubble sort first.

And to do that you need to get rid of EVERYTHING else.

If need be, put this program aside for the moment and just write a class called BubbleSort that has only ONE requirement - to sort an array using the bubble sort algorithm.
Ie, something like this:And don't write another line of code in your Roster class until you have that class working every single time and with any input array - including an empty one.

Once you do, it should be a simple matter to transfer that sort method back to your original class - and then you can work on your next problem. But not before.

You will also do yourself a lot of good by indenting your code properly. Right now it's rather a mess.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!