Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provide java code for the cookbook Should be all in one file - Create a class named RecipeFactory - public static Recipe makeRecipe(String recipeType, String

Provide java code for the cookbook

Should be all in one file

- Create a class named RecipeFactory - public static Recipe makeRecipe(String recipeType, String recipeName, HashMapingredients) -public static final String (DESSERT and DINNER) - "Dessert" and "Dinner"

-Create an abstract class named Recipe - protected HashMapingredients - Key: ingredient name - Value: ingredient amount - protected String name - HashMap getIngredients() - Can implement here - String getName() - Can implement here

- Extend your abstract class in DessertRecipe and DinnerRecipe - Override toString - Expected output on next slide - Use the StringBuilder class - Implement a constructor that takes String name and HashMap ingredients. - Warning: assigning HashMap from constructor and memory - new HashMap(hashMap)

Hint: use to add a newline and \t to add the tab Since this will go through an autograder, you must exactly match the formatting (do not add an extra to the very end)

- Create a singleton class named Cookbook - private Cookbook() { } - private ArrayList recipes - void addRecipe(Recipe r) - void clearRecipes() - ArrayList getRecipes() - Cookbook getInstance() ----------------------------------------------------------------------------------------------------------------------------- - Create a file named FinalProject.java - This file will contain all your code when you submit your completed project - Both methods you work on this week should be in the public FinalProject class - You can add main to this class to help you test your code

- Define a static method called connectToServer that takes as input a String ipAddress and integer port. - Create a socket (client) and connect to the input port - This will be your connection to the RecipeServer - Make sure your socket is continually reading in messages from the socket - Pseudocode: while (input from socket != null) print out input from socket - Use an InputStreamReader wrapped in a BufferedReader

As you receive recipes over the socket, you should create the appropriate Recipe object (using the factory) and add them to the Cookbook list.

- Test your code with the RecipeServer code. You can use 8765 as your testing port. - Note: You will have to run the server and your code separately. You will need to test it locally. - You should be able to continually send messages from the server and receive them from your client. - Do not change the server code this version will be used to test your program.

------------------------------------------------------------------------------------------------------------------------------ - If you run the following code from main in FinalProject.java - FinalProject.connectToServer(8765); - System.out.println(Hello); Hello will never be printed Why?

- Update your connectToServer method - Instead of performing the connection and reading on the main thread, perform the work in a new thread. - To test your changes, run your code from the previous slide. Hello should be print out immediately. - Also make sure you are still able to receive messages continually from RecipeServer. ------------------------------------------------------------------------------------------------------------------------------ - Write the following methods in your FinalProject class. - public static void serializeRecipe(Recipe r, String path) - Serialize the given recipe to the path - You should only store the following fields - name - ingredients - You can serialize the object as a Recipe - No need to check which child class was input

- public static Recipe deserializeRecipe(String path) - Deserialize a Recipe at the given path - Cast the returned object to Recipe - Note: Even if you treat it as a Recipe, the data from the child class you used will be saved - i.e. no need to cast it to the child class

- Place all your classes in your FinalProject.java file. - Test to make sure all the code still works. - Here is how testing will be done: - A server socket will await your connection - Recipe strings will be sent over the socket - Your Cookbook should be updated after each recipe - All of your methods will be tested, including your RecipeFactory and Cookbook methods.

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions