hello sir!!!

i need the answer as soon as possible!! can you change this code and execute it using the JOptionPane... Please help me!!! You may send your answers to this address... <snip email>
Thanks a lot!!!

import java.io.*;

public class ToyoradaII
{  
    public static void main(String []lyn)   
    throws IOException
   {
     String choice;
        InputStreamReader stream=new InputStreamReader(System.in);
        BufferedReader read=new BufferedReader(stream);   

        int grades[]=new int[10];
        int num=1;
        
        String str;
do{        
System.out.println("+-----------------------------------+");        
System.out.println("|NOTE 1:NO GRADES BELOW 50 0R HIGHER|\n|\t\tTHAN 100 SHALL BE ENTERED!  |");
System.out.println("+-----------------------------------+");          
System.out.println("+---------------------------------------+");
System.out.println("THIS PROGRAM ACCEPTS ONLY WHOLE NUMBERS!|");
System.out.println("+---------------------------------------+");

        int x=0;
        while(x<10)
 {
 do{
   System.out.println("\n");
   
            System.out.print("Student "+num+":");
            str=read.readLine();
            grades[x]=Integer.parseInt(str);
           
            if(grades[x]<50)
             {
                System.out.println("GRADE BELOW 50 NOT ALLOWED! \n\tEnter another. . . ");
                }
                
            if(grades[x]>100)
            {
            System.out.println("OVERWHELMING GRADE!\n\tEnter another. . .");
            }
           
            }
     while(grades[x]<50||grades[x]>100);
            num++; 
            x++;     
        }
        
        
System.out.println("+------------------+");

int Hi_Grade;
     int y=0;
     while(y<grades.length-1)   

 {
            if(grades[y]>grades[y+1])
     {
            Hi_Grade=grades[y];
            grades[y]=grades[y+1];
            grades[y+1]=Hi_Grade;
            }
            y++;
        }
        
        System.out.println("\n\nHIGHEST GRADE: "+grades[9]);
       

int Low_Grade;
 int z=0;
 while(z<grades.length-1)

 {  
            if(grades[z]<grades[z+1]){
            Low_Grade=grades[z];
            grades[z]=grades[z+1];
            grades[z+1]=Low_Grade;
            }
            z++;
        }
        
        System.out.println("\nLOWEST GRADE: "+grades[9]);


int Average=0;
        int ave=0;
        while(ave<grades.length)
    
 {
        Average+=grades[ave];
        ave++;
        }
        

        Average=Average/10;
     System.out.println("\nAVERAGE GRADE: "+Average);

 

   
     System.out.println("\n\nGRADE DISTRIBUTION: ");
   int dist1=0;
   int a=0;
   while(a<grades.length)
 {
        if(grades[a]>=50&&grades[a]<=60)
 {
  
        dist1++;
        
 }a++;
}
        System.out.print("\n50-60 : ");
        int b=0;
        while(b<dist1)
        
 {
        System.out.print("*");
        b++;
        } 
        

int dist2=0;  
 int c=0;
    while(c<grades.length) 
 {
            if(grades[c]>=61&&grades[c]<=70)
     {
            dist2++;
            
     }c++;
        }
        System.out.print("\n61-70 : ");
        int d=0;
        while(d<dist2)
      
 {
        System.out.print("*");
        d++;
        }
        
       

int dist3=0;
 int e=0;
    while(e<grades.length)
 {
            if(grades[e]>=71&&grades[e]<=80)
     {
            dist3++;
            
     }e++;
        }
        System.out.print("\n71-80 : ");
        int f=0;
        while(f<dist3)
    
 {
        System.out.print("*"); 
         f++;  
        }
        
    
int dist4=0;
 int g=0;
    while(g<grades.length)
 {
            if(grades[g]>=81&&grades[g]<=90)
     {
            dist4++;
            
     }g++;
        }
        System.out.print("\n81-90 : ");
        int h=0;
        while(h<dist4)
     
 {
        System.out.print("*");
        h++;
        }

int dist5=0;
 int i=0;
    while(i<grades.length)
 {
            if(grades[i]>=91&&grades[i]<=100)
  {
                dist5++;
                
  }i++;
        }
        System.out.print("\n91-100: ");
        int j=0;
        while(j<dist5)
       
 {
        System.out.print("*");
        j++;
        }
        
       
  System.out.println("\n+------------------------------+");
     System.out.print("|WANT TO DO IT AGAIN? [YES][NO]|");
     System.out.println("\n+------------------------------+");
     choice=read.readLine();
          
     if(choice.equalsIgnoreCase("yes"))
     num=1;
     
}while(choice.equalsIgnoreCase("yes"));
   } 
}

Do you know which part of the code needs to be replaced with JOptionPane? If you don't that probably means that you didn't write it. Tell us what you don't understand and we will help, but no one is going to email you the solution

if you want it in JFrame then i've done it. Let me know if you still need it.

@hny_lyn

  1. Read the rules, no request for homework solutions to be send over by email or PM
  2. "i need the answer as soon as possible!!" is rude thing to say, we will help when we want, it doesn't matter to us that when you need to submit this home work
  3. a code that has exception attached to main method is one of the worst things and we do not like to see it

if you want it in JFrame then i've done it. Let me know if you still need it.

If you think you helping him, you are mistaken. By giving the code, hny_lyn will learn nothing. Copy & paste is not a solution when you learning

commented: Agree with all of this. +10

hello sir!!!

i really do learn something about java!! its just that its too hard for me as a beginner!!!
actually, our project is about a 2-dimensional array using JOptionPane!! i have made that code<the one posted> last week...,<i really made it! swear!!>

i just wanted to have an idea on how to do it with JOption!!

sir peter_budo;

sorry for using such statements!! to show you that i have learned something in java.... it have made this code...

public class Grade{
	public static void main (String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		String str;
		String grad;
		int student[][]=new int[10][3];
		String prelim;
		String midterm;
		String finals;
		int mj=1;
		int lowest=0;
		int highest=0;
		int average=0;
		
		for(int rw=0; rw<10; rw++){
			for(int col=0; col<3; col++){
				do{
					grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]");
					student[rw][col]=Integer.parseInt(grad);
					if(student[rw][col]<50||student[rw][col]>100){
						JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
						}
					grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]");
					student[rw][col]=Integer.parseInt(grad);
					if(student[rw][col]<50||student[rw][col]>100){
						JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
						}
					grad=JOptionPane.showInputDialog("Student Finals["+mj+"]");
					student[rw][col]=Integer.parseInt(grad);
					if(student[rw][col]<50||student[rw][col]>100){
						JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
						}
				}while(student[rw][col]<50||student[rw][col]>100);
				mj++;
				if()
				
				
			}
		}	
			   }
}

///the problem now sir, is that im hanging in this state...its about 2-dimensional arrays!!
>i have to get the lowest grade, the highest and the average.... one thing i know on how to get this is by means of sorting......SORTING 2-dimensional arrays is my problem now!!! the output is just similar to my first posted thread!!!

hello sir!!!

i made the code!!
i swear!!!

i just dont have enough idea about the JOption thing!!!

Sorry!!

for(int rw=0; rw<10; rw++){
for(int col=0; col<3; col++){
do{
grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]");
student[rw][col]=Integer.parseInt(grad);
if(student[rw][col]<50||student[rw][col]>100){
JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
}
grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]");
student[rw][col]=Integer.parseInt(grad);
if(student[rw][col]<50||student[rw][col]>100){
JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
}
grad=JOptionPane.showInputDialog("Student Finals["+mj+"]");
student[rw][col]=Integer.parseInt(grad);
if(student[rw][col]<50||student[rw][col]>100){
JOptionPane.showMessageDialog(null,"Inputed Grade of student is not allowed!!!");
}
}while(student[rw][col]<50||student[rw][col]>100);
mj++;

Let's talk about your code:

You don't need 2 for loops. This is what you wrote:

grad=JOptionPane.showInputDialog("Student Prelim["+mj+"]");
student[rw][col]=Integer.parseInt(grad);
grad=JOptionPane.showInputDialog("Student Midterm["+mj+"]");
student[rw][col]=Integer.parseInt(grad);
grad=JOptionPane.showInputDialog("Student Finals["+mj+"]");
student[rw][col]=Integer.parseInt(grad);

You will put 3 different values:
1) JOptionPane.showInputDialog("Student Prelim["+mj+"]") ;
2) JOptionPane.showInputDialog("Student Midterm["+mj+"]")
3) grad=JOptionPane.showInputDialog("Student Finals["+mj+"]")
At the same location: student[rw][col]

You might want to try this:

for (int i=0;i<10;i++) {

grad=JOptionPane.showInputDialog("Student Prelim["+i+"]");
student[i][0]=Integer.parseInt(grad);

grad=JOptionPane.showInputDialog("Student Midterm["+i+"]");
student[i][1]=Integer.parseInt(grad);

grad=JOptionPane.showInputDialog("Student Finals["+i+"]");
student[i][2]=Integer.parseInt(grad);
}

Assuming that at the location:
[0] there will be the Preilim
[1] there will be the Midterm
[2] there will be the Finals

As for the check I would suggest first to take all the values, check them all and then put them in the array:


for (int i=0;i<10;i++) {

boolean ok = false;
while (!ok) {
 prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]");
 midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]");
 finals=JOptionPane.showInputDialog("Student Finals["+i+"]");

 if (/* check the above values. if they are ok*/) {
  ok=true;

  //put them in the array as showed above
  }

 }

}

The first time the check will be made, ok will be false and you will go in the while. If the values are valid, ok will be turned into true. So the while statement (!ok) will be false, and you will exit the while, and you will continue at the next for loop. If the values are wrong then the ok variable will not change and you will repeat the while.

sir!

thank you for this!!

i'll share this with my other classmates..., same with me...having troubles dealing with this JOptionPane!!

Another version using YOUR do while loop is this:

for (int i=0;i<10;i++) {

do{
 prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]");
 midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]");
 finals=JOptionPane.showInputDialog("Student Finals["+i+"]");

  boolean bPrelim =(prelim<50) || (prelim>100) ;
  boolean bMidterm =(midterm<50) || (midterm>100) ; 
  boolean bFinals =(finals<50) || (finals>100) ;

  if (bPrelim ) {
    //print the appropriate error message
  }
  if (bMidterm) {
    //print the appropriate error message
  }
  if (bMidterm) {
    //print the appropriate error message
  }

  student[i][0]=Integer.parseInt(prelim);
  student[i][1]=Integer.parseInt(midterm);
  student[i][2]=Integer.parseInt(finals);  

}  while( bPrelim || bMidterm || bMidterm);

}

If any of the boolean variables are true, that means that the values are wrong. So the while will repeat and ask for the values again. The <i> will not chang since you are inside the same for loop. If all the boolean values are false, means that all the values are correct and the while will be false, so you will continue with the next for loop.

You could also try this:

for (int i=0;i<10;i++) {

do{
 prelim=JOptionPane.showInputDialog("Student Prelim["+i+"]");
 midterm=JOptionPane.showInputDialog("Student Midterm["+i+"]");
 finals=JOptionPane.showInputDialog("Student Finals["+i+"]");

  boolean bPrelim =(prelim<50) || (prelim>100) ;
  boolean bMidterm =(midterm<50) || (midterm>100) ; 
  boolean bFinals =(finals<50) || (finals>100) ;

  if (bPrelim ) {
    //print the appropriate error message
  }
  if (bMidterm) {
    //print the appropriate error message
  }
  if (bMidterm) {
    //print the appropriate error message
  }
}  while( bPrelim || bMidterm || bMidterm);

  student[i][0]=Integer.parseInt(prelim);
  student[i][1]=Integer.parseInt(midterm);
  student[i][2]=Integer.parseInt(finals);  
}

REGARDING MY THREAD!
my problem now is that... how can i get the "average grade" of those given grades!!

for example:
the user have given me three grades....PRELIM,MIDTERM den FINALS!

its in the array right? what could be the possible code to do this??

Mr. moderator,

sorry for my mistakes!

Once you have the necessary information for a specific student:

double avg = (student[i][0] + student[i][1] + student[i][2])/3.0

REGARDING MY THREAD:

its about 2dimensional arrays!
my program accepts 3 input grades! my problem is how can i get the average of those 3 grades!!!

thanks javaAddict!!!!!
How about getting the highest average grade and the lowest????

Put all the averages in a new array. Then write two methods that accept an array as input and return the greater and the lower value.

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.