Starting from:

$30

SE450-Assignment 3 Solved

This problem combines the decorator pattern with the chain of responsibility pattern(CoR) on a Length converter program (LCP) with a GUI . The LCP performs conversion from kilometer to one of the following three units: Mile, Yard, and Foot.  

1)      Chain of Responsibility Pattern 

The input string specifies the amount to be converted and dropdown menu indicates which unit it will convert to. The CoR pattern will be applied to the processing of the input string to generate a number representing the converted amount. The LCP user interface is seen as a client making a request to convert the input to a given unit. Three handlers are available, one for each unit (MILE, YARD, FOOT). 

 

The resulting processing flow for LCP is shown schematically in the next figure: 

 

Amount in                                                                                                                      Converted 

Kilometer                                                            Amount 

 
 

FOOT_Handler 
 
 
 

2)      Chain of Responsibility + Decorator Pattern 

 

The text appearing in the output field of the LCP GUI is a string that has to undergo three decorations: 

⚫   Round output to 2nd decimal (e.g., 218.723 to 218.72) 

⚫   Write output in exp. notation (e.g., 218.72 to 2.1872e2 ) 

⚫   Add the unit name to the converted amount (e.g., 2.1872e2 to 2.1872e2 Yards) 

 

The resulting processing flow (including the chain of responsibility) for LCP is shown schematically in the next figure: 

  

You will find attached to this document a JAVA files that contains the code of the GUI. 

The code is based on libraries : javax.swing and java.awt 

P.S : at the end of the last lecture I talked about this assignment (for online students and students who did not attend the last lecture, I recommend you to watch that part of the lecture) 

More products