Question

Use MATLAB Write a Brownie class It should have two properties: an integer, "yield" which is...

Use MATLAB

Write a Brownie class

It should have two properties: an integer, "yield" which is how many brownies a batch produces, and a logical "chocchips", which true if the recipe uses chocolate chips and false if not.

Both properties should be given default values

Write two methods: a constructor function which uses the values passed to it (if any) or the default values if not; also overload the disp function so that the output is as shown in the following example:

>>mochab = Brownies(16,true)

mochab =

This recipe yields 16 brownies and has chocolate chips

>>bettyc = Brownies(20,false)

bettyc =

This recipe yields 20 brownies and does not have chocolate chips

>>disp(bettyc)

This recipe yields 20 brownies and does not have chocolate chips

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

%   MATLAB Program for brownies

classdef Brownies
    properties
        yield
        chocchips
    end
    methods
        function obj = Brownies(y,c)
            if nargin == 0
                obj.yield = 10;
                obj.chocchips = false;
            else
                obj.yield = y;
                obj.chocchips = c;
            end
        end
        function disp(obj)
            if obj.chocchips == true
                disp(['This recipe yields ' num2str(obj.yield) ' brownies and has chocolate chips']);
            else
                disp(['This recipe yields ' num2str(obj.yield) ' brownies and does not have chocolate chips']);
            end
        end
    end
end
Add a comment
Know the answer?
Add Answer to:
Use MATLAB Write a Brownie class It should have two properties: an integer, "yield" which is...
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
  • Write a class definition for a Rectangle. The data fields should be: • An integer for...

    Write a class definition for a Rectangle. The data fields should be: • An integer for the value of the width of the Rectangle • An integer for the value of the height of the Rectangle An integer for the value of the area of the Rectangle It must have: . A default constructor A constructor that has a parameters for width and height and assigns them to the member variables. • The class should have mutators for all of...

  • Write a class named HalfOpenCylinder that has two data members: a double for the height in inches and a double for the radius in inches. It should have a constructor that takes two parameters and uses...

    Write a class named HalfOpenCylinder that has two data members: a double for the height in inches and a double for the radius in inches. It should have a constructor that takes two parameters and uses them to initialize the data members. It should have a default constructor that initializes the height to 10 and the radius to 2. It should have a method named surfaceArea that returns the the surface area (in square inches) of a cylinder with that...

  • Write a class called Player that has four data members: a string for the player's name,...

    Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...

  • Exercise 1: Create a class Resource. The class should have: a) Two private variables status and w...

    C++C++ Exercise 1: Create a class Resource. The class should have: a) Two private variables status and writeTo representing integer value either 0 or 1. b) One default constructor that initializes the status and writeTo to zero. c) One single parameterized constructor to initialize the writeTo variable. d) Two constant accessor functions per class that return the values of status e) Two mutator functions per class that set the values of status and writeTo One output (member) function that outputs...

  • C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named month...

    C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...

  • The function should have a class name CPizza that will have three constructors (default, type, and...

    The function should have a class name CPizza that will have three constructors (default, type, and copyl, public functions to use and implement are noted for you in the starter kit, and private member variables (all which are allocated dynamically). The private member variables include the three different sizes of pizza (Large, Medium, and Small), cost, a bool delivery, name, and delivery fee. The prices of the pizzas' are $20. $15, and $10 for large, medium, and small respectively. The...

  • Write a class named Month. The class should have an int field named monthNumber that holds...

    Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...

  • MUST BE DONE IN MATLAB! Test inputs Write a function called CheckInputs which checks if three...

    MUST BE DONE IN MATLAB! Test inputs Write a function called CheckInputs which checks if three inputs parameters are the correct data types. The first second, and third input variables must be a string, numeric, and logical data type, respectively. The output of Checkinputs should be a logical row array, errorCode with 4 values If all the tests pass, then errorCode should consist of only false values. If the 1st input parameter is not a string, the 1st array element...

  • IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and...

    IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has two parameters to allow...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

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