13 Replies - 6238 Views - Last Post: 26 October 2009 - 07:42 PM Rate Topic: -----

#1 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Write a program that prompt the user to enter number of student

Post icon  Posted 26 October 2009 - 06:26 PM

1.Write a program that prompt user to enter the students and each student name and score and finally display the student with highest score..

guys do u have any clue to solve this question?thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Write a program that prompt the user to enter number of student

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:32 PM

Without sayinbg your code not much we can say

"Hey mechanic, fix my car but do not open the hood!"

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:37 PM

 
public void add(String name, int score)
{
if (numStudents >= MAX_STUDENTS)
return; // not enough space to add new student score
names[numStudents] = name;
scores[numStudents] = score;
numStudents++;
}





this is the code i try but i found an error ... any clue to solve to support this question?
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,901
  • Joined: 10-May 07

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:38 PM

Where do you declare the arrays for names & scores?

Also, by 'numStudents++;' this looks like you are trying to implement a loop, & not a conditional if.
Was This Post Helpful? 0
  • +
  • -

#5 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:42 PM

so can i know where is the mistake that i put wrong or write wrong?
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,901
  • Joined: 10-May 07

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:44 PM

I don't know where you are getting the values for MAX_STUDENTS, or the arrays for names & scores.
public void add(String name, int score) {
  if (numStudents >= MAX_STUDENTS) {
	return; // not enough space to add new student score
  }
  while(numStudents < MAX_STUDENTS) {
	names[numStudents] = name;
	scores[numStudents] = score;
	numStudents++;
  }
}


Was This Post Helpful? 0
  • +
  • -

#7 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:48 PM

o
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 06:54 PM

assuming that numStudents is a static int within your class that should works
but I won't beg you to post your code... you are wasting everybodies time here
Was This Post Helpful? 0
  • +
  • -

#9 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 07:02 PM


public class StudentScoresTester
{
public static void main(String[] args)
{
StudentScores studSc = new StudentScores();
Scanner in = new Scanner(System.in);
boolean done = false;
// Read the students names and scores, and add them to
studSc
do
{
System.out.println("Enter a student name or -1 to
end: ");
String name = in.nextLine();
if (name.equals("-1"))
done = true;
else
{
System.out.println("Enter the student's score:
");
int score = in.nextInt();
in.nextLine(); // skip the end-of-line character
/** Your code goes here */
}
}
while (!done);
// Find the students with highest and second high scores and
print
// their names and scores
/** And here */
}
}



got an error =(
Was This Post Helpful? 0
  • +
  • -

#10 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 07:07 PM

View PostZzwincezZ, on 26 Oct, 2009 - 08:02 PM, said:

got an error =(


Can you be more specific? What errors did you encounter?
Was This Post Helpful? 0
  • +
  • -

#11 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 07:08 PM

hmm... dint get the second score ...
Was This Post Helpful? 0
  • +
  • -

#12 ZzwincezZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-October 09

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 07:11 PM

 
public String getHighest()
{
if (numStudents == 0)
return null;
int highest = 0;
for (int i = 1; i < numStudents; i++)
if (scores[i] > scores[highest])
highest = i;
return names[highest];
}



if i put this should be correct?
Was This Post Helpful? 0
  • +
  • -

#13 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,901
  • Joined: 10-May 07

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 07:13 PM

Topics merged, please don't open multiple topics asking the same question.
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Write a program that prompt the user to enter number of student

Posted 26 October 2009 - 07:42 PM

That is surely not a valid Java statement

// Read the students names and scores, and add them to
studSc
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1