Saturday, August 29, 2015

Average Grade Using One Dimensional Array in Java

In this example I wrote a program that will compute the average grade of the student on his or her several subjects using one dimensional array in Java the code is very simple to understand and use.

If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

/*
average_array.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 23, 2015
Tools: NetBeans 8.0.2, Java SE 8.0

Problem No. 2:
  
Write a program that will ask the user to give eight grades for
eight subjects and then our program will find average grade of 
the student from the eight subjects.
*/
              

import java.util.Scanner;

class grade_array {
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
     String[] subjects = new String[]
     {"Computer", "Math", "English","Physical Education",
      "History","Science","Music and Arts","Filipino"};
     
  do { 
      int [] values; 
      values  = new int[8];  
      int x=0,average_grade=0,total_sum=0;
      System.out.print("Average Grade Solver");
      System.out.println();
      for (int a=0; a<8; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter your subject grade on " + subjects[a] + " : ");
         values[a] = input.nextInt();
         total_sum+=values[a];
         average_grade = total_sum/8;
      }
     System.out.println(); 
     System.out.println();
     System.out.print("Your average grade is 8 subject is " + average_grade + ".");
     System.out.println();
     System.out.print("\nDo you want to continue (Type y or n) : ");
     ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
     System.out.println();
     System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
     System.out.println("\n\n");
  }
} // End of Code

No comments:

Post a Comment