Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92226796
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As