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: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
totengtoh 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.