All pastes #163545 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-09-07 17:16 UTC
rendered paste body
/** 
* Program Description: This program prompts the user for marks of 3 subjects then produces a grade and an average mark 
* 
* By Michael Vulin 
* Date: 31.08.2006 
*/ 
import javax.swing.JOptionPane; 
import java.text.DecimalFormat; 
public class StudentGrades 
{ 
  public static void main(String[]args) 
  {    

        
      final int limit=3; 
      double avrg=0; 
      double sum=0; 
      double result = 0; 
      String repeat; 
      
   
      do 
       
      {     
          String lastName = JOptionPane.showInputDialog("Enter family name:"); 
          String firstName = JOptionPane.showInputDialog("Enter first name:"); 
          String firstUpper = firstName.toUpperCase(); 
          char ch; 
          int index = 0; 
          ch = firstUpper.charAt(index); 
          for (int count=1; count<=limit; count++) 
           
           
      
       { 
               

              
             
             
                { 
                    String subject=JOptionPane.showInputDialog("Enter subject:");     
                
                  
               
                 do{ 
                      
                     String sResult=JOptionPane.showInputDialog("Enter mark:"); 
                     result=Double.parseDouble(sResult); 
                   }while(result<0 || result>100); 
            
                  
               
                           
                                                   
               
                        
              if (result > 0 && result < 50) 
                  { 
                      JOptionPane.showMessageDialog(null,"Result for " + ch + ". " + lastName + "\n" + subject + ":" + " " + "Fail"); 
                        
                  } 
              else 
                  if (result >=50 && result < 60) 
                
                  { 
                      JOptionPane.showMessageDialog(null,"Result for " + ch + ". " + lastName + "\n" + subject + ":" + " " + "Pass"); 
                        
                  } 
                  else 
                      if (result >=60 && result < 70) 
                      { 
                          JOptionPane.showMessageDialog(null,"Result for " + ch + ". " + lastName + "\n" + subject + ":" + " " + "Credit"); 
                            
                      } 
                      else 
                          if (result >=70 && result < 80) 
                          { 
                              JOptionPane.showMessageDialog(null,"Result for " + ch + ". " + lastName + "\n" + subject + ":" + " " + "Distinction"); 
                                
                          } 
                          else 
                              if (result >=80 && result <=100) 
                              { 
                                  JOptionPane.showMessageDialog(null,"Result for " + ch + ". " + lastName + "\n" + subject + ":" + " " + "High Distinction"); 
                                    
                             } 
                   } 
                    
                    
                    
                   
                   
                      sum = sum + result;        
                } 
           
           
          DecimalFormat fmt = new DecimalFormat("0.##"); 
          avrg = sum / 3 ; 
          JOptionPane.showMessageDialog(null, "Average for " + ch + ". " + lastName + "\n" + fmt.format(avrg)); 
                
          repeat = JOptionPane.showInputDialog("Another student (y/n)?"); 
      }      
        
      while (repeat.equalsIgnoreCase("y"));                  
    
    
  }                                  
}