Using Python,
Write a class named Scores. This data structure will store a collection of lab scores (or programs scores or any other collection of scores). Since numbered assignments generally start with 1 – your first assignment this summer was lab 1 – the user of this class will think of this collection as being a 1-based list of values. All the methods which require a lab number will assume that value is based upon what the user sees, a 1 based list, and not what the programmers sees. You will have to use a list to store the scores. You could even use the FlexibleArray class instead of a traditional list to implement the 1-based list.
Specifics
Create the following methods and variable, EXACTLY as specified:
Class variable
NO_VALUE – set to -1
Constructor
Creates a list of length maxSize and sets the initial value of each variable to NO_VALUE.
Setters and Getters
getScore(index) – returns a single value from the array. The argument is the user’s index of the item to return.
getNumOfScores() – returns the number of non-default scores stored in the list.
getTotalPoints() – returns the total of the non-default scores stored in the list.
getMaxValue() – returns the maximum value in the list.
getMinValue() – returns the minimum, non-default value in the list.
getAverage () – returns the average of the non-default scores.
setScore(index, score) – the first argument is the user’s number of the lab, the second argument is the score. Only accept scores between 0 and 200. Return True if the value is accepted into the list, otherwise return False.
Write a program to thoroughly test the Scores class. This test program must test ALL the required functionality required within the class. The test program does not necessarily have to have user input from the keyboard, it just needs to completely test your class.
'''
Python version : 2.7
Python program to create and test class Scores
'''
class Scores:
# class variable
NO_VALUE = -1
#constructor to create a list of length maxSize and sets the initial value of each variable to NO_VALUE.
def __init__(self, maxSize):
self.lst = [Scores.NO_VALUE]*maxSize
# function to return a single value from the array. The argument is the user’s index of the item to return.
def getScore(self,index):
#check if index is valid
if index >=0 and index < len(self.lst):
return self.lst[index]
return Scores.NO_VALUE
# function to return the number of non-default scores stored in the list.
def getNumOfScores(self):
count = 0
for i in range(len(self.lst)):
if self.lst[i] != Scores.NO_VALUE:
count = count + 1
return count
# function to return the total of the non-default scores stored in the list.
def getTotalPoints(self):
total = 0
for i in range(len(self.lst)):
if self.lst[i] != Scores.NO_VALUE:
total = total + self.lst[i]
return total
# function to return the maximum value in the list.
def getMaxValue(self):
maxValue = Scores.NO_VALUE
for i in range(len(self.lst)):
if self.lst[i] > maxValue:
maxValue = self.lst[i]
return maxValue
# function to return the minimum, non-default value in the list.
def getMinValue(self):
minValue = Scores.NO_VALUE
for i in range(len(self.lst)):
if self.lst[i] != Scores.NO_VALUE:
if minValue == Scores.NO_VALUE:
minValue = self.lst[i]
elif self.lst[i] < minValue:
minValue = self.lst[i]
return minValue
# function to return the average of the non-default scores.
def getAverage(self):
if(self.getNumOfScores() > 0):
return float(self.getTotalPoints())/self.getNumOfScores()
return 0
# function to set the score at the given index
def setScore(self,index, score):
# check if index is valid
if index >=0 and index < len(self.lst):
# check if score is valid
if score >=0 and score <=200:
self.lst[index] = score
return True
else:
return False
else:
return False
# function to test the Scores class
def main():
score = Scores(20)
print(score.setScore(0,10))
print(score.setScore(1,-2))
print(score.setScore(1,201))
print(score.setScore(5,31))
print('Number of scores : %d' %(score.getNumOfScores()))
print('Score at 5 : %f' %(score.getScore(5)))
print('Total points : %f' %(score.getTotalPoints()))
print('Max Value : %f' %(score.getMaxValue()))
print('Max Value : %f' %(score.getMinValue()))
print('Average : %f' %(score.getAverage()))
#call the main function
main()
#end of program
Code Screenshot:



Output:

Using Python, Write a class named Scores. This data structure will store a collection of lab...
Write a Python program that asks the user to type in their three quiz scores (scores between 0 and 100) and displays two averages. The program should be written so one function gets the user to input a score, another function takes the three scores and returns the average of them. And another function takes the three scores and averages the two highest scores (in other words, drops the lowest). Each of these functions should do the computation and return...
Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...
Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to be...
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 toString method for the Scores class. It should print the Scores object as follows: [(EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) , (EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) ,(EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) , (EntryName, EntryScore)] GameEntry.java public class GameEntry { protected String name; // name of the person earning this score protected int score; // the score value /** Constructor to create a game entry */ public GameEntry(String n, int s) { name = n; score =...
Write a class named TestScores. The class constructor should accept an array test scores as its argument. The class should a method that returns the average of the test scores. If any test score is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate this with an array of five items. This is JAVA program.
PHYTHON NOT JAVA!!! need HELP ASAP!!! This program gets a series of test scores and # calculates the average of the scores with the # lowest score dropped. def main(): # Get the test scores from the user and store it in a variable called scores. # Get the total of the test scores and store it in a variable called total. # DONE - Get the lowest test score and store it in a variable called lowest....
in python Write a class named RetaiI_Item that holds data about an item in a retail store. The class should store the following data in attributes: • Item Number • Item Description • Units in Inventory • Price Create another class named Cash_Register that can be used with the Retail_Item class. The Cash_Register class should be able to internally keep a list of Retail_Item objects. The class should include the following methods: • A method named purchase_item that accepts a...
Look at this partial class definition, and then answer questions a - b below: Class Book Private String title Private String author Private String publisher Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant Public Module message() Display "I'm a plant." End Module...
Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...