Implement the dynamic linkage pattern specified

Assignment Help JAVA Programming
Reference no: EM131417006

Use Java to implement the Dynamic Linkage pattern specified below.

You need to implement all of the classes as defined below substituting the yellow classes with your own class definitions.

For example, you need to define your own FoodProcessorProgram, such as Salsa and PotatoSalad in place of YourRecipeA and YourRecipeB.

2143_Figure.jpg


FoodProcessorEnvironmentIF and AbstractFoodProcessorProgram are the same as specified in the book.

AbstractFoodProcessorEnvironment and ChocolateMilk are provided below.

Your Client/main program needs to

• ask user to pick a directory to find FoodProcessorProgram (Recipe) which will be the classPath
Ex. User selects ./bin as the class path directory, your program creates a File object with "./bin" as parameter, then you call toURI() then call toURL() to get the URL representation of the user selected directory. The selected URL representation of classPath will be used as a parameter to create user selected environment.
You can use either JFileChooser to let user select a directory or use command prompt.

• ask user to pick one of your FoodProcessorEnvironments to use
Ex. User selects YourFoodProcessorEnvironmentA, your program creates an instance of YourFoodProcessorEnvironmentA. Or you can create both instances at the beginning then assign the selected on to the current environment.

• ask user to pick one of FoodProcessorPrograms(Recipes) to use
Your program needs to show all the .class files under the user selected directory (classPath) and allows user to select one of the .class files as the program to be run

(started). Ex. User selects ChocolateMilk which is a String that will be the parameter passed to run() on user selected environment.

• call run() on the user selected environment with user selected
FoodProcessorProgram (Recipe) as parameter.

Class AbstractFoodProcessorEnvironment -

import java.net.URL;
import java.net.URLClassLoader;

/**
* class AbstractFoodProcessorEnvironment
* implements FoodProceesorEnvironmentIF which contains methods called by Food processor programs
* defines instance variable URL[] classPath which contains the classPaths
* that will be searched to load Food processor programs
* defines void run(String programName) which will be called by an initialization program
* which wants to use an instance of this environment to find the named programName in classPath
* using URLClassLoader to load a class of programName then creates a new instance of program
*/

public abstract class AbstractFoodProcessorEnvironment implements FoodProcessorEnvironmentIF { private URL[] classPath;
public AbstractFoodProcessorEnvironment(URL cp){
classPath = new URL[]{cp};
}

/**
* Run the named program.
* @param programName the name of the program to run.
*
* Creates an URLClassLoader based on the specified classPath
* the class loader loads the class based on the programName
* the program class then creates a new instance of the program
*
* Sets this environment to be the newly created program instance's environment,
*
* Calls start() on the program
*/
abstract void run(String programName); void display(String s) {
System.out.println("Displaying the program name - "+s);
} // display(String)

URL[] getURL(){
return classPath;
}
} // class AbstractFoodProcessorEnvironment

Class ChocolateMilk -
public class ChocolateMilk
extends AbstractFoodProcessorProgram {
/**
* Return the name of this food processing program object.
*/
public String getName() { return "ChocolateMilk"; }

/**
* A call to this method tells a food processing program to start
* doing whatever it is supposed to be doing.
*/
public void start() { double milkWeight; double cocoWeight;

System.out.println("\n--------- Starting Recipe ---------");

System.out.println("Place milk on the scale ..."); milkWeight = getEnvironment().weigh(); System.out.println("Milk weight is "+milkWeight);
System.out.println("Remove milk from scale and place it in the mixer ...");

System.out.println("Place Coco powder on the scale ..."); cocoWeight = getEnvironment().weigh(); System.out.println("Coco weight is "+cocoWeight);
System.out.println("Remove Coco powder from scale and place it in the mixer ..."); getEnvironment().mix(4);
System.out.println("--------- End Recipe ---------\n");

} // start()
//...
} // class ChocolateMilk - a ConcreteFoodProcessorProgram

A sample output below with user selected directory as ./bin and ChocolateMilk as selected FoodProcessorProgram.

145_Figure1.jpg

You need to include a header section for each of your Java program.

The header basically is a comment section at the beginning of each of your Java file about the name of file, what the file is about, the creator, when was the file created, last modified for what reasons.

Verified Expert

This program code is an implementation of Dynamic Linkage Pattern in Java which allows the program to load a class, dynamically, upon request. This code presented here creates the linkage pattern between a Food Processor Environment, that performs functions like- slicing, mixing of ingredients to prepare the food and Food Processor Program like Chocolate Milk, Orange Juice. For this, the user is given a choice to choose a directory where all .class file pertaining to Food Processor program should reside. Thus the program compiles all the Food Processor Program .java files in that specific directory and further lets the user choose to choose a particular food processor environment and a food processor program name from the listed .class files in the directory. Further, the chosen environment runs the recipe of the program name that user chose.

Reference no: EM131417006

Questions Cloud

Global creative organizations using the criteria description : Identify and discuss several global creative organizations using the criteria descriptions in Ch. 11 of Mastering Leadership. Include the strategic opportunities for change the organizations have. Two substantive comments (minimum 350 words each)
Give numerical values for the mean and standard deviation : Find the standardized statistic for x‾ = 97.- Find the standardized statistic for x‾ = 105.- Give numerical values for the mean and standard deviation of the sampling distribution of x‾.
Describe how much funding will be required for the venture : Describe how much funding will be required for the venture and be sure to address how funding will be utilized. Discuss the type of pro forma projections to be used to increase borrowing capacity credibility.
Design a communication plan for the project : Construct a project charter to revamp the compensation and benefits package. Design a communication plan for the project. Define the scope of the project
Implement the dynamic linkage pattern specified : Implement the Dynamic Linkage pattern specified - implement all of the classes as defined below substituting the yellow classes with your own class definitions - The header basically is a comment section at the beginning of each of your Java file ab..
Approach described in question work every time : 1. Describe the thought process you use to decide if a compound is ionic or molecular, from its formula. 2. Classify the following as ionic or molecular: NaCl, NCl3, NH3, NH4OH, CH3OH, HCN. Did your initial approach described in question 6 work eve..
Which of the two distributions would be more spread out : In each of the following situations, which of the two distributions would be more spread out?- Standard normal distribution or t-distribution with df = 10.
Discuss the progress of the company ethical issue : From Part I of this discussion, imagine that you are the marketing manager hired to keep the public informed of the progress of the company's ethical issue
Why do we want to know answer to the question we are asking : Why do we want to know the answer to the question we are asking? Finally, it should end the hypothesis from your Week Two experiment, and the reasoning behind your hypothesis.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd