Question: Python Program 1. Most teachers assign various graded activities for their students to complete. A graded activity can be given a numeric score such as

Python Program

1. Most teachers assign various graded activities for their students to complete. A graded activity can be given a numeric score such as 70, 85, 90, and so on, and a letter grade such as A, B, C, D, or F. The GradedActivity class below is designed to hold the numeric score of a graded activity. The setScore method sets a numeric score, and the getScore method returns the numeric score. The getGrade method returns the letter grade that corresponds to the numeric score.

Class GradedActivity

// The score field holds a numeric score.

Private Real score

// Mutator

Public Module setScore(Real s)

Set score = s

End Module

// Accessor

Public Function Real getScore()

Return score

End Function

// getGrade method

Public Function String getGrade()

// Local variable to hold a grade.

Declare String grade

// Determine the grade.

If score >= 90 Then

Set grade = "A"

Else If score >= 80 Then

Set grade = "B"

Else If score >= 70 Then

Set grade = "C"

Else If score >= 60 Then

Set grade = "D"

Else

Set grade = "F"

End If

// Return the grade.

Return grade

End Function

End Class

Write the GradedActivity class and the main() method below in Python. Run the program which will create an object from the GradedActivity class. Copy a screenshot of your Python program and output window and paste into your answer document.

Module main()

// A variable to hold a test score.

Declare Real testScore

// A class variable to reference a

// GradedActivity object.

Declare GradedActivity test

// Create a GradedActivity object.

Set test = New GradedActivity()

// Get a test score from the user.

Display "Enter a numeric test score."

Input testScore

// Store the test score in the object.

test.setScore(testScore)

// Display the grade for the object.

Display "The grade for that test is ",

test.getGrade()

End Module

2. Extend the GradedActivity class to create a new class FinalTest. Add the number of questions on an Test and the number missed. The class will calculate how many points each question is worth (out of Test score of 100) and calculate the score. Create the main() module to create a FinalTest object. Copy a screenshot of your Python program and output window and paste into your answer document.

Class FinalTest Extends GradedActivity

// Fields

Private Integer numQuestions

Private Real pointsEach

Private Integer numMissed

// The constructor sets the number of

// questions on the Test and the number

// of questions missed.

Public Module FinalTest(Integer questions,

Integer missed)

// Local variable to hold the numeric score.

Declare Real numericScore

// Set the numQuestions and numMissed fields.

Set numQuestions = questions

Set numMissed = missed

// Calculate the points for each question

// and the numeric score for this Test.

Set pointsEach = 100.0 / questions

Set numericScore = 100.0 - (missed * pointsEach)

// Call the inherited setScore method to

// set the numeric score.

Call setScore(numericScore)

End Module

// Accessors

Public Function Real getPointsEach()

Return pointsEach

End Function

Public Function Integer getNumMissed()

Return numMissed

End Function

End Class

The constructor for FinalTest may be tricky for you, so here is the Python code.

def __init__(self, questions, missed):

numericScore = 0.0

self.numQuestions = questions

self.numMissed = missed

self.pointsEach = 100.0 / questions

numericScore = 100.0 - (missed * self.pointsEach)

GradedActivity.setScore(self, numericScore)

Module main()

// Variables to hold user input.

Declare Integer questions, missed

// Class variable to reference a FinalTest object.

Declare FinalTest Test

// Prompt the user for the number of questions

// on the Test.

Display "Enter the number of questions on the Test."

Input questions

// Prompt the user for the number of questions

// missed by the student.

Display "Enter the number of questions that the ",

"student missed."

Input missed

// Create a FinalTest object.

Set Test = New FinalTest(questions, missed)

// Display the test results.

Display "Each question on the Test counts ",

Test.getPointsEach(), " points."

Display "The Test score is ", Test.getScore()

Display "The Test grade is ", Test.getGrade()

End Module

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!