Question

Each question needs a screenshot of the result and the code. insert appropriate amount of comments in the code. Exercise-1: PgetMass No arguments. Return: Float, the current biomass for this plant setMass One argument: Positive float State change: ThMethods getTitle No arguments. Return: String, the value of the state variable title getAuthor No arguments. Return: String,MyCar arguments: car_owner_name, make, model State change: A new object of type Car is created. Values for the cars owner, m

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

Exercise 1

class Plant():

    def __init__(self,species,mass):
        self.species=species
        self.biomass=mass

    def getSpecies(self):
        return self.species

    def getMass(self):
        return self.biomass

    def setMass(self,mass):
        self.biomass=mass
        
    def getName(self):
        return self.species

tree=Plant('red oak',1042)
flower=Plant('rose',2.7)
print(tree.getName())
flower.setMass(2.85)
print(flower.getMass())

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

Exercise 2

class Book():
    def __init__(self,title,author,year):
        self.title=title
        self.author=author
        self.year=year
    def getTitle(self):
        return self.title
    def getAuthor(self):
        return self.author
    def getYear(self):
        return self.year
    def setYear(self,year):
        self.year=year

book1=Book('War and Peace','Leo Tolstoy',1869)
print(book1.getTitle())
print(book1.getAuthor())
print(book1.getYear())
book1.setYear(1778)
print(book1.getYear())

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

Exercise 3

class MyCar():
    year = 0
    color = ''
    vin_number = 0

    def __init__(self, owner, make, model):
        self.owner_name = owner
        self.make = make
        self.model = model

    def setInformation(self, year, color, vin):
        MyCar.year = year
        MyCar.color = color
        MyCar.vin_number = vin

    def DescribeCar(self):
        return 'Owner: ' + self.owner_name + ', Make: ' + self.make + ', Model: ' + \
               self.model +', Year:'+ str(MyCar.year) + ", Color: " + MyCar.color + ", " + 'vin #: ' + str(MyCar.vin_number)


Altima = MyCar("vinay", "nissan", "altima")
Altima.setInformation("2007", "red", "dsd2324424244")
print(Altima.DescribeCar())

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

thank you so much ! and please need a thumbs up : )

Add a comment
Know the answer?
Add Answer to:
Each question needs a screenshot of the result and the code. insert appropriate amount of comments...
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
  • Please help with a source code for C++ and also need screenshot of output: Step 1:...

    Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int....

    Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int. There is also an attribute of the class, points, which does not have a corresponding instance variable. Also note the constructor and methods of the class and what they do. TournamentAdmin class code: public class RankAdmin {    /**     * Constructor for objects of class...

  • Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; //...

    Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

  • (C++)This is the problem that I'm supposed to write a program for: This is the layout...

    (C++)This is the problem that I'm supposed to write a program for: This is the layout that we are supposed to fill out for the project: If anything is unclear, comment and I'll try to clarify. Thank you! Objective Reading Dala Files Project This is a variation of ng challenge 133 de Write a class named Car that has the following pelvate member variables. model Year An ie car's uodd year. make A string that bolds the make of the...

  • Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete...

    Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete the exercise. Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. 1. Write a Point class. The Point class should be written as an abstract data type. 2. Include the following instance variables: a. an integer representing the x coordinate b. an integer representing the y coordinate c. The instance variables in your program should only...

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