Академический Документы
Профессиональный Документы
Культура Документы
Directions:
The exam is open book and there is no time limit. However make sure you
submit your document before end of day Tuesday Dec 13th.
Do your own work. Sign the honor pledge.
Honor Pledge: I have not given nor received unauthorized assistance in doing
this exam.
Christopher Luntsford
Sign or print your name here.
1
1. UML Class Sequence diagram
Download the file finalExam_questino1_UML.zip that contains classes: Weather (the main
class), WeatherJason and FetchTask. Create an eclipse Java project and copy these classes
into the project. To compile and execute the program you need to have the gson.jar file (also in
the zip) in your build path.
An asynchronous background task is created to get the weather information from the web site
openweathermap.org and display it in a not too interesting text format (weather.com has nothing
to worry about here).
Complete the UML sequence diagram to show the interactions among the objects:
Weather.ActionListener, FetchTask,the UI components and the openweathermap.org web site.
In particular, show the creation of the FetchTask object, how does control pass to it, when does
control return to the UI and when do the cityField and centerField components get updated. It
is important that you show the interactions in the correct sequence and that the arrows originate
from the correct calling object and terminate on the correct called object.
2
<Paste your complete UML diagram here. >
3
to fetch and until there is no more city information. At this point a url connection is
opened to openweathermap.org, and a inputstream is opened and the citylist is shared
with the url until the list is empty, at that time CenterText is updated with the weather
information for the city, the setEnabled(true) is set for the CityField, a return null iss sent
back to Fetch Task and the inputstream is closed, and the display is updated.
4
2. Pub/Sub (also called Observer) Design Pattern
Download the ProblemDesign.zip file. It contains 6 classes; App is the main class. Create a
Java project and copy the 6 classes into the project.
A palindrome is text that reads the same backwards as forwards. Examples are
tattarrattat
Never odd or even.
Do geese see God?
A Toyota! Race fast.. safe car: a toyota.
The application displays a window with 3 field, the user enters text in the center field and the
program shows the character count in the top field and determines if the text is a palindrome
and displays YES or NO in the lower field. The 3 field are implements as 3 views over a
common data model (using the Model-View-Controller pattern).
The program as written does not update the other fields when the text is entered.
Use the Publish/Subscriber pattern to finish the program. You will need to
define Publisher and Subscriber interfaces
decide which class(es) need to implement the subscriber interface. Remember that you
need a receive method on the subscriber.
the Data class should be the publisher and notify all subscribers whenever the text
changes.
<copy your source code for Publisher and Subscriber java interfaces
here>
***
5
Good News, the pub/sub works great(tThast what we want J). The not so
great news is I had brain freeze, for the textfield.setText(data).
Couldnt figure out how to use the different methods with them in the
subscribers
package dw;
package dw;
import java.util.ArrayList;
public class Data implements Publisher{
ArrayList <Subscriber> list = new ArrayList<Subscriber>();
6
s.receive(data);
}
}
}
package dw;
import javax.swing.*;
public class ViewCount extends JPanel implements Subscriber{
textfield.setText(data);
}
7
private JTextField textfield = new JTextField("", 10);
package dw;
import javax.swing.*;
public class ViewPalindrome extends JPanel implements Subscriber
{
textfield.setText(data);
}
}
8
Explain describe the Publisher / Subscriber pattern. When do you use
it? How do you implement it?
3. J2EE
Yes the MVC Pattern can still be used in this case, since there is a
WEB.xml portion to handle the JSON output, so it is the View portion of
the MVC design pattern. If we look further into the web.xml file for the
above mentioned application, we will notice that there is a reference to
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-
9
class>. This mention class handles the output portion of the application.
Thus confirming that the MVC pattern can still be used.
10