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

  Do you think that overall performance of app is use program

Do you think that overall performance of an app is one of the main reasons people wouldn't use the program? If you were designing an app what might be some of the things which could cause performance to increase?

  Write a custom java exception class named badarrayexception

A constructor taking a String parameter (the exception message) that must be passed to the parent Exception(String) constructor.

  Define javascript and servlet

The web site must be built using one of these techniques. JavaScript and servlet

  Java application to permit user to enter ten numbers

Write down Java application which permits a user to enter 10 numbers (double precision) into the array and then sorts and displays numbers from lowest to highest.

  Create javascript program to find gross pay for employees

Create JavaScript program which will find out the gross pay for each of three employees. Company pays "straight time" for first 40 hours worked by each employee and pays "time and a half".

  Calculate the maximum data rate in mb/second

b)How much cylinder skew is needed for an Oceangate disk operating at 20,000 rpm(new series for the Christmas promotions) which has a seek time of 0.5 milliseconds? This disk has 800 sectors of 512 bytes each on each track.

  Create a java gui application using netbeans

Create a Java GUI application using Netbeans that allows the user to enter the number of hours spent in each activity and then calculates the number of pounds lost.

  Find the errors in the javascript code

I get this error when running the Java Script above: JS Error: TypeError: Object # has no method 'error'

  Compare the readability and writability of for loop in java

Search the internet about the properties of the for loop in Ada, compare the readability, writability and reliability of the for loop in Ada and Java. Explain your answer

  Prepare a polynomial-time algorithm

Write a polynomial-time algorithm that, given an initial configuration (P_1, P_2, ..., P_k), decides if it is a winning configuration - Prepare a polynomial-time algorithm that decides if it is a winning configuration.

  Implement 4 sorting algorithms in a java "sort" class.

Implement 4 sorting algorithms in a Java " Sort " class. ( insertion sort, selection sort and quicksort, and mergesort). count the number of comparisons made.

  Calculate rental fee for different types of borrowable media

Assume that there is an abstract class called Vehicle, which has two concrete subclasses, Car and Truck. There is also an interface Loadable, which only Truck implements - calculate a rental fee for different types of borrowable media (e.g. books,..

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