Welcome to Dream.In.Code
Become a Java Expert!

Join 149,602 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,904 people online right now. Registration is fast and FREE... Join Now!




total number of students

 
Reply to this topicStart new topic

total number of students

mariposa
16 Sep, 2007 - 01:50 PM
Post #1

New D.I.C Head
*

Joined: 16 Sep, 2007
Posts: 1


My Contributions
write a program that promps the user to enter the number of studenst up tp 3 students , the students name and scores, finally dysplays the student with the highest score


CODE

public static void main(String[] args) {
// Prompt the user to enter the number of Students, Each Students Name and Score
String s1 = JOptionPane.showInputDialog(null,
"Enter the number of students",
"Example 32 Input", JOptionPane.QUESTION_MESSAGE);
int n1 = Integer.parseInt(s1);

String s2 = JOptionPane.showInputDialog(null,
"Enter the students score",
"Example 89 Input", JOptionPane.QUESTION_MESSAGE);
int n2 = Integer.parseInt(s2);

String s3 = JOptionPane.showInputDialog(null, "Enter the students name",
"Example Shane, Kevin, Sara, Anna",
JOptionPane.QUESTION_MESSAGE);

int shs = 0;

while (s1 > 0) {
if (n2 > shs);
shs = n2;
s1 = s1 - 1;
}
JOptionPane.showMessageDialog(null, "The Student and High Score is " + shs + s3,
"Example Shane 92", JOptionPane.INFORMATION_MESSAGE);
}

}
*edit: code tags

This post has been edited by PennyBoki: 16 Sep, 2007 - 01:53 PM
User is offlineProfile CardPM
+Quote Post

alpha02
RE: Total Number Of Students
16 Sep, 2007 - 01:53 PM
Post #2

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
Welcome to DIC! Please post the errors you are getting and we will help you. Thanks.

This post has been edited by alpha02: 16 Sep, 2007 - 01:54 PM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Total Number Of Students
16 Sep, 2007 - 01:55 PM
Post #3

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi mariposa, welcome. Maybe you want to post this as a code snippet if it is working, if not please tell what are the errors you are receiving.
User is offlineProfile CardPM
+Quote Post

goldenthunder
RE: Total Number Of Students
18 Sep, 2007 - 01:47 AM
Post #4

New D.I.C Head
*

Joined: 18 Sep, 2007
Posts: 13


My Contributions
I guess, if you type in 3 in the first dialog
the 2nd and 3rd dialog are only shown once, right?

right after reading the number of students (n1) you should start with your for-loop where the next two dialogs are included.
You can save the inputs in a Map "studenname" => "score" or just save the current students name an scores in
variables defined outside the for-loop as you have done with shs.

This post has been edited by goldenthunder: 18 Sep, 2007 - 01:48 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:50PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month