Question: Create a class for Donuts following the UML (unified modelling language) below. It should have instance variables(private) kind , count. Then write two constructors: a
Create a class for Donuts following the UML (unified modelling language) below. It should have instance variables(private) kind, count. Then write two constructors: a default constructor(), i.e. no parameters, and a value constructor() with two parameters for the two instance variables kind and count.
Then one method eat() to say "Yum! Yum! This is a good donut!".
Finally, the toString() method and the equals() method.
For the lab create a second class Lab11Donuts.java with the main() to show your favorite donut for a baker's dozen (13 count) and another donut for me, Mr. R. I would like a "blueberry donut" please! :-)
Donut dDonut0 = new Donut( "...", 13 ); // your favorite donut System.out.println( dDonut0.toString() ); // memory dump dDonut0.eat(); // "Yum! Yum! This is a good donut!" Donut dDonut1 = new Donut( "blueberry donut", 1 ); System.out.println( dDonut1.toString() ); dDonut1.eat(); // is your donut the same as Mr. R's donut? true or false System.out.println( dDonut0.equals( dDonut1 ) );
| Donut |
-kind : String -count : int |
+Donut() +Donut( String, int ) +eat() : void +toString(): String +equals( Donut ) : boolean |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
