Friday, 5 July 2013

Student Grade Report

Student Grade Report Java Program

Java Code:


import java.util.Scanner;


public class grade {



       public static void average(int[] array){
       double sum=0;
       int count=0;
       double average=0;
       for(int i=0; i<array.length; i++){
              sum+=array[i];
              count++;
       }
       average=sum/count;
       System.out.print(average);
    }
       public static void main(String[] args) {

              Scanner input = new Scanner(System.in);
              System.out.print("Enter the number of students: ");
              int NoS = input.nextInt();
              String[] names = new String[NoS];
        int[] array = new int[NoS];
              int i=0;
              int Score;
              while(i<NoS){
              System.out.print("Enter the test Score: ");
              Score = input.nextInt();
              if(Score<0 || Score >100){
                     System.out.print("incorrect score, Re-enter the score-(must be positive and between 0 to 100):");
                     Score = input.nextInt();
              }
             
             
              array[i]=Score;
              System.out.print("Enter the Student Name: ");
              String name = input.next();
              names[i]=name;
              i++;
             
             
              }
              int h=array[0];
              int high=0;
              int j=0;
              while(j<array.length){
                    
                     if(h>=array[j]){
                           high= h;
                           j++;
                     }
                     else{
                           h=array[j];
                     }
                     }
              int l=array[0];
              int low=0;
              int k=0;
              while(k<array.length){
                    
                     if(l<=array[k]){
                           low=l;
                           k++;
                           }
                     else{
                           l=array[k];
                     }
              }
              int ind=0;
              int n=0;
              int m=0;
              while(ind<array.length){
                     if(array[ind]==high){
                           n=ind;
                          
                     }
                     if(array[ind]==low){
                           m=ind;
                          
                     }
              ind++;
                    
             
              }
              System.out.print("\n");
              System.out.println("Test Analysis Program");
              System.out.println("High score: "+ names[n] +": "+ high);
              System.out.println("Low score: "+ names[m] +": "+ low);
             
              System.out.print("Class average is" + " ");
        average(array);
       
      
              int grade=0;
              int a=0;
              int b=0;
              int c=0;
              int d=0;
              int e=0;
              while(grade<array.length){
                     if(array[grade]>=90){
                           a+=1;
                     }
                     if(array[grade]>=80 && array[grade]<90){
                           b+=1;
                     }
                     if(array[grade]>=70 && array[grade]<80){
                           c+=1;
                     }
                     if(array[grade]>=60 && array[grade]<70){
                           d+=1;
                     }
                     if(array[grade]>=0 && array[grade]<60){
                           e+=1;
                     }
                     grade++;
              }
               System.out.print("\n");
                     System.out.println("Grade Distribution");
                     System.out.println("90-100: " + a);
                     System.out.println("80-89:  " + b);
                     System.out.println("70-79:  " + c);
                     System.out.println("60-69:  " + d);
                     System.out.println("Below 60:" + e);
             
       }

}

  Program Snapshots:

 

Compound Interest Java Program

Compound Interest Java Program

Java Code:


import java.util.*;

public class compoundInterest {

       /**
        * @param args
        */
      
       public static void main(String[] args) {
              // TODO Auto-generated method stub
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the Initial Investment: ");
              double Iv = input.nextInt();
              System.out.print("Enter Annual Interest Rate in % : ");
              double Ap = input.nextInt();
              System.out.print("Enter Number of years: ");
              double Ny = input.nextInt();
             
              System.out.println("Year" +" "    +"Beginning Balance"+" "+" "+"Interest"+" "+" "+ "Ending Balance");
              for(int i=1; i<=Ny;i++){
                     double in=(Iv*Ap)/100;
                     double ou=(Iv+in);
                     System.out.printf(i+ " "+" "+" "+ " "+"%.2f", Iv );
                     System.out.printf(" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+ "%.2f", in );
                     System.out.printf(" "+" "+" "+" "+"%.2f", ou );
                     System.out.println();
                     Iv=ou;
              }
             
             
             

       }

}

 Snapshots: