Program functionality description written in a way closest to the written language (with stricter rules):


Create a window with field group data: "Forename", "Surname", "Birthday" in format "YYYY-mm-dd", "City" and "Country". When the userclicks on the "Save" button the program stores the data into "Users" table in the "Listings" database on the "localhost" database server. If $"database query result" was true, the program displays a message "Data has been saved.", and if notthen "There was an error: " and $"last database error".


Simplified program functionality description:


Create window(data)("Forename" "Surname" "Birthday"(format:"YYYY-mm-dd")"City" "Country" )

Userclick button("Save")store (data) database server("localhost")database("Listings") table("Users")

If $"database query result" true display "Data has been saved."

If$"database query result" falsedisplay "There was an error: " + $"last database error"


Identifying various parts for the program design:


   Create(action) window(object) Forename(parameter) Surname(parameter) Birthday(parameter,format:"YYYY-mm-dd"), City(parameter), Country(parameter)

   User(user) enter(action) Forename(parameter) Surname(parameter) Birthday(parameter), City(parameter), Country(parameter)

   User(user) click(action) button(Save)(object)

   Store(action) localhost(object) Listings(object) Users(object) Forename(parameter) Surname(parameter) Birthday(parameter), City(parameter), Country(parameter)

   $"database query result"(parameter) switch(process)


     ( display(action) "Data has been saved."(parameter) )(case TRUE sequence)

     ( display(action) "There was an error: "(parameter) $"last database result"(parameter) )(case FALSE sequence)



Transformation into a script:



      1a.   Create: window

      1b.   Add: field "Forename", field "Surname", field "Birthday", field "City", field "Country"

      1c.   Set: field "Birthday" pattern"YYYY-mm-dd"

      2a.   Add: button "Save"

      2b.   Set: button "Save" click event{

             2b1.  Connect:database server "localhost"

             2b2.  Use:database "Listings"

             2b3.  Query: INSERT INTO "Users" VALUES ( NULL, field "Forename" value, field "Surname" value, field "Birthday" value, field "City" value, field "Country" value )

             2b5.  Disconnect:database server

             2b4.  return:$"database query result" @resultA


      3a.   Process: switch@resultA {

             3a1.  Case: TRUE{

                      3a1a. Create: message= "Data has been saved."


             3a2.  Case: FALSE{

                      3a2a. Create: message= "There was an error: " + $"last database error"





Script without numbering:


      Create: window

      Add: field "Forename", field "Surname", field "Birthday", field "City", field "Country"

      Set: field "Birthday" pattern"YYYY-mm-dd"

      Add: button "Save"

      Set: button "Save" click event{

          Connect:database server "localhost"

          Use:database "Listings"

          Query: INSERT INTO "Users" VALUES ( NULL, field "Forename" value, field "Surname" value, field "Birthday" value, field "City" value, field "Country" value )

          Disconnect:database server

          return:$"database query result" @resultA


      Process: switch@resultA {

          Case: TRUE{

             Create: message= "Data has been saved."


          Case: FALSE{

             Create: message= "There was an error: " + $"last database error"





Transformation into source code:


package spoken;


import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.text.SimpleDateFormat;

import javax.swing.BoxLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.event.CaretEvent;

import javax.swing.event.CaretListener;


publicclass Spoken extends JFrame {

    publicstatic JTextField Forename, Surname, Birthday, City, Country;

    publicstatic JButton Save;


    public Spoken() {


        JPanel p = new JPanel();

        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));


        setSize(300, 300);


        JLabel ForenameLabel = new JLabel("Forename");

        Forename = new JTextField();

        JLabel SurnameLabel = new JLabel("Surname");

        Surname  = new JTextField();

        JLabel BirthdayLabel = new JLabel("Birthday");

        Birthday = new JTextField();

        JLabel CityLabel = new JLabel("City");

        City     = new JTextField();

        JLabel CountryLabel = new JLabel("Country");

        Country  = new JTextField();


        Birthday.addCaretListener(new CaretListener() {


            publicvoid caretUpdate(CaretEvent e) {

                if ( Birthday.getText().equals("") ) {


                } else {

                    try {

                        (new SimpleDateFormat("yyyy-MM-dd")).parse( Birthday.getText() );

                        System.out.println("Validation passed for " + Birthday.getText());



                    } catch (Exception ex) {

                        System.out.println("Validation failed for " + Birthday.getText());



















        Save = new JButton("Save");

        Save.addActionListener(new ActionListener() {


            publicvoid actionPerformed(ActionEvent e) {

                try {


                    String url = "jdbc:mysql://localhost:3306/Listings";

                    Connection con = DriverManager.getConnection(url, "root", "");


                    PreparedStatement ps = con.prepareStatement("INSERT INTO `Users` VALUES (NULL, ?, ?, ?, ?, ?)");


                    ps.setString(1, Forename.getText());

                    ps.setString(2, Surname.getText());

                    ps.setString(3, Birthday.getText());

                    ps.setString(4, City.getText());

                    ps.setString(5, Country.getText());




                    JOptionPane.showMessageDialog(null, "Data has been saved.");




                } catch (ClassNotFoundException | SQLException ex) {

                    JOptionPane.showMessageDialog(null, "There was an error: " + ex.getMessage());










    publicstaticvoid main(String[] args) {

        new Spoken();