Sie sind auf Seite 1von 13

CST438 Software Engineering Fall 2016 Final Exam

Name : _________Alan Ayoub________

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.

Problem Points Your Score


1 30
2 30
3 20
4 20
total 100

1
1. UML Class Sequence diagram

A UML sequence diagram is used to show the details of class collaborations.

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.

The user enters one or more names of cities separated by commas

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;

public class Data implements Publisher<String> {


private List<Subscriber<String>> subscribers;
private Data () {
subscribers = List.empty();
}
public static Data create () {
return new data();
}

public void publish (String data) {


for (Subscriber<String> sub : subscribers)
sub.getPublication(data);
}
public static String getInput () {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String response = "";
try {
response = br.readLine();
if (response==null) {

return "";
}
} catch (Exception e) {
System.out.println(""+e);

}
return response;

5
}
}

<Subscriber>

import static View.textfield;

public class View implements Subscriber<String> {


private Data data=new Data();

public static void View(String input) {


try {
data = new data(input);
BufferedReader in =
new BufferedReader(new InputStreamReader(data.openStream()));
String inputLine;

} catch (Exception e) {
System.out.println(""+e);
}
}
public void getPublication (String data) {
if (data.startsWith(""+str))
data.setText(textfield.getText());
}
}
>

<copy your modifications to Data, ViewCount, ViewPalindrome, View


classes here

<Data>

package app;

import java.util.ArrayList;
public class Data {

private String data ="tattarrattat";

public String getText()

6
return data;

}
public void setText(String str) {
if (!data.equals(str)) {
data = str;
}
}

public String getCountAsString() { return Integer.toString(


data.length() ); }

public String getCountAsString(String toString) {


throw new UnsupportedOperationException("Not supported yet.");
}
}

<ViewCount>

import app.Data;
import javafx.scene.chart.PieChart;
import javax.swing.*;
public class ViewCount extends JPanel {

private JTextField textfield1 = new JTextField("", 10);

public ViewCount(String label, Data model) {


add( new JLabel(label));
textfield1.setText( model.getCountAsString());
textfield1.setEditable(false);
add(textfield1);
}

ViewCount(String character_Count, PieChart.Data data) {


throw new UnsupportedOperationException("Not supported yet.");
}

<ViewPalindrome>

import app.Data;

7
import javafx.scene.chart.PieChart;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.Element;

public class View extends JPanel {

public static JTextField textfield = new JTextField("", 10);


private Data data;

public View(String label, Data model){


data = model;
add(new JLabel(label));

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());
}

});
}

View(String text, PieChart.Data data) {


throw new UnsupportedOperationException("Not supported yet.");
}
}

8
<View>

import app.Data;
import javafx.scene.chart.PieChart;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.Element;

public class View extends JPanel {

public static JTextField textfield = new JTextField("", 10);


private Data data;

public View(String label, Data model){


data = model;
add(new JLabel(label));

//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.");
}
}

>

Explain describe the Publisher / Subscriber pattern. When do you use


it? How do you implement it?

<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

a. In your own words describe what a Model-View-Controller pattern


is and how J2EE (JSP java server pages, Servlets, and JPA Entity classes)
implement this pattern.

<
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.

The Model View Controller pattern can be implemented with J2EE.


Model is where we retrieve data and convert to Objects. This is
where the Java Persistence Architecture is located. View is where
we create an HTML response to send to a browser. This is where the
Java Server Pages are located. Controller is where we handle
incoming requests. This is where the Servlets are located.

>

b. When writing a REST-JSON application, there are no JSPs that


create html. Can an MVC pattern still be applied to design and implementation of
a REST-JSON server application?

<

Yes, MVC pattern can still be applied to design and implement a


REST-JSON server application. As we have learned, Amazon is a
great example of REST scale out and how they use independent
services for features of their website. Amazon.com appears appears
to be one application when it actuality there are several independent
web services that make up the entire website.

>

11
4. Proxy Design Pattern

a. Read or review the description of the Proxy design pattern in


Marsic 2.6.4 page 264. Describe ways in which the TestHttpExchange class that
was used in Assignment 4 on Junit test of the Http Hangman game, is an
example of using the Proxy pattern.

<

**Assignment #4 is one of the assignments that I had issues with


and was unable to complete, I will do my best answering this
question**

Based on the readings, we use a proxy pattern to manage or control


access to an object. Proxy design serves as a helper object when we
have services that are overly complex.

For the hangman game, we used the TestHttpExchange class as a


helper object to control access to an object.
>

b. Describe one way in which the TestHttpExchange class is not an


example of the Proxy pattern according to the Marsic definition of Proxy 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.
>

c. Briefly describe one other situation where proxy objects would be


useful. It might be something that you coded for other courses but did not realize
at the time it was a Proxy pattern; it might be an example from the textbook; or
an example that you think up on your own.

<

Im going to use security as an example. An example of a situation


where a proxy object would be useful is an ATM machine. If we had

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

Das könnte Ihnen auch gefallen