In need of Project Assistance

+2 Zach Barnes · April 27, 2015
Hey guys so I am having an issue with my last project in my first CS class in college. It covers object oriented programming, and my instructor did not explain it very well in my opinion. I'll first post the basic instructions given, and then I'll post my code along with the error I'm receiving so far. 


I. Part 1: supply a constructor that can construct which initializes the instance variables of CS120Test class. Hint, the constructor would initialize the default studentName= "CS120" ; studentID= "800-80-8000"; totalTestscore=0; maxTestScore=0 


II. Part2: Create 9 methods (public interface).
(1). Create a method called setName(), which sets the name of the student.
(2). Create a method called setID(), which sets the ID of the student. 
(3). Create a method called getName(), which gets the name of the student. Hint: return the name of the student.
(4). Create a method called getID(), which gets the ID of the student. Hint: return the ID of the student. 
(5). Create a method called addTest(), which adds a test score to the student's total CS120Test score.
(6). Create a method called getTotalScore(), which gets the total score for all Tests. Hint: return a student's total test score. 
(7). Create a method called getAverageScore(), which gets the average score for a student. Hint: return the average score. 
(8). Create a method called getMaxTestScore (), which gets the maximum Test score for a student. Hint: return the maximum Test score. 
(9). Create a method called getLetterGrade(), which gets the letter grade (for instance, A, A-, B+, etc.). Hint: return the letter grade for a student. 


And then from there I use an outside main() function and use these methods from the class.

So here is my code so far: 

class CS120Test:
  def __init__(self):
    studentName = "The default student name is: CS120"
    self.setName()
    studentID = "The default student ID is: 800-80-8000"
    self.setID()
    totalTestScore = 0
    maxTestScore = 0
  
  def setName(self):
    newName = requestString("Please enter student name:")
    self.studentName = newName
  
  def setID(self):
    newStudentID = requestString("Please enter student ID:")
    self.studentID = newStudentID
  
  def getName(self):
    return self.newName
  
  def getID(self):
    return self.newStudentID
  
def main():
  test = CS120Test()
  test.getName()
  test.getID()

The error was:'instance' object has no attribute 'newName'
Attribute not found.
You are trying to access a part of the object that doesn't exist.

I hope you guys can help, because I've been looking at it for a while now and I cannot figure this out. Thanks in advance!

Post a Reply

Replies

Oldest  Newest  Rating
0 tyler anderson · April 27, 2015
The problem so far of what I can see is that in your

def getName(self):
    return self.newName
 
  def getID(self):
    return self.newStudentID

is that you need to change your returns  to return self.studentName and return self.studentID.
  • 1

Python

107,261 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator