关于前端:COMP122-图形接口

40次阅读

共计 5265 个字符,预计需要花费 14 分钟才能阅读完成。

COMP122 Assessment 3
Graphical User Interfaces
Due 2019-05-02 at 5pm
COMP122 Assessment 3 Due 2019-05-02 at 5pm
A GUI for a new cryptographic routine
Your employer has patented a brand new and super secure encryption algorithm and you are tasked
with building a flashy UI for end-users to help the marketing department turn it into gold.
You are told that the encryption mechanism uses an integer as secret key when translating plain texts to
crypto texts and back. Both encryption and decryption are done using the same method, called rotate.
To encrypt a plain text string plaintext with key k (an int), you would pass both values as parameters
to this function: cryptotext = rotate(plaintext, k); Conversely, decoding works very much
the same way, but using the inverse key as follows: plaintext = rotate(cryptotext, -k);
To comply with recent governmental regulations, and to make some extra money, your employer
decided to additionally include a back-door – a separate routine that allows to deduce plain texts from
crypto texts without knowing the secret key.
Both crypto-routines are implemented as methods of a class called Caesar, but the implementation
details are proprietary and above your pay grade. So instead of the source code of this class, you are
only given an interface called RotationCipher (see the UML diagram below and also the javadoc
comments in RotationCipher.java) that declares the two routines.
<<interface>>
RotationCipher

  • rotate(s : String, n: int) : String
  • decipher(s : String) : String
    Additionally, you are given a file called Caesar.class that contains the compiled bytecode of the
    Caesar class, which implements this interface, and which you can instantiate in your code to access
    the crypto-routines.
    Requirements
    You are tasked to write a graphical user interface based on the Swing toolkit that allows users to encrypt
    and decrypt text using the new method.
    a. Write a Java program called CaesarGUI that allows users to encrypt and decrypt text. You can
    add any JComponent widgets you like but as a minimum there should be
    a JFrame window to hold all other components
    JTextFields (or similar components) for the plain text, the integer key, and crypto text.
    a JButton for the user to click on and trigger the conversion
    appropriate JLabels to identify the above.
    2
    COMP122 Assessment 3 Due 2019-05-02 at 5pm
    When the button is clicked, your program should read the input plain text and integer key o the
    respective components, call the rotate method and update the component for the crypto text.
    b. Document your design. Where in your code do you instantiate the Caesar class? How do
    the dierent component depend on each other (who creates who)? Describe your design in a
    separate report (a PDF). Good documentation would include javadoc and in-line comments at an
    appropriate level (don’t document every line of code). You should also add an UML class diagram
    that displays all component classes and their attributes/methods that you used in your code.
    c. (Bonus) Add some way of validating the input of the integer key. Acceptable solutions would be
    if, in case the input cannot be parsed as an integer, the text field turns red, a warning pop-up or
    some status line displays an error message. You may also use (or write) Component classes that
    make it impossible for users to input non-integers. Document your design choices.
    d. (Bonus) Write another GUI, similar to the one above, that uses Caesar.decipher to decipher
    encrypted text without the secret key.
    Hints
    As mentioned in the lectures, it is good practice (but not required) to define your main window
    as subclass of JFrame and assemble the components in its constructor.
    To react to the user clicking on your button, you will want to write an ActionListener (a class
    that implements this interface) and register an instance of this listener class with the button. This
    is the Controller part of your Model-View-Controller program. Have a look at the code examples
    in lecture 17 to see how to do this.
    To get or set the content of a TextField, use its methods getText() and setText() with
    signatures as below. See the API docs on oracle.com for more.
  • public String getText();
  • public void setText(String s);
    For part c) remember the input validation we discussed as examples for exception handling in
    lectures 11 & 12. You may use java.io.Scanner or java.lang.Integer’s parseInt method,
    which takes a String, returns an int and possibly throws a NumberFormatException.
  • try{
  • int i = Integer.parseInt(text)
  • }
  • catch (NumberFormatException e){…}
    3
    COMP122 Assessment 3 Due 2019-05-02 at 5pm
    Submission Instructions
    Deadline: Thursday, 2 May 2019, 5:00pm
    Submission server: https://sam.csc.liv.ac.uk/COM…
    Your submission should be a single compressed .zip file called comp122_assessment_3_SID.zip
    where SID should be replaced by your student ID. This file should include:
  • Your implementation. This must include the .java source files. Put everything into a subfolder
    called‘src’, including the interface and class file you received for the exercise.
  • A report in .pdf format. You can structure this report as you like and do not need to have the
    same formal structure nor pseudo-code as in A1.
    Marking Scheme
    Each part counts towards the final mark of this coursework as follows.
    a b c d
    50% 30% 10% 10%
    To get full marks for parts c) and d) you need to include documentation, not just the implementation
    alone. You do not need to include a full UML class diagram for part d) but it’d make sense to have one
    diagram that covers a) and c).
    If your code does not compile and run on departmental computer systems you will suer a penalty of
    5%. The same applies if your submission does not exactly follow the submission instructions regarding
    file name and type.
    Your submission is an individual piece of work. No collaboration with other students is allowed!
    Expect that plagiarism detection soware will be run on your submission to compare your work to
    that of other students. Late submissions and plagiarism/collusion are subject to the University Code
    of Practice on Assessment, available here1
    . In particular, since these are online submissions, a late
    penalty of 5% applies for every 24h period aer the deadline.
    Notice that I will not grant extensions requested aer the submission deadline!
正文完
 0