SHARE
TWEET

Untitled

a guest May 19th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Students
  4. {
  5.     public static void main (String [] args)
  6.     {
  7.         String[] student;
  8.         String name;
  9.         double courseWork, exam, average;
  10.         char grade;
  11.         int i;
  12.  
  13.         Scanner keyboard= new Scanner (System.in);
  14.         System.out.println("Please enter names of 10 students: ");
  15.         student= new String[10];
  16.  
  17.         //Array, prints out student1 - student10 by calling the print method
  18.         for(i=0; i<10; i++)
  19.         {
  20.             System.out.print("Student"  +(i+1)+ ": ");
  21.             student[i] = keyboard.nextLine();
  22.         }
  23.         print(student);
  24.  
  25.         //Entering data for each student
  26.         do  {
  27.             boolean found;                                          //Making the program re-run
  28.             do  {
  29.  
  30.                 System.out.print("\n");
  31.                 System.out.print("Please enter student name: ");
  32.                 name = keyboard.nextLine();
  33.                 for(int j=0; j<10; j++)
  34.                 {
  35.                     if  (name.compareTo(student[j]) == 0)
  36.                     {found = true;
  37.                     }
  38.                     else
  39.                         found = false;
  40.                         System.out.print("Student " +name+ " not found.");
  41.                 }
  42.             }   while (found = false);
  43.  
  44.             if(name.equals("NONE"))                     //Program termination if "NONE" is entered
  45.             {
  46.                 System.out.print("Program Terminated...");
  47.                 System.exit(0);
  48.             }
  49.  
  50.             do  {                                       //Keeping values in range (0-100 marks)
  51.                 System.out.print("Please enter " +name+ "'s course work mark: ");
  52.                 courseWork = keyboard.nextDouble();
  53.                 if  (courseWork < 0 || courseWork > 100)
  54.                     System.out.print("Not in valid range, please re-enter");
  55.             }   while (courseWork < 0 || courseWork > 100);
  56.  
  57.             do  {
  58.                 System.out.print("Please enter " +name+ "'s exam mark: ");
  59.                 exam = keyboard.nextDouble();
  60.                 if  (exam < 0 || exam > 100)
  61.                     System.out.print("Not in valid range, please re-enter");
  62.             }   while (exam < 0 || exam > 100);
  63.  
  64.             grade = getGrade(exam, courseWork); //Calling the getGrade method
  65.             System.out.print("Grade: " +grade);
  66.             keyboard.nextLine();
  67.         }   while (grade == 'A' || grade == 'B' || grade == 'C' || grade == 'D' || grade == 'F');
  68.     }
  69.  
  70.  
  71.     //The print method, used to print the array of students in the main method
  72.     public static void print(String[] student)
  73.     {
  74.         System.out.print("\n");
  75.         System.out.println("List of students you entered are as follows:");
  76.         for(int k=0; k<10; k++)
  77.         {   System.out.println("Student" +(k+1)+ ": " + student[k]);
  78.         }
  79.     }
  80.  
  81.  
  82.     //The getGrade method, used to output the grade for each student
  83.     public static char getGrade( double exam, double courseWork )
  84.     {
  85.         double average;
  86.         average = (courseWork + exam) / 2;
  87.         if(average < 50)
  88.         {   return 'F';
  89.         }
  90.         else if(average < 60)
  91.         {   return 'D';
  92.         }
  93.         else if(average < 70)
  94.         {   return 'C';
  95.         }
  96.         else if(average < 80)
  97.         {   return 'B';
  98.         }
  99.         else
  100.         {   return 'A';
  101.         }
  102.     }
  103. }
RAW Paste Data
Top