Sort by

recency

|

1179 Discussions

|

  • + 0 comments
    class Student extends Person{
    	private int[] testScores;
        Student(String firstName, String lastName, int identification, int a[]){
            super(firstName,lastName,identification);
            this.testScores=a;
        }
        public String calculate(){
            int sum=0;
            for(int i=0; i<testScores.length; i++){
                sum+=testScores[i];
            }
            int avg=sum/testScores.length;
            if(avg>=90 && avg<=100){
                return "O";
            }
            else if(avg>=80 && avg<90){
                return "E";
            }
            else if(avg>=70 && avg<80){
                return "A";
            }
            else if(avg>=55 && avg<70){
                return "P";
            }
            else if(avg>=40 && avg<55){
                return "D";
            }
            return "T";
        }
    }
    
  • + 0 comments

    Java Solution

    class Student extends Person{
    	private int[] testScores;
        
        Student(String firstName, String lastName, int id, int[] scores){
            super(firstName, lastName, id);
            this.testScores = scores;
        }
    
        char calculate() {
            int myScore = 0;
            for(int i : testScores) myScore += i;
            myScore /= testScores.length;
    
            char myResult = (
              (myScore>=90)?'O':
              (myScore>=80)?'E':
              (myScore>=70)?'A':
              (myScore>=55)?'P':
              (myScore>=40)?'D':
              'T'
            );
            
            return(myResult);
        }
        
    }
    
  • + 0 comments

    in c#

    class Student : Person{ private int[] testScores;

    public Student(string firstName,string lastName,int id,int[] scores):
    base(firstName,lastName,id)
    {
                testScores=scores;
    }
    
    public char Calculate()
    {
       int avg= testScores.Sum() /testScores.Count();
    
        switch(avg)
        {
            case int n when n>=90 &&  n<=100:
                return 'O';
                break;
            case int n when n>=80 && n<90:
                return 'E';
                break;
            case int n when n>=70 && n<80:
                return 'A';
                break;
            case int n when n>=55 && n<70:  
                return 'P';
                break; 
            case int n when n>=40 && n<55:  
                return 'D';
                break;
             case int n when  n<40:  
                return 'T';
                break; 
            default :
            return ' ';
            }
    
    }
    

    }

  • + 0 comments
    class Student extends Person{
    	private int[] testScores;
        Student(String firstname,String lastname,int id,int testScores[]){
           super(firstname,lastname,id);
            this.testScores=testScores;
        }
        public char calculate(){
            int sum=0;
            for(int i=0;i<testScores.length;i++){
                sum=sum+testScores[i];
            }
            int avg=sum/testScores.length;
            if(avg>=90 && avg<=100) return 'O';
            else if(avg>=80 && avg<90) return 'E';
            else if(avg>=70 && avg<80) return 'A';
            else if(avg>=55 && avg<70) return 'P';
            else if(avg>=40 && avg<55) return 'D';
            else return 'T';
        }
    }
    
  • + 0 comments

    class Person: def init(self, firstName, lastName, idNumber): self.firstName = firstName self.lastName = lastName self.idNumber = idNumber def printPerson(self): print("Name:", self.lastName + ",", self.firstName) print("ID:", self.idNumber)

    class Student(Person): def init(self, firstName, lastName, idNumber, scores): self.firstName = firstName self.lastName = lastName self.idNumber = idNumber self.scores = scores

    def calculate(self):
        sum = 0
        for score in self.scores:
            sum += score
    
        avg = sum / len(self.scores)
        if avg <= 100 and avg >= 90:
            return "O"
        elif avg < 90 and avg >= 80:
            return "E"
        elif avg < 80 and avg >= 70:
            return "A"
        elif avg < 70 and avg >= 55:
            return "P"
        elif avg < 55 and avg >= 40:
            return "D"
        else:
            return "T"
    

    line = input().split() firstName = line[0] lastName = line[1] idNum = line[2] numScores = int(input()) # not needed for Python scores = list( map(int, input().split()) ) s = Student(firstName, lastName, idNum, scores) s.printPerson() print("Grade:", s.calculate())