class student_name:
    def __init__(self,student):
        self.student = student
    def student_name(self):
        print('Student Name: ', self.student)

class Majors:
    def __init__(self,name1,name2):
        self.name1 = name1
        self.name2 = name2
    def major(self):
        pass
    def major2(self):
        print('Majors: ',self.name1, self.name2)

class School:
    def __init__(self,school):
        self.school = school
    def school_name(self):
        print('School Name: ', self.school)
class Student_Track:
    def __init__(self, School, student_name, Majors):
        self.School = School
        self.student_name = student_name
        self.Majors = Majors
    def track (self):
        print( 'School Name: ', School,
               'Student Name: ', student_name,
               'Majors: ', Majors)

ob1 = student_name('bob')
ob1.student_name()
ob2 = Majors('l','l')
ob2.major2()
ob3 = School('o')
ob3.school_name()
ob4 = Student_Track(ob3.school_name,ob1,ob2)
ob4.track()

Design a class for a Student/Major tracking system. You may use stubs for the member methods. Include a Class Diagram.I get:

"School Name: <class 'main.School'> Student Name: <class 'main.student_name'> Majors: <class 'main.Majors'>"

instead of:

Student Name: bob
Majors: l l
School Name: o

in one line

The problem you are having is three-fold. First, you are using the same names (student_name, School, and Majors) for both classes, and for the parameters to the to Student_Track.__init__(). Second, you are using the names of the classes in your print statement, rather than names of the instance variables (which always bgine with self., remember). Thirs, you are attempting to print the objects directly, without defining a __str__() method for them.

While I have not tested this, I think tha the following will fix the problem:

class Student_Name:
    def __init__(self, student):
        self.student = student
    def __str__(self):
        return 'Student Name: {name}'.format(name=self.student)

class Majors:
    def __init__(self, major, minor):
        self.major = major
        self.minor = minor
    def __str__(self):
        return 'Majors: {0}, {1}'.format(self.major, self.minor)

class School:
    def __init__(self,school):
        self.school = school
    def __str__(self):
        return 'School Name: {0}'.format(self.school)
class Student_Track:
    def __init__(self, school, student,  majors):
        self.school = school
        self.student = student
        self.majors = majors
    def __str__(self):
        return '{school},\n{student}\n{majors}\n'.format(
                                                         school=self.school,
                                                         student=self.student,
                                                         majors=self.majors)

ob1 = Student_Name('bob')
print(ob1)
ob2 = Majors('l','l')
print(ob2)
ob3 = School('o')
print(ob3)
ob4 = Student_Track(ob3,ob1,ob2)
print(ob4)

Thanks. Looks like I need more practice with classes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.