Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this last part is for better understanding.. Please i would like you to answer this for me in less than 2hours 30mins thanks in advance.

image text in transcribedimage text in transcribedimage text in transcribedthis last part is for better understanding..

Please i would like you to answer this for me in less than 2hours 30mins thanks in advance.

Home task: Goal: Practice Java Strategy Pattern Imagine the situation, where you have many children and they all want to get a candy (just 1). All children are different meaning that the ways they choose (using what principle) are also different. Let's call it "Children Strategy of choosing Candy". Your task is to implement this logic into Java code and test it in TestStrategy() class. Explanation: Follow this order of implementation to make your work easier Candy type: String +Candy(type: String) +getType(): String +toString(): String Candy class (What children will be choosing). Each Candy has: - Constructor Type : String (type might be whatever you choose : "Marshmallow", "Jelly Candy", "Caramel") getType() method which returns the type of Candy - toString() method which properly format Candy object representation > ChoosingCandyStrategy +chooseCandy(listOfCandies : List, childAge : int) : void ChoosingCandyStrategy Interface (The way children choose the candy). This interface has just 1 method: - chooseCandy(listOfCandies: List, childAge : int) o listOfCandies - Candy1, Candy2, Candy3] o childAge : int Therefore there are 3 different implementations of current interface Class CandyHaterStrategy() implements ChoosingCandyStrategy- - This strategy by getting the list of candy objects randomly returns any Candy (just 1 candy) not even considering the age of the child. Class ChooseOnlySugarFreeCandies Strategy() implements ChoosingCandyStrategy - Let's imagine that the length of Candy type (String) is actually the amount of the calories for current candy. Meaning that this strategy by getting the list of candies returns any Candy (just 1 candy) which type length is the shortest. If there are multiple such - return any satisfying this condition. Class MakeChoiceDepemdingOnAgeStrategy() implements ChoosingCandyStrategy- Child chooses candy which type length matches child's age. If there are no such - chooses randomly and return just 1 candy. Child age: int choosingCandyStrategy : ChoosingCandyStrategy +Child (age: int, choosingCandyStrategy : ChoosingCandyStrategy) +chooseCandy(List candies) : Candy Child class or the class where all of the magic is happening. Each Child has: Constructor -taking age and certain strategy for choosing candies - chooseCandy() method through which child chooses candy using strategy given. - toString() method which properly format Child object representation Write also TestStrategy() class and test your code functionality Highly recommended to distribute you classes and interfaces in packages as follows: v v v candy Candy child Child strategies CandyHaterStrategy ChooseOnlySugarFreeCandies Strategy ChoosingCandyStrategy MakeChoiceDependingOnAgeStrategy Main Good luck > ChoosingCandyStrategy +chooseCandy(listOfCandies : List, childAge : int) : void Home Task: ChooseOnlySugarFreeCandiesStrategy +choose Candy(listOfCandies : List, childAge : int) : Candy CandyHaterStrategy Child +choose Candy(listOfCandies : List, childAge : int): Candy age: int choosingCandyStrategy : ChoosingCandyStrategy MakeChoise DependingOnAgeStrategy +choose Candy(listOfCandies : List, childAge : int) : Candy +Child (age: int, choosingCandyStrategy : ChoosingCandyStrategy) +chooseCandy(List candies) : Candy +toString(): String Candy type: String +Candy(type: String) +getType(): String +toString(): String vbi candy Candy v bu child Child strategies CandyHaterStrategy ChooseOnlySugarFreeCandies Strategy ChoosingCandyStrategy MakeChoiceDependingOnAgeStrategy Main Home task: Goal: Practice Java Strategy Pattern Imagine the situation, where you have many children and they all want to get a candy (just 1). All children are different meaning that the ways they choose (using what principle) are also different. Let's call it "Children Strategy of choosing Candy". Your task is to implement this logic into Java code and test it in TestStrategy() class. Explanation: Follow this order of implementation to make your work easier Candy type: String +Candy(type: String) +getType(): String +toString(): String Candy class (What children will be choosing). Each Candy has: - Constructor Type : String (type might be whatever you choose : "Marshmallow", "Jelly Candy", "Caramel") getType() method which returns the type of Candy - toString() method which properly format Candy object representation > ChoosingCandyStrategy +chooseCandy(listOfCandies : List, childAge : int) : void ChoosingCandyStrategy Interface (The way children choose the candy). This interface has just 1 method: - chooseCandy(listOfCandies: List, childAge : int) o listOfCandies - Candy1, Candy2, Candy3] o childAge : int Therefore there are 3 different implementations of current interface Class CandyHaterStrategy() implements ChoosingCandyStrategy- - This strategy by getting the list of candy objects randomly returns any Candy (just 1 candy) not even considering the age of the child. Class ChooseOnlySugarFreeCandies Strategy() implements ChoosingCandyStrategy - Let's imagine that the length of Candy type (String) is actually the amount of the calories for current candy. Meaning that this strategy by getting the list of candies returns any Candy (just 1 candy) which type length is the shortest. If there are multiple such - return any satisfying this condition. Class MakeChoiceDepemdingOnAgeStrategy() implements ChoosingCandyStrategy- Child chooses candy which type length matches child's age. If there are no such - chooses randomly and return just 1 candy. Child age: int choosingCandyStrategy : ChoosingCandyStrategy +Child (age: int, choosingCandyStrategy : ChoosingCandyStrategy) +chooseCandy(List candies) : Candy Child class or the class where all of the magic is happening. Each Child has: Constructor -taking age and certain strategy for choosing candies - chooseCandy() method through which child chooses candy using strategy given. - toString() method which properly format Child object representation Write also TestStrategy() class and test your code functionality Highly recommended to distribute you classes and interfaces in packages as follows: v v v candy Candy child Child strategies CandyHaterStrategy ChooseOnlySugarFreeCandies Strategy ChoosingCandyStrategy MakeChoiceDependingOnAgeStrategy Main Good luck > ChoosingCandyStrategy +chooseCandy(listOfCandies : List, childAge : int) : void Home Task: ChooseOnlySugarFreeCandiesStrategy +choose Candy(listOfCandies : List, childAge : int) : Candy CandyHaterStrategy Child +choose Candy(listOfCandies : List, childAge : int): Candy age: int choosingCandyStrategy : ChoosingCandyStrategy MakeChoise DependingOnAgeStrategy +choose Candy(listOfCandies : List, childAge : int) : Candy +Child (age: int, choosingCandyStrategy : ChoosingCandyStrategy) +chooseCandy(List candies) : Candy +toString(): String Candy type: String +Candy(type: String) +getType(): String +toString(): String vbi candy Candy v bu child Child strategies CandyHaterStrategy ChooseOnlySugarFreeCandies Strategy ChoosingCandyStrategy MakeChoiceDependingOnAgeStrategy Main

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago

Question

*SHOW COMPLETE ANSWER IN SAME FORMAT*

Answered: 1 week ago

Question

Define the goals of persuasive speaking

Answered: 1 week ago