Question

Question 3. [16 MARKS] Part (a) [4 MARKS Complete the Car class below. class Car: A Car class. we Attributes plate: this car
0 0
Add a comment Improve this question Transcribed image text
Answer #1

check out the solution and do comment for any queries.

-------------------------------------------------------

class Car:
plate: str
odometer: int
  
# constructor
def __init__(self, plate: str) -> None:
# assign class attribute with the given plate
self.plate = plate
# assign 0 to class attribute using self
self.odometer = 0

c1 = Car("AAA111") # object creation with parameterized constructor
print(c1.plate) # print plate value
print(c1.odometer) # print odometer value

-------------------

Code and result :

1* class Car: plate: str odometer: int # constructor def _init_(self, plate: str) -> None : # assign class attribute with the

--------------------------------------------------------------------------------------------------------------------------------------

code :

class Car:
plate: str
odometer: int
  
# constructor
def __init__(self, plate: str) -> None:
# assign class attribute with the given plate
self.plate = plate
# assign 0 to class attribute using self
self.odometer = 0
  
# drive method - updates odometer value
# method takes distance parameter with data type 'int'
def drive(self, distance: int) -> int:
if(distance > 0): # if value is positive then modify odometer value
# adds given distance value to class attribute 'odometer'
self.odometer = self.odometer + distance
  
return self.odometer
  

c = Car("AAA111") # object creation with parameterized constructor
print(c.drive(10)) # print odometer value
print(c.drive(33)) # method call using object and print the returned value
print(c.drive(-12))

------------------------------------

code :

1- class Car: plate: str odometer: int 4 # constructor def _init_(self, plate: str) -> None: # assign class attribute with th

Output :

Result executed in 1.133 sec(s) 10 43 43

Add a comment
Know the answer?
Add Answer to:
Question 3. [16 MARKS] Part (a) [4 MARKS Complete the Car class below. class Car: A...
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
  • Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Ini...

    Must be in Python 3 exercise_2.py # Define the Student class class Student():    # Initialize the object properties def __init__(self, id, name, mark): # TODO # Print the object as an string def __str__(self): return ' - {}, {}, {}'.format(self.id, self.name, self.mark) # Check if the mark of the input student is greater than the student object # The output is either True or False def is_greater_than(self, another_student): # TODO # Sort the student_list # The output is the sorted...

  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • Task 2: SecretWord class: Download and save a copy of LinkedLists.py (found at the bottom of...

    Task 2: SecretWord class: Download and save a copy of LinkedLists.py (found at the bottom of this assignment page on eClass). In this file, you have been given the complete code for a LinkedList class. Familiarize yourself with this class, noticing that it uses the Node class from Task 1 and is almost identical to the SLinkedList class given in the lectures. However, it also has a complete insert(pos, item) method (which should be similar to the insert method you...

  • need java code for this question Question 2 (15 marks) (a) Does the following class successfully...

    need java code for this question Question 2 (15 marks) (a) Does the following class successfully compile? Explain your answer. public class MyClass public static void main(String arge) if(Integer.parseInt(args[0]) < 0) throw new RuntimeException(); C { 1 } If the class does compile, describe what will happen when we run it with command: java MyClass -10 (5 marks) (b) Write a complete definition of the method with the heading given below: public static double calculate insurance Premium double carValue, int...

  • In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game...

    In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.   For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”. Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the...

  • 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...

  • python 3 question Project Description Electronic gradebooks are used by instructors to store grades on individual assignments and to calculate students’ overall grades. Perhaps your instructor uses gr...

    python 3 question Project Description Electronic gradebooks are used by instructors to store grades on individual assignments and to calculate students’ overall grades. Perhaps your instructor uses gradebook software to keep track of your grades. Some instructors like to calculate grades based on what is sometimes called a “total points” system. This is the simplest way to calculate grades. A student’s grade is the sum of the points earned on all assignments divided by the sum of the points available...

  • Complete Task 4, 5, 6 Instructions Page 3 of 3 query.sql 1 -- Write your query...

    Complete Task 4, 5, 6 Instructions Page 3 of 3 query.sql 1 -- Write your query below and then click "Run Query" to execute it. To save multiple queries, click the "+" icon above. VE Task 4: </> The InstantRide User Satisfaction team is a core team for Instant Ride, and they focus on increasing the customer satisfaction. They want to learn the travel time for each ride in the system. You need to return the USER_ID, and the TRAVEL_TIME...

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
Active Questions
ADVERTISEMENT