Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, someone previously helped me with setting up a program that displays a lot o

ID: 3866361 • Letter: H

Question

Hi, someone previously helped me with setting up a program that displays a lot of test scores. I had to reconfigure it a little to use JOptionPane dialog boxes, but now I am trying to get it so that all the scores show up in one dialog box. Right now it is set up as a loop so that each time the loop goes through, it displays that score in dialog box (which results in a lot of dialog boxes). I want to display all the scores in one dialog box, can anyone help me reconfigure this part to make that happen?

//Displaying the test scores and number of students who got that test scores private static void listofscores (int[] marks) int students[0;inewmarts.length; for (int 1-0; 1

Explanation / Answer

Here is the modified code to display all marks in one dialog box:

private static void listofScores(int[] marks)
{
String out="";
for(int i=0;i<marks.length;i++)
{
out+=marks[i]+" marks ";
}
JOptionPane.showMessageDialog(null, "Displaying students marks list: "+out); //to display list marks
}

Here is the code if you want to display x marks got by total number of student:

private static void listofScores(int[] marks,int[] stumarks)
{
//int[] marks is a list of marks and int[] stumarks is a list of students marks
int count=0;
String out="";
for(int i=0;i<marks.length;i++)
{
for(int j=0;j<stumarks.length;j++)
{
if(marks[i]==stumarks[j])
count++;
}
out+=count+" got "+marks[i]+" marks ";
count=0;
}
JOptionPane.showMessageDialog(null, "Displaying students marks list: "+out); //to display list marks
}

I hope this code solves your problem :)

comment If you have any problem in this code.

and dont forget to give thumbs up :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote