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

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • I Need Help with this using Java Programming : Class name fname lname Class variable total...

    I Need Help with this using Java Programming : Class name fname lname Class variable total Number Constructor (no arguments) Constructor (takes two arguments, fname and lname) One getter method to return the fname and lname One setter method for fname and lname Inside Main: Create three objects with the following names Jill Doe John James Jack Smith When creating the first object (Should not be an anonymous object) use the argument-less constructor Then use the setter method to assign...

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

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

  • Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The...

    Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The BankAccount class declaration in file BankAccount.java is the blueprint of a BankAccount object. Check out the design of a BankAccount class. 1. In BankAccount.java class, all of the method stubs ( methods with a header but empty bodies ) are present to help you get started. Your task is to complete the method bodies. All comments in red in the diagram above indicates what...

  • Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and...

    Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and Bird 2.      A Bird class that is a descendant of Animal 3.      A Dog class that is a descendant of Animal 4.      A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: ·        one instance variable, a private String variable named   name ·        a single constructor that takes one argument, a String, used to set...

  • I need help with my code. It keeps getting this error: The assignment is: Create a...

    I need help with my code. It keeps getting this error: The assignment is: Create a class to represent a Food object. Use the description provided below in UML. Food name : String calories : int Food(String, int) // The only constructor. Food name and calories must be // specified setName(String) : void // Sets the name of the Food getName() : String // Returns the name of the Food setCalories(int) : void // Sets the calories of the Food...

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

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