Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Each question needs a screenshot of the result and the code. insert appropriate amount of comments in the code. Exercise-1: Plant class. Define a class
Each question needs a screenshot of the result and the code. insert appropriate amount of comments in the code. Exercise-1: Plant class. Define a class Plant that satisfies the spec below. Hints A. For this problem, provide an implementation for the Plant spec below, and test it using the example calls provided B. Although the constructor is described in the spec (and called) using the name Plant), the internal name for a class's constructor is_init__(). (There are two underscores before and to underscores after init.) C. A "zeroeth" argument self should be included with the constructor and each method. For example, the spec shows two arguments for the constructor, but__init_() should be defined using three arguments: def-init-(self, species, mass): D. Likewise, the spec shows 0 arguments for the method getSpecies(), but that doesn't count self: def getSpecies(self): return self.species E. This "zeroeth" argument self must appear first in an argument list Plant class Represents selected information about a plant. State variables A.name - String, common name for the plant B.mass Positive float, the biomass of the plant, in kilograms Constructor Plant 2 arguments: A string representing a plant's common name, and a positive float representing the plant's initial biomass. State change: A new object of type Plant is created. The state variable name is assigned the value arg1, and the state variable mass is assigned the value arg2 Return: That newly created Plant object. Methods getName No arguments. Return: String, the name for this plant getMass No arguments. Return: Float, the current biomass for this plant setMass One argument: Positive float State change: The state variable mass is assigned the value arg1 Return: Positive float, the new value of the state variable mass Example calls: tree Plant(red oak, 1042) flower Plant(rose', 2.7) tree.getName() --> 'red oak flower.setMass(2.85) flower.getMass() --> 2.85 Note: insert appropriate amount of comments in your program Exercise-2: Book class. Define a class Book that satisfies the spec belovw Hints For this problem, provide just an implementation as Account Class for the Book spec below, and test it using the example calls provided Book class A physical book State variables C.title - String, the title of a book D.author - String, the author of a book E.year - Positive integer, the year of publication of a book Constructor Book 3 arguments: Two strings and a positive integer representing a year State change: A new object of type Book is created. The value arg1 is assigned to the state variable title, the value arg2 is assigned to the state variable author, and the value arg3 is assigned to the state variable year. Return: That newly created Book object. Methods getTitle No arguments. Return: String, the value of the state variable title getAuthor No arguments. Return: String, the value of the state variable author getYear No arguments. Return: Positive integer, the value of the state variable year setYear One argument: Positive integer representing a year. State change: The state variable year is assigned the value arg1 Return: Positive integer, the new value of year. Example calls: book1 Book(War and Peace', Leo Tolstoy, 1869) book2 - Book(The Wealth of Nations', 'Adam Smith', 1778) book1.getTitle() --> 'War and Peace' book2.getAuthor() --> Adam Smith' book2.getYear() --> 1778 book2.setYear(1776) --> 1776 book2.getYear() --> 1776 Note: insert appropriate amount of comments in your program Exercise-3: MyCar class Represents selected information about a car. Class variables Attributes of a car Instance variables Car owner name, Make, Model MyCar arguments: car_owner_name, make, model State change: A new object of type Car is created. Values for the car's owner, make and model are assigned. (Instance variables) Return: That newly created Car object. Methods setlnformation arguments: attributes - year, body_style, color, vin_number, cylinders, etc State change: (changes class variables) The class's variables are changed Return: New values of class's variables (Clue: how can we use the class variables in setlnformation? Declare those as global.) DescribeCar No arguments. Return: All information about the car including class and instance variables Example calls: Altima-Car ("yinay", "nissan", "altima") Altima.setInformation ("2007", "red", "dsd232442.4244") print (Altima. DescribeCar ())
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started