Computer Science CS50 Lecture 1: SDA_LAB Final

36 views6 pages

Document Summary

A class diagram of pizza store application is shown below. Use factory method design pattern to create the following pizza store application. In cheese pizza, i called the tostring() method, that s why dough, sauce and toppings are shown, while in veggie pizza i called just the getname() method. You can call tostring() method with both veggie and cheese pizza. Step 1: abstract pizza class import java. util. arraylist; abstract public class pizza { Arraylist toppings = new arraylist(); public string getname() { return name; public void prepare() { System. out. println("\n preparing " + name); public void bake() { System. out. println(" baking " + name); public void cut() { System. out. println(" cutting " + name); public void box() { System. out. println(" boxing " + name); public string tostring() { Stringbuffer display = new stringbuffer(); display. append(" " + name + "\n"); display. append(dough + "\n"); display. append(sauce + "\n"); for (int i = 0; i < toppings. size(); i++) { display. append((string) toppings. get(i) + "\n"); return display. tostring();

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions