Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Assume that you have opened a modern Icecream Bar' in front of the NSU main gate. In your Icecream Bar, different flavors of Ice

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

1. Assume that you have opened a modern Icecream Bar' in front of the NSU main gate. In your Icecream Bar, different flavors of Ice cream are available along with a range of choices of toppings. Customers can have any flavors with their choice of toppings. You want to build an App for customers to order their flavor and choose toppings. The App should calculate the price according to the ice cream flavor and toppings. Each flavor and toppings have a different unit cost. Initially, you have designed the following class diagram for the App mentioned above. Icecream -name: String - hasCandy:boolean - has Sprinkles:boolean - hasCaramelsauce: boolean + Icecream (...) + getPrice (): double + getHasCandy (): boolean + getHas Sprinkles(): boolean + getHasCaramel Sauce (): boolean Chocolatelcecream Vanillalcecream +getPrice (): double +getPrice (): double However, this design has the following problems. Price changes in toppings will lead to alternation in the existing code of getPrice(). New toppings will force adding new variables and methods in the Icecream class and changing calculation accordingly. Some toppings may not be appropriate for some ice cream flavors, yet the subclass inherits them. Answer the following questions. a) Apply the Decorator design pattern to solve the problems mentioned above. After applying the Decorator design pattern, draw the class diagram and justify your answer. (20 points) 5. Write unit testing code for the following MyStack class using JUnit5 Framework. Make sure all the methods are tested and the timeouts of all methods' call are at most 100 milliseconds. public class MyStack { private int SIZE; private int items[]; private int top; public MyStack(int size) { SIZE = size; items = new int [SIZE]; top = 0; } } boolean isFull() { if(top==SIZE) return true; return false; } } boolean isEmpty() { if(top==0) return true; return false; } void push(int key) { if(isFull()) System.out.println("Stack Full."); else items [top++] = key; } void pop() { if(isEmpty()) System.out.println("Stack Empty."); else top--; } int peek() { return items [top-1]; } } // MyStack class ends

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions