Question

2. Create a class that represents a group of students called GroupOfStudents. Create another class Student that represents a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

***Please leave a rating or give a review if you liked the solution***

Screenshot of the code:-

Student.py

class GroupOfStudents: def init__(self, student_list): self.student_list = student_list #Creating the average of the list of

for i in range(0, len (self.student_list)): if self.student_list[i].getTest_score() == max: students.append(self.student_list

StudentTester.py

from Student import Student from Student import GroupofStudents students1 = [] students2 = [] print(For Group 1) 3 students

#Printing the names of students below average for group 1 for name in gl.name30fStudentsBelowAverage(): print (name) dict1 =

Screenshot of the output:-

For Group 1 Enter name Ashish Enter test score 20 Enter name Prakash Enter test score 30 Enter name Javi Enter test score 40

Python Code to copy:-

Student.py -This is to create the two classes

class GroupOfStudents:

def __init__(self,student_list):
self.student_list = student_list

#Creating the average of the list of students
def group_average(self):
sum = 0

for i in range(0,len(self.student_list)):

sum = sum + self.student_list[i].getTest_score()

return sum/len(self.student_list)

#Getting the names of students whose marks are below average
def namesOfStudentsBelowAverage(self):

names = []

avg = self.group_average()

for i in range(0,len(self.student_list)):

if self.student_list[i].getTest_score() < avg:
names.append(self.student_list[i].getName())

return names

#Getting the max score and list of students scoring equal to max_score
def highest_test(self):

max = 0;

for i in range(0,len(self.student_list)):

if self.student_list[i].getTest_score() > max:
max = self.student_list[i].getTest_score()

students = []
  
for i in range(0,len(self.student_list)):
if self.student_list[i].getTest_score() == max:
students.append(self.student_list[i].getName())


max_dict = {max:tuple(students)}
return max_dict

class Student:

  
def __init__(self,name,test_score):
self.name = name
self.test_score = test_score

#Getters and Setters of Student class
def getName(self):
return self.name
  

def setName(self,name):
self.name = name
  

def getTest_score(self):
return self.test_score
  

def setTest_score(self,test_score):
self.test_score = test_score;
  

StudentTester.py - This is to create the testing module

from Student import Student
from Student import GroupOfStudents

students1 = []
students2 = []

print("For Group 1")

#3 students for the first group
for i in range(0,3):

print("Enter name")
name = input()
print("Enter test score")
test_score = int(input())
  
students1.append(Student(name,test_score))


print("For Group 2")

#3 students for the second group
for i in range(0,3):

print("Enter name")
name = input()
print("Enter test score")
test_score = int(input())
  
students2.append(Student(name,test_score))

#Creating two instances of GroupOfStudents
g1 = GroupOfStudents(students1)
g2 = GroupOfStudents(students2)

#Printing the group average for group 1
print("Group Average: " + str(g1.group_average()))

print("Names of students below average for group 1")

#Printing the names of students below average for group 1
for name in g1.namesOfStudentsBelowAverage():
print(name)

dict1 = g1.highest_test()

#Printing the highest score and the name of students equal to highest score for group 1
for key in dict1:
print("Max score " + str(key), end = ",")
print("Name ",end=":")

temp = dict1[key]
  
for name in list(temp):
print(name +" ")

#Printing the group average for group 1
print("Group Average: " + str(g2.group_average()))

print("Names of students below average for group 2")

#Printing the group average for group 1
for name in g2.namesOfStudentsBelowAverage():
print(name)

dict2 = g2.highest_test()

#Printing the highest score and the name of students equal to highest score for group 1
for key in dict2:
print("Max score " + str(key), end = ",")
print("Name ",end=":")

temp = dict2[key]
  
for name in list(temp):
print(name +" ")
  


  
  
  
  

  
  

Add a comment
Know the answer?
Add Answer to:
2. Create a class that represents a group of students called GroupOfStudents. Create another class Student...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write this code on python 3 only. Suppose class Student represents information about students in a...

    Write this code on python 3 only. Suppose class Student represents information about students in a course. Each student has a name and a list of test scores. The Student class should allow the user to view a student's name, view a test score at a given position, view the highest test score, view the average test score, and obtain a string representation of the student's information. When a Student object is created, the user supplies the student's name and...

  • Write a Python program that creates a class which represents a candidate in an election. The...

    Write a Python program that creates a class which represents a candidate in an election. The class must have the candidates first and last name, as well as the number of votes received as attributes. The class must also have a method that allows the user to set and get these attributes. Create a separate test module where instances of the class are created, and the methods are tested. Create instances of the class to represent 5 candidates in the...

  • Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class...

    Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class •Initializing Objects using Constructors •Software Engineering with Private Instances Variables and Public Set/Get Methods •Uses Methods inside classes Description: You are asked to write a program to process two students’ scores. Each student will have scores for 3 tests, the user will input each student’s full name followed by their three scores. When the data for the two students are read from the keyboard,...

  • Use C++ to create a class called Student, which represents the students of a university. A...

    Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • please use java do what u can 1. Modify the Student class presented to you as...

    please use java do what u can 1. Modify the Student class presented to you as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called set Test Score that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called get...

  • Key Takeaways -To create 2 groups of 4 students (8 students in total) -NEEDS random GPAs for each student -No arrays ---...

    Key Takeaways -To create 2 groups of 4 students (8 students in total) -NEEDS random GPAs for each student -No arrays ------------------------------------- app.java, student.java, and group.java as requested below. Please use the diagram above to help answer the Question: Create a project that: Has a student class Instance variables for Firstname, last name , and age random generated GPA methods to return getinfo and semesterGPA Build upon the solutions of the previous labs (e.g., using app.java and student.java) You will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT