StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Software Architecture: Design and Implementation - Coursework Example

Cite this document
Summary
The paper 'Software Architecture: Design and Implementation' states that a server that after the connection of a client reads files and sends to the client, the client then sends back an answer to the question and if the correct score will be sent to the client…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER94.2% of users find it useful

Extract of sample "Software Architecture: Design and Implementation"

This test class checks if the connection is made.

import  java.net.*  ;

import  java.util.*  ;

import  java.io.*  ;

import  java.math.*;

class  TestClassCall  extends  Thread

{

            Socket  s;

 

            TestClassCall(Socket  s)

            {

                        this.s=s;

            }

 

            public  void  run()

            {

                        try{

 

 

                        OutputStream  o  =  s.getOutputStream()  ;

                        PrintWriter  p  =  new  PrintWriter(o)  ;

 

                        p.println("You  are  the  lucky  caller");

                        createFile  c=  new  createFile();

            c.createFilemain();//creating  the  questions  file

            String  file="questions.txt";

            String  ans;

            int  j=0;

 

            while(j<3)

                        {

                        FileHandler  h  =  new  FileHandler(s,  file)  ;

                        h.start()  ;//call  filehandler  to  pass  files  to  client

                        j++;//increment  every  time  a  file  is  passed

 

                        try  {

                        InetAddress  inet  =  InetAddress.getLocalHost()  ;

                        try  {

                                               Socket  sc  =  new  Socket(inet,  2002);

                                               InputStream  inc  =  sc.getInputStream();

                        BufferedReader  dc  =  new  BufferedReader(new  InputStreamReader(inc));

            ans  =  dc.readLine();

 

            System.out.println(ans)  ;

 

                        if(j==1)//for  the  first  file

                        {

 

                                   if  (ans=="cbabbaabac")//if  answer  to  first  file  is  correct

                                   {

 

                        int  fnum;

                        fnum=  1+((int)(Math.random()*3));

 

                        switch  (fnum)

                        {

                        case  1:  file="finalq1.txt";

                        createFile  c1=  new  createFile();

            c1.createFile1();

                        break;

                        case  2:  file="finalq2.txt";

                        createFile  c2=  new  createFile();

            c2.createFile2();

                        break;

                        case  3:  file="finalq3.txt";

                        createFile  c3=  new  createFile();

                        c3.createFile3();

                        break;

                        default:  file="finalq1.txt";

                        createFile  c4=  new  createFile();

            c4.createFile1();

            break;

                        }

                                   }

                                   else

                                   {

                                               p.println("Unlucky,  try  again");

                                               j=3;

                                   }

                                   }

 

                        if(j==2)//the  second  time  a  file  is  called  i.e  the  final  q

                        {

                        if  (ans=="a")

            p.println("You  have  won  $10,000,  congratulations");

            else

            p.println("You  have  answered  incorrectly.  your  prize  is  a  tv");

            j=3;

                        }

 

                        }

                        catch  (IOException  e)

                                   {

                                               System.out.println("Failed  connection  to  server")  ;

                                   }

                        }

                        catch  (UnknownHostException  e)  {

                        System.out.println("Unknown  Host  ")  ;

                        e.printStackTrace();

                        }

            }

 

                        }

                        catch  (IOException  e)  {

            System.out.println("an  exception  occurred:  "  +  e.getMessage());

            e.printStackTrace();

            }

                        }

                        }

import java.io.*;

import java.util.*;

import java.util.ListIterator;

import java.awt.event.*;

import javax.swing.*;

 

  1. This test class checks the proper functioning of the multiple-choice tests.

 

public class Swing_Tester extends javax. swing.JFrame {

    ArrayList questions = new ArrayList();

    ArrayList answers = new ArrayList();

    ArrayList explainations = new ArrayList();

    int iTotalQuestionsAnswered=0;

    int iTotalQuestionsAnsweredCorrectly=0;

    int iCurrentQuestion;

    boolean fQuestionWasAnswered;

 

    /** Creates new form Swing_Tester */

    public Swing_Tester() {

        initComponents();

    }

 

    String replace(String sOriginal,

          String sSearchFor,

          String sReplacement) {

      if (sOriginal.equals("")) return "";

      String sNewString = "";

      int iPosOfStr = sOriginal.indexOf(sSearchFor,0);

      int iLastPos = 0;

      while (iPosOfStr != -1) {

        sNewString += sOriginal.substring(

            iLastPos,iPosOfStr) +

            sReplacement;

        iLastPos = iPosOfStr + sSearchFor.length();

        iPosOfStr = sOriginal.indexOf(sSearchFor,iLastPos);

      }

      sNewString += sOriginal.substring(iLastPos);

      return sNewString;

    }

 

    private void setNewQuestion() {

        txtQuestion.setText("");

        iCurrentQuestion=(int)(Math.random()*questions.size());

        txtQuestion.setText(txtQuestion.getText()

          + "\nQuestion:\n");

        txtQuestion.setText(txtQuestion.getText()

          + (String)questions.get(iCurrentQuestion));

        txtQuestion.setText(txtQuestion.getText() + "\n");

    }

 

    private void printScore() {

        float rScore = (float)iTotalQuestionsAnsweredCorrectly /

            (float)iTotalQuestionsAnswered * 100F;

        rScore = java.lang.Math.round(rScore*10F)/10F;

        txtQuestion.setText(txtQuestion.getText()

            + "\nYour score is: " + rScore + "%");

        txtQuestion.setText(txtQuestion.getText() + "\n"

            + iTotalQuestionsAnsweredCorrectly

            + " out of " + iTotalQuestionsAnswered);

    }

 

    private void showExplaination(){

        txtQuestion.setText(txtQuestion.getText()

            + "Explaination:\n"

            + (String)explainations.get(iCurrentQuestion));

    }

 

    private void checkAnswer() {

        txtQuestion.setText(txtQuestion.getText()

            + "\n" + txtAnswer.getText());

        if (txtAnswer.getText().equals(

            (String)answers.get(iCurrentQuestion))) {

          txtQuestion.setText(txtQuestion.getText()

            + "\n     Right!\n");

          iTotalQuestionsAnswered++;

          iTotalQuestionsAnsweredCorrectly++;

        } else {

          txtQuestion.setText(txtQuestion.getText()

            + "\nWrong.");

          txtQuestion.setText(txtQuestion.getText()

            + "\nThe correct answer is: '"

            + (String)answers.get(iCurrentQuestion)

            + "' not '" + txtAnswer.getText() + "'\n");

          iTotalQuestionsAnswered++;

        }

    }

    //

    /** This method is called from within the constructor to

     * initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is

     * always regenerated by the Form Editor.

     */

    private void initComponents() {

        jScrollPane4 = new javax.swing.JScrollPane();

        txtQuestion = new javax.swing.JTextArea();

        txtAnswer = new javax.swing.JTextField();

 

        setFont(new java.awt.Font("Arial", 0, 10));

        addWindowListener(new java.awt.event.WindowAdapter() {

            public void windowOpened(java.awt.event.WindowEvent evt) {

                formWindowOpened(evt);

            }

            public void windowClosing(java.awt.event.WindowEvent evt) {

                exitForm(evt);

            }

        });

 

        txtQuestion.setEditable(false);

        txtQuestion.setLineWrap(true);

        txtQuestion.setWrapStyleWord(true);

        jScrollPane4.setViewportView(txtQuestion);

 

        getContentPane().add(jScrollPane4,

                 java.awt.BorderLayout.CENTER);

 

        txtAnswer.setText("Type your answer here and press enter.  Press enter a second time to move to the next question.");

        txtAnswer.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyPressed(java.awt.event.KeyEvent evt) {

                txtAnswerKeyPressed(evt);

            }

        });

 

        getContentPane().add(txtAnswer, java.awt.BorderLayout.SOUTH);

 

        pack();

        java.awt.Dimension screenSize =

              java.awt.Toolkit.getDefaultToolkit().getScreenSize();

        setSize(new java.awt.Dimension(600, 300));

        setLocation((screenSize.width-600)/2,

              (screenSize.height-300)/2);

    }

 

    private void txtAnswerKeyPressed(java.awt.event.KeyEvent evt) {

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {

            if (fQuestionWasAnswered) {

                txtAnswer.setText("");

                setNewQuestion();

            } else {

                checkAnswer();

                showExplaination();

                printScore();

            }

            fQuestionWasAnswered = !fQuestionWasAnswered;

        }

    }

 

    private void formWindowOpened(java.awt.event.WindowEvent evt) {

        // Add your handling code here:

        BufferedReader oBufferedReader;

        String sLineOfText;

 

        try {

          oBufferedReader = new BufferedReader(

              new FileReader("fill.txt"));

 

          String sSection = "q";

          String sLineToAdd = "";

          while((sLineOfText = oBufferedReader.readLine())!= null) {

            if (sLineOfText.indexOf("<q>")>=0) {

                sSection = "q";

                sLineOfText = replace(sLineOfText, "<q>","");

            } else if (sLineOfText.indexOf("<a>")>=0) {

                sSection = "a";

                sLineOfText = replace(sLineOfText, "<a>","");

            } else if (sLineOfText.indexOf("<e>")>=0) {

                sSection = "e";

                sLineOfText = replace(sLineOfText, "<e>","");

            }

 

            if (sLineOfText.indexOf("</q>")>=0) {

                sSection = "/q";

                sLineOfText = replace(sLineOfText, "</q>","");

            } else if (sLineOfText.indexOf("</a>")>=0) {

                sSection = "/a";

                sLineOfText = replace(sLineOfText, "</a>","");

            } else if (sLineOfText.indexOf("</e>")>=0) {

                sSection = "/e";

                sLineOfText = replace(sLineOfText, "</e>","");

            }

 

            if (sLineToAdd.equals("")) {

                sLineToAdd = sLineOfText;

            } else {

                sLineToAdd = sLineToAdd + "\n" + sLineOfText;

            }

 

            if (sSection.equals("/q")) {

              questions.add(sLineToAdd);

              sLineToAdd = "";

              sSection = "";

            } else if (sSection.equals("/a")) {

              answers.add(sLineToAdd);

              sLineToAdd = "";

              sSection = "";

            } else if (sSection.equals("/e")) {

              explainations.add(sLineToAdd);

              sLineToAdd = "";

              sSection = "";

            }

          }

          oBufferedReader.close();

        } catch (FileNotFoundException ioe) {

          JOptionPane.showMessageDialog(this,

              "Couldn't open the file fill.txt.",

              "Question file error:", JOptionPane.INFORMATION_MESSAGE);

          System.exit(0);

        }catch (IOException ioe1) {

          JOptionPane.showMessageDialog(this,

              "Now that's something different",

              "Question file error:", JOptionPane.INFORMATION_MESSAGE);

          System.exit(0);

        };

 

        txtAnswer.requestFocus();

        txtAnswer.setSelectionStart(0);

        txtAnswer.setSelectionEnd(txtAnswer.getText().length());

        //Show the first question.

        setNewQuestion();

    }

 

    /** Exit the Application */

    private void exitForm(java.awt.event.WindowEvent evt) {

        System.exit(0);

    }

 

    /**

    * @param args the command line arguments

    */

    public static void main(String args[]) {

        new Swing_Tester().show();

    }

 

 

    // Variables declaration - do not modify

    private javax.swing.JScrollPane jScrollPane4;

    private javax.swing.JTextArea txtQuestion;

    private javax.swing.JTextField txtAnswer;

    // End of variables declaration

 

}

//End of code----------------

Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(Software Architecture: Design And Implementation(Pogramming Java 3), n.d.)
Software Architecture: Design And Implementation(Pogramming Java 3). https://studentshare.org/logic-programming/2043653-software-architecture-design-and-implementationpogramming-java-3
(Software Architecture: Design And Implementation(Pogramming Java 3)
Software Architecture: Design And Implementation(Pogramming Java 3). https://studentshare.org/logic-programming/2043653-software-architecture-design-and-implementationpogramming-java-3.
“Software Architecture: Design And Implementation(Pogramming Java 3)”. https://studentshare.org/logic-programming/2043653-software-architecture-design-and-implementationpogramming-java-3.
  • Cited: 0 times

CHECK THESE SAMPLES OF Software Architecture: Design and Implementation

Physical Architecture Layer Design

Physical layer architecture design specifies the distribution of the system across the networked computers in addition to pointing out the necessary hardware and software to be used.... The paper explores on the different components of physical architecture design, network models, various architecture designs and the factors that affect the design of the physical layer architecture.... Introduction The physical layer architecture design is used to specify how the system is distributed across the computers constituting the network of an organization....
3 Pages (750 words) Coursework

Literature Review: The Use of Patterns in Architecture

software architecture Knowledge Management.... In this way, always being modified to fit better into the various implementation scopes.... The use of patterns in architecture represents the view of using archetypal and reusable descriptions as representations of architectural design ideas.... An essay "Literature Review: The Use of Patterns in architecture" claims that architecture patterns seek to bring forth usable ideas through which people and communities can follow in the construction of their buildings....
8 Pages (2000 words) Essay

Digital Tools and Architectural Visualization

This is attributed to the availability of digital media which predominantly promotes computer visualization, and the use of architectural design in information systems.... Architectural design is among the professions in the world that have direct effect on us, we probably would not be seeing the kind of buildings that pride our skylines today were not for this profession.... It should be understood that the current complex designs seen in the first world countries would not have happened without complex digital technology to birth a design....
12 Pages (3000 words) Term Paper

Service Oriented Architectures

“Just as the Databases were at the center of design of applications of the 70s and 80s, Components are at the center of design of the applications of the 90s and the next century” – David Vaskevitch, VP, Microsoft.... he large scale success of component-based architecture has lead to the development of Service Oriented Architectures (SOA).... The concept of SOA is an evolution of the Component Based architecture in which the enterprise's architecture is developed in a ‘Service-Driven Approach'....
12 Pages (3000 words) Essay

Software Architecture

Whether developing a desktop application or web-based software program, the architecture design formulated would be a specialized version of one of the documented styles and patterns.... The paper "software architecture" presents an overview of the most commonly used architecture styles and patterns.... software architecture represents the high-level structural model of a software system.... software architecture is important with regard to the several purposes it fulfills....
6 Pages (1500 words) Term Paper

Analysis Modeling, Design Concepts, and Architectural Design

Software design and architecture requires understanding of Entity Relationship Diagram, Class Diagram, relationship between design and programming, rationality behind modular programming, and relation between the concepts of portability and coupling.... oftware design is not a program, but it defines high level abstraction or pieces of logic for satisfying business requirement from a client into creation and delivery of software before even coding starts (Pressman, 2005)....
5 Pages (1250 words) Assignment

Software Design

Then we integrate these details into the software architecture design and evaluation methods.... These are; system formulation, requirement definition, architecture design, detailed design, implementation, system test and deployment.... These emerging issues will either be USABILITY AND software architecture: “THE FORGOTTEN PROBLEMS” The “forgotten problems”.... The software architecture in place will determine the easiness of change....
2 Pages (500 words) Essay

The Role of Software Architecture

The paper 'The software architecture' presents an illustration of the software architecture along with the software components.... The objective of developing software architecture is that the under development software application should qualify all the quality parameters defined in the architecture.... It is pertinent to mention here that the advantages of using the software application cannot be achieved if the software application does not accomplish the quality parameters specified in the software architecture....
12 Pages (3000 words) Assignment
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us