Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class Student {
  5.    
  6.     private String id;
  7.     private String [] quizresult=new String[10];
  8.     public int score;
  9.     public char letterGrade;
  10.    
  11.     public Student(){
  12.        
  13.         id=" ";
  14.         for(int i =0; i<quizresult.length; i++){
  15.              quizresult[i]="";
  16.                        
  17.         }
  18.        
  19.         score =0;
  20.     }
  21.    
  22.    
  23.     public Student(String a, String[] answers){
  24.        
  25.         id=a;
  26.        
  27.         for(int i=0; i<answers.length; i++){
  28.            
  29.             quizresult[i]=answers[i];
  30.            
  31.         }
  32.        
  33.         score = 0;
  34.        
  35.     }
  36.    
  37.     public String [] getAnwers(){
  38.        
  39.         return quizresult;
  40.        
  41.     }
  42.    
  43.     public String getId(){
  44.        
  45.         return id;
  46.        
  47.     }
  48.    
  49.    
  50.     public void grade(String [] answerkey, String[] studentanswer){
  51.        
  52.         int count=0;
  53.        
  54.                 for(int i=0; i<answerkey.length; i++){
  55.                    
  56.                     if(answerkey[i].equals(studentanswer[i])){
  57.                        
  58.                         count = count+10;
  59.                        
  60.                     }
  61.                    
  62.                 }
  63.        
  64.                 score = count;
  65.        
  66.        
  67.     }
  68.    
  69.    
  70.    
  71.    
  72.  
  73.  
  74.     public int getScore() {         //method to get the score
  75.  
  76.         return score;
  77.     }
  78.  
  79.  
  80. //method assigns letter grade based on score
  81.     public static char assignLetterGrade (int score) {
  82.        
  83.        
  84.         char letterGrade;
  85.    
  86.         if(score == 100)
  87.             letterGrade = 'A';
  88.         else if(score == 90)
  89.             letterGrade = 'B';
  90.         else if(score == 80 || score ==70)
  91.             letterGrade = 'C';
  92.         else if(score == 60 || score == 50)
  93.             letterGrade = 'D';
  94.         else
  95.             letterGrade = 'F';
  96.        
  97.        
  98.         return letterGrade;
  99.     }
  100.    
  101. public String toString(){
  102.        
  103.         String a = "Student id: " + id + " " +  Arrays.toString(quizresult) + " The score for this quiz is:  " +  score + " The letter grade is: " + letterGrade + "\n";
  104.        
  105.         return a;
  106.        
  107.        
  108.            
  109.             }
  110.    
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement