• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

My program doesn't function properly

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program is suppose to accept up to 5 names and grades and it does that but when I try to sort them by Name or Grade and then try print them out I am only getting the last name and grade entry made. I'm pretty sure the problem is with my counter but I can't seem to figure it out. Any help would be appreciated it.
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code doesn't compile. Please paste code which can be compiled and also use codetagsfor the same.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Welcome to the ranch.

Yeah, as Tushar has pointed out, it helps if you UseCodeTags. <--- click to find out how.
I've put them in for you this time - see how much better it looks?


There are a couple of minor compile errors in there
- missing import for scanner class
- missing an opening { for your class.

Once those are sorted your program should compile and run .

You do have a problem in the code that inputs the names.
Your print method looks ok though. I would suggest calling it after you have finished entering names just to show you what the user entered before sorting.
Or maybe even printing them names after you have entered EACH name .
That should help you get a handle on what is going on in your program.

 
Clark James
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if it compiles now. I'm using NetBeans and it does compile there but I left out the top couple lines previously.

 
Clark James
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:Hi! Welcome to the ranch.

Yeah, as Tushar has pointed out, it helps if you UseCodeTags. <--- click to find out how.
I've put them in for you this time - see how much better it looks?


There are a couple of minor compile errors in there
- missing import for scanner class
- missing an opening { for your class.

Once those are sorted your program should compile and run .

You do have a problem in the code that inputs the names.
Your print method looks ok though. I would suggest calling it after you have finished entering names just to show you what the user entered before sorting.
Or maybe even printing them names after you have entered EACH name .
That should help you get a handle on what is going on in your program.


Stefan,

After reading your comments I started looking at my Name and Grade input and finally got it working. I simply added i++; after the Grade input line and it finally accepted and printed all five names and grades out of the parallel arrays.
Thanks for your help. I'm only a couple months into Java and this had me stumped for a few days.

 
Marshal
Posts: 80508
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch again

I can see lots of ways you can improve that code. One problem is that method is much too large. You should divide that up; you can probably make ten methods from it. Don't start variable names with CapitalLetters; start them with smallLetters. Don't write comments which make the lines so long and don't tell us anything we can't guess from the code anyway.

Where did you add i++; (line number)? Can you explain why that made the program work? If you can do that, you will demonstrate you learnt something useful.
 
Saloon Keeper
Posts: 11040
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a for() loop on line 23 without any braces. The result is the for() loop immediately incloses the following while() loop.
 
Sheriff
Posts: 9008
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what is more bad: to put such a lot code in one method, or create such an amount of comments - which just makes code less readable.

But even that, if you decide to write so many comments, make sure they are very accurate.
For example:

Clark James wrote:


This comment is overloaded of useless information, wouldn't be clearer like:


[edit]I just realized now, probably you were thinking about array indexes, in this context, maybe that comment is not so bad[edit]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic