help hw

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2009
Posts: 2
Reputation: linhngoc2100 is an unknown quantity at this point 
Solved Threads: 0
linhngoc2100 linhngoc2100 is offline Offline
Newbie Poster

help hw

 
0
  #1
Apr 4th, 2009
I have a homework that only uses loops and selections. I do not know how to do it. Here is the topic:
Write a program that prompts the user to enter the number of students and each student's name, score. Finally, display two students have the highest scores.
Thank you.
Last edited by linhngoc2100; Apr 4th, 2009 at 5:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: help hw

 
0
  #2
Apr 4th, 2009
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: linhngoc2100 is an unknown quantity at this point 
Solved Threads: 0
linhngoc2100 linhngoc2100 is offline Offline
Newbie Poster

Re: help hw

 
0
  #3
Apr 4th, 2009
I know how to find the first highest, but can not find the second.
System.out.println("Enter a name of student: ");
String namea=input.next();
System.out.println("Enter a student score: ");
double scorea = input.nextDouble();
System.out.println("Enter the number of student: ");
int numberstudent=input.nextInt();


for( int i=0;i<= numberstudent-1; i++)
{
System.out.println("Enter the student name: ");
String name1 =input.next();
System.out.println("Enter the student score: ");
double score1=input.nextDouble();
if (score1>scorea)
{ namea=name1;
scorea=score1;
}
Last edited by linhngoc2100; Apr 4th, 2009 at 5:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: help hw

 
0
  #4
Apr 4th, 2009
if (score1 > score of the greatest)
{
name of the second = name of the first
score of the second = score of the first
name of the first = new name of the first
score of the first = new score of the first
}

This is very easy to implement that pseudo-code.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC