the program accept student name and grades and output it.use an array.
it also traverses the array and allow the user to perform the following processes
a) search for a particular student and his or her marks
b)find the average of all the student in the class
c)find all student with a mark below 50 and output them.
Expand|Select|Wrap|Line Numbers
- import javax.swing.JOptionPane;
- import java.util.Arrays;
- public class pdemo {
- private String[] names;
- private int [] grade;
- public int Nos;
- private String num;
- public String go ,b,c,x;
- public pdemo()
- {
- num =JOptionPane.showInputDialog( null,"Welcome Enter the Number of student taking This Couse");
- Nos = Integer.parseInt(num);
- names = new String[Nos];
- grade=new int [Nos];
- }
- public void inputNames()
- {int z =1;
- for (int i = 0; i < names.length; i++) {
- names[i] = JOptionPane.showInputDialog("Enter name: "+z);
- ++z;
- }
- }
- public void inputGrades()
- {
- for(int i=0; i<grade.length ; i++)
- {int z=1;
- System.out.println("Enter the grade ");
- num =JOptionPane.showInputDialog(null,"Enter the grade "+ z);
- grade[i] =Integer.parseInt(num);
- ++z;
- }
- }
- public void trav()
- {
- for (int da=0;da<names.length;da++) {
- JOptionPane.showMessageDialog(null, da+ ":"+ names[da]+" :"+grade[da]);
- Array.sort(names);
- }
- }
- public void search(String name)
- {
- int i=0;
- {
- name = JOptionPane.showInputDialog ("What is the name of the student u are looking for?");
- }
- {
- for( ; i<names.length ; i++){
- if( names[i].equals(name) ){
- JOptionPane.showMessageDialog(null,"found " + names[i] + " at index " + i + " with grade " + grade[i]);
- }
- }
- }
- }
- public void average()
- {
- double ave=0;
- /*if (b==b)*/{
- for(int i=0; i<grade.length ; i++)
- {
- ave+=grade[i];
- }
- JOptionPane.showMessageDialog(null,"The average of the total student body is:"+ ave);
- }
- }
- public void below(){
- /*if (c==c)*/{
- JOptionPane.showMessageDialog(null,"The following people have a grade lower than 50");
- for(int i=0 ; i<grade.length ; i++){
- if( grade[i]<50 ){
- JOptionPane.showMessageDialog(null,names[i] + ": " + grade[i]);
- }
- }
- }
- }
- }
- import java.io.*;
- public class Main {
- public static int n;
- public static String name;
- /**
- * @param args the command line arguments
- */
- private static BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );
- public static void main(String[] args)
- throws IOException
- {
- pdemo demo = new pdemo();
- demo.inputNames();
- demo.inputGrades();
- demo.trav();
- //demo.sele();
- demo.search(name);
- demo.below();
- demo.average();
- }
- }