Question

"Write a class that represents a course at Juniata. A course has a department (ex. CS,...

"Write a class that represents a course at Juniata. A course has a department (ex. CS, IT, PY, BI), a number (ex. 110, 240, 356), a name (ex. Computer Science 1), and a number of credits.

Write a test driver just to make sure your class works. I recommend just instantiating a few courses and displaying them using the __str__ method. If you want to go a little farther, store a few courses in a list and loop through them to display. You will need this class to use in the next program as we are going to extend it to do more.

Submit your .py file through Moodle."

some examples of classes would be

BI-110 Introduction to Biology

CH-342 Advanced Biochemistry

BI-310 General Ecology

EN-292 Crossing the Border

Please help me figure out how to set up this code using python, thanks!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code :

The code in the above screenshot:

class Juniata:
   ''' Class for course details '''
   def __init__(self, code,name,credits) :
       self.code = code
       self.name = name
       self.credits = credits
  
   def __str__(self) :
       return '(DETAILS : %s %s )' %(self.code,self.name)

class TestJuniata :
''' instantiate objects and print '''
   biology = Juniata('BI-110','Introduction to Biology',30)
   biochem = Juniata('CH-342','Advanced Biochemistry',25)
   ecology = Juniata('BI-310','General Ecology',15)
   english = Juniata('EN-292','Crossing the Border',10)
  
   course_list = [ biology,biochem,ecology,english ]
  
   for course in course_list :
       print(course)

Here , I have declared a class Juniata. The course details  are initialized using __init__ method. The __str__ method is used to return the string format. In the testJuniata class, I have instantiated the courses and its values, stored them in a list and printed. This is the output I got:

Hope this helps.

Add a comment
Know the answer?
Add Answer to:
"Write a class that represents a course at Juniata. A course has a department (ex. CS,...
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
  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • just write the answers in a sentences. No need to explain them. THE CASE OF SEAMUS...

    just write the answers in a sentences. No need to explain them. THE CASE OF SEAMUS Seamus was born to an Irish-American family that was upper class. His mother was a nurse; his father was an up-and-coming lawyer who was already making six figures in the middle 1970’s. Seamus grew up in a beautiful house with his brother in a predominantly white neighborhood. His family also occasionally took in Seamus’s friends who were having hard times. For example, one friend...

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

  • And there was a buy-sell arrangement which laid out the conditions under which either shareholder could...

    And there was a buy-sell arrangement which laid out the conditions under which either shareholder could buy out the other. Paul knew that this offer would strengthen his financial picture…but did he really want a partner?It was going to be a long night. read the case study above and answer this question what would you do if you were Paul with regards to financing, and why? ntroductloh Paul McTaggart sat at his desk. Behind him, the computer screen flickered with...

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