• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me please I dont know it

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a program that prompts the user to enter the number of students and each student's name and score, and finally displays the student with the highest score.and the student with the second-highest score
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pinar and welcome to the JavaRanch.

We are NotACodeMill and also we have a policy about homework (here).
We are willing to help but we not going to write the code for you.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseAMeaningfulSubjectLine. And can you show us what you've done so far?

Let me help you a little bit. I see three sub tasks:
- read the user input.
- put that user input into some data structure; since the number is known an array may be good enough. You'll probably need a custom class for this, e.g. Student, with two fields: a String name and a numeric (int, float, double, ...) score.
- find the student with the highest score inside that data structure. If it's an array or Collection than a simple loop would be the basis of this.
 
pinar yazgan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I wanted user who have max score I wrote this code but it didnt work.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code. It will highlight your code and make it much easier to read. It probably will also increase the number of people helping you. I'll add them for you since you are new so that you can see the difference.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pinar yazgan wrote:



System.out.println() has only one parameter
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you remove that } on line 16 and fix the printing issue Wouter mentioned then I believe your code will work. Well, except that it doesn't ask for the number of students. But that's just reading the number first, then using that number in the loop.
 
pinar yazgan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sory I forget + 1. System.out.println(max+ "" + maxno +""+bigname)
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what is your problem? You can now read 3 students and display the values of the one with the highest score. So far I see two things that need to be done:
1) read the number of students to read first.

2) add input validation. What if:
2a) you try to read an int but no int is available?
2b) the score is too low or too high? Especially negative scores will hurt your program; if all students have negative scores then nobody will have the highest score.
 
reply
    Bookmark Topic Watch Topic
  • New Topic