0

guys, i am making a program in java. i have to use a sorting agoritm. i manage to get some from the internet
but it seems that they are too technical and hard to understand and i dont know where to put them and how to use them.
here is my codes!please help me on where i will put the sorting algo..
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import javax.swing.*;
public class StudGrade {
public static void main(String args[]) {
String sGrade="";
int grade[] = new int [11];
for(int iGrade=1;iGrade<11;iGrade++)
{
sGrade=JOptionPane.showInputDialog("Student "+iGrade);
grade[iGrade]=Integer.parseInt(sGrade);
}
String output2="";
String output = "Students\tGrades\n";
float sum = 0;
float average=0;
for (int counter = 1;counter<grade.length;counter++)
{
//can you also please help me on how i can modify this following codes using for loop?:mrgreen:
sum = grade[1]+grade[2]+grade[3]+grade[4]+grade[5]+grade[6]+grade[7]+grade[8]+grade[9]+grade[10];
average = sum/10;
output +="\nStudent "+counter+"\t"+grade[counter];
//after sorting, i should display the lowest and the highest grade in the list, also a problem:mrgreen:
output2 = "\t\n\nThe average grdae is : "+average+"\nThe highest grade is : " +"\nThe lowest grade is : ";
}
JTextArea outputArea = new JTextArea();
outputArea.setText(output+output2);
JOptionPane.showMessageDialog(null, outputArea);
System.exit(0);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
here is the sample of the sorting algo, the bubble sort.please give me an example of a program that uses sorting algo
and i will work on it.i may be not become a good programmer,i want to be one.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class BubbleSort2Algorithm extends SortAlgorithm {
void sort(int a[]) throws Exception {
for (int i = a.length; --i>=0; ) {
boolean flipped = false;
for (int j = 0; j<i; j++) {
if (stopRequested) {
return;
}
if (a[j] > a[j+1]) {
int T = a[j];
a[j] = a[j+1];
a[j+1] = T;
flipped = true;
}
pause(i,j);
}
if (!flipped) {
return;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
i am an IT diploma student in a small town in philippines. guys, any help from you will be fully appreciated.
///////////////////////////////////////////////:cheesy: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2
Contributors
3
Replies
5
Views
10 Years
Discussion Span
Last Post by totengtoh
0

".i may be not become a good programmer,i want to be one."

Wrong attitude. Why should we help someone becoming a bad programmer? There are more than enough bad programmers already...

As to examples of programs using sorting algorithms, just look around you.
You find sorted lists of stuff everywhere.

0

".i may be not become a good programmer,i want to be one."
what i mean is, i may not become good in programming, not a bad progrmmer. sorry coz what ive written is not clear

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.