Beruflich Dokumente
Kultur Dokumente
Directions:
The exam is open book and there is no time limit. However make sure you
submit your document before end of day Friday Dec 16th.
Do your own work. Sign the honor pledge.
Honor Pledge: I have not given nor received unauthorized assistance in doing
this exam.
_______Alan Ayoub_____
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.
>
<We have four main objects. In the City Field object, the user will be able to enter one of
more cities into the City Field. When the user hits enter, the inputted text will be passed
to CenterText and Weather Action Listener. The CenterText will show the message
Waiting. (As show in the image above). Weather Action Listener then passes a signal
to Fetch Task using a background thread that executes the submit request to the Fetch
Task object. The Fetch Task calls weather api and then passes the required data (URL,
APPID) and then the api will fetch the required data (Current Weather/Temperature). Next,
the Fetch Task will return this data to CenterText and the results will updated in the
display.
>
3
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).
4
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
<Publisher>
import java.awt.List;
import java.io.BufferedReader;
import java.io.InputStreamReader;
return "";
}
} catch (Exception e) {
System.out.println(""+e);
}
return response;
5
}
}
<Subscriber>
} catch (Exception e) {
System.out.println(""+e);
}
}
public void getPublication (String data) {
if (data.startsWith(""+str))
data.setText(textfield.getText());
}
}
>
<Data>
package app;
import java.util.ArrayList;
public class Data {
6
return data;
}
public void setText(String str) {
if (!data.equals(str)) {
data = str;
}
}
<ViewCount>
import app.Data;
import javafx.scene.chart.PieChart;
import javax.swing.*;
public class ViewCount extends JPanel {
<ViewPalindrome>
import app.Data;
7
import javafx.scene.chart.PieChart;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.Element;
textfield.setText(data.getText());
add(textfield);
textfield.setText("abcd");
data.setText(textfield.getText());
textfield.getDocument().addDocumentListener( new
DocumentListener() {
@Override
public void changedUpdate(DocumentEvent ev) {
@Override
public void removeUpdate(DocumentEvent ev){
data.setText( textfield.getText());
}
@Override
public void insertUpdate(DocumentEvent ev){
data.setText( textfield.getText());
}
});
}
8
<View>
import app.Data;
import javafx.scene.chart.PieChart;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.Element;
//textfield.setText(data.getText());
add(textfield);
textfield.setText("abcd");
data.setText(textfield.getText());
textfield.getDocument().addDocumentListener( new
DocumentListener() {
@Override
public void changedUpdate(DocumentEvent ev) {
@Override
public void removeUpdate(DocumentEvent ev){
data.setText( textfield.getText());
}
@Override
public void insertUpdate(DocumentEvent ev){
data.setText( textfield.getText());
}
});
}
9
View(String text, PieChart.Data data) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
>
<There are several different classes that help us achieve our requirements. Publishers
role is to publish and generate items of interest to the rest of the application.
Subscribers role is to receive the application updates. We are also notified when a new
item is published.
>
10
3. J2EE
<
Model View Controller pattern helps us organize and separate the
program three interconnected parts: Model, View, and Controller.
This software design pattern is commonly used and it gives the
programmer a way to organize the information that is presented or
accepted from the user.
>
<
>
11
4. Proxy Design Pattern
<
<
In the proxy pattern definition, it mentions that logistics of
accessing the subjects servicer is overly complex and comparable
or greater in size than that of clients primary responsibility. In our
case, the hangman game was not great in size.
>
<
12
a class called ATMMachine, we would use a proxy object called
ATMProxy in between the Client and the ATMMachine class that
would only allow the client to get their balance for example or only
be able to deposit. The Proxy would act as a buffer to ensure that
the client doesnt have capabilities to set the balance or retrieve
cash that isnt theirs.
>
13