From 06e01756bf8547034b5787dc9df0a93f786ec1fd Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Sun, 24 Sep 2017 11:41:48 +0200 Subject: [PATCH] Finishing statements exercise --- Doc/Sd1/Ref/Statements/if_elseIf_else.svg | 1365 +++++++++++++++++++++ Doc/Sd1/coreClasses.xml | 472 ++----- Doc/Sd1/statements.xml | 1357 +++++++++++--------- 3 files changed, 2263 insertions(+), 931 deletions(-) create mode 100644 Doc/Sd1/Ref/Statements/if_elseIf_else.svg diff --git a/Doc/Sd1/Ref/Statements/if_elseIf_else.svg b/Doc/Sd1/Ref/Statements/if_elseIf_else.svg new file mode 100644 index 000000000..2e6153a04 --- /dev/null +++ b/Doc/Sd1/Ref/Statements/if_elseIf_else.svg @@ -0,0 +1,1365 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:ns1="http://sozi.baierouge.fr" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + sodipodi:docname="ifElse_ifElse.svg" + inkscape:version="0.92.1 r15371" + version="1.2" + id="svg2" + height="441.26913" + width="560"> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="0.85397725" + inkscape:cx="694.03135" + inkscape:cy="3.2124643" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="1600" + inkscape:window-height="1105" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="1" + showguides="false" + inkscape:guide-bbox="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0"> + <inkscape:grid + originy="-250.56831" + originx="60" + id="grid1569" + type="xygrid" /> + </sodipodi:namedview> + <defs + id="defs4"> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#00ff00;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:isstock="true" + style="overflow:visible" + id="marker2318" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lend"> + <path + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.85333335pt;stroke-opacity:1" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path2316" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:isstock="true" + style="overflow:visible" + id="marker4887" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lend"> + <path + inkscape:connector-curvature="0" + transform="matrix(-0.8,0,0,-0.8,-10,0)" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + id="path4627" /> + </marker> + <marker + inkscape:stockid="Arrow1Lend" + orient="auto" + refY="0" + refX="0" + id="marker6797" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path6799" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.85333335pt;stroke-opacity:1" /> + </marker> + <marker + inkscape:stockid="Arrow1Lend" + orient="auto" + refY="0" + refX="0" + id="marker6793" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path6795" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.85333335pt;stroke-opacity:1" /> + </marker> + <marker + inkscape:isstock="true" + style="overflow:visible" + id="marker6778" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lend"> + <path + inkscape:connector-curvature="0" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.85333335pt;stroke-opacity:1" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path6514" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1Lstart" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lstart"> + <path + inkscape:connector-curvature="0" + style="fill-rule:evenodd;stroke:#000000;stroke-width:0.85333335pt" + d="M 10.666667,0 14.933333,-4.2666667 0,0 14.933333,4.2666667 Z" + id="path3841" /> + </marker> + <marker + inkscape:stockid="SquareM" + orient="auto" + refY="0" + refX="0" + id="SquareM" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path3914" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill-rule:evenodd;stroke:#000000;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1Lend" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lend"> + <path + inkscape:connector-curvature="0" + style="fill-rule:evenodd;stroke:#000000;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path3844" /> + </marker> + <marker + style="overflow:visible" + id="DiamondM" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="DiamondM"> + <path + inkscape:connector-curvature="0" + style="fill-rule:evenodd;stroke:#000000;stroke-width:0.42666668pt" + d="M 0,-3.0169928 -3.0169981,0 0,3.0169851 3.0169797,0 Z" + id="path3923" /> + </marker> + <marker + style="overflow:visible" + id="DiamondMH" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="DiamondMH"> + <path + inkscape:connector-curvature="0" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.42666668pt" + d="M 0,-3.0169928 -3.0169981,0 0,3.0169851 3.0169797,0 Z" + id="path4656" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LendB" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LendB"> + <path + inkscape:connector-curvature="0" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path4659" /> + </marker> + <marker + inkscape:stockid="SquareMU" + orient="auto" + refY="0" + refX="0" + id="SquareMU" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path5221" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1Lend3" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lend3"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path5224" /> + </marker> + <marker + style="overflow:visible" + id="DiamondMo" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="DiamondMo"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.42666668pt" + d="M 0,-3.0169928 -3.0169981,0 0,3.0169851 3.0169797,0 Z" + id="path5799" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LendO" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LendO"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path5802" /> + </marker> + <marker + style="overflow:visible" + id="DiamondM1" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="DiamondM1"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.42666668pt" + d="M 0,-3.0169928 -3.0169981,0 0,3.0169851 3.0169797,0 Z" + id="path6393" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LendV" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LendV"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path6396" /> + </marker> + <marker + inkscape:stockid="SquareMN" + orient="auto" + refY="0" + refX="0" + id="SquareMN" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path7813" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LstartP" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LstartP"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.85333335pt" + d="M 10.666667,0 14.933333,-4.2666667 0,0 14.933333,4.2666667 Z" + id="path7816" /> + </marker> + <marker + inkscape:stockid="SquareMb" + orient="auto" + refY="0" + refX="0" + id="SquareMb" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path9491" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LendX" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LendX"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path9494" /> + </marker> + <marker + inkscape:stockid="SquareM8" + orient="auto" + refY="0" + refX="0" + id="SquareM8" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path10143" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LendT" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LendT"> + <path + inkscape:connector-curvature="0" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path10146" /> + </marker> + <marker + inkscape:stockid="SquareMNT" + orient="auto" + refY="0" + refX="0" + id="SquareMNT" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path12195" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LstartPJ" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LstartPJ"> + <path + inkscape:connector-curvature="0" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.85333335pt" + d="M 10.666667,0 14.933333,-4.2666667 0,0 14.933333,4.2666667 Z" + id="path12198" /> + </marker> + <marker + inkscape:stockid="SquareMNTL" + orient="auto" + refY="0" + refX="0" + id="SquareMNTL" + style="overflow:visible"> + <path + inkscape:connector-curvature="0" + id="path12907" + d="M -2.1333333,-2.1333333 V 2.1333333 H 2.1333333 V -2.1333333 Z" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.42666668pt" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1Lendx" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1Lendx"> + <path + inkscape:connector-curvature="0" + style="fill:#ff0000;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path12910" /> + </marker> + <marker + style="overflow:visible" + id="DiamondMoY" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="DiamondMoY"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.42666668pt" + d="M 0,-3.0169928 -3.0169981,0 0,3.0169851 3.0169797,0 Z" + id="path13187" /> + </marker> + <marker + style="overflow:visible" + id="Arrow1LendOe" + refX="0" + refY="0" + orient="auto" + inkscape:stockid="Arrow1LendOe"> + <path + inkscape:connector-curvature="0" + style="fill:#00ff00;fill-rule:evenodd;stroke:#00ff00;stroke-width:0.85333335pt" + d="M -10.666667,0 -14.933333,4.2666667 0,0 -14.933333,-4.2666667 Z" + id="path13190" /> + </marker> + <linearGradient + id="linearGradient3928-8"> + <stop + id="stop3930-2" + style="stop-color:#7c7c7c" + offset="0" /> + <stop + id="stop3932-0" + style="stop-color:#e6e3e3" + offset="1" /> + </linearGradient> + <linearGradient + id="linearGradient8877"> + <stop + id="stop8879" + offset="0" + style="stop-color:#cecece;stop-opacity:1;" /> + <stop + id="stop8881" + offset="1" + style="stop-color:#ffffff;stop-opacity:1;" /> + </linearGradient> + <linearGradient + id="linearGradient8869"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop8871" /> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="1" + id="stop8873" /> + </linearGradient> + <linearGradient + id="linearGradient7421"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop7423" /> + <stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop7425" /> + </linearGradient> + <linearGradient + id="linearGradient7405"> + <stop + id="stop7407" + offset="0" + style="stop-color:#9e9e9e;stop-opacity:1;" /> + <stop + id="stop7409" + offset="1" + style="stop-color:#ffffff;stop-opacity:0;" /> + </linearGradient> + <linearGradient + id="linearGradient7378"> + <stop + style="stop-color:#9e9e9e;stop-opacity:1;" + offset="0" + id="stop7380" /> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="1" + id="stop7382" /> + </linearGradient> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 32 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="64 : 32 : 1" + inkscape:persp3d-origin="32 : 21.333333 : 1" + id="perspective6864" /> + <filter + style="color-interpolation-filters:sRGB" + id="imagebot_16"> + <feGaussianBlur + stdDeviation="1.2625" + id="imagebot_21" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.90019155,1.1108747)" + x1="32.287571" + y1="-192.16943" + x2="33.162106" + xlink:href="#linearGradient3928-8" + y2="-235.34229" + id="imagebot_14" /> + <filter + style="color-interpolation-filters:sRGB" + height="1.215" + x="-0.041609999" + y="-0.1075" + width="1.0832" + id="imagebot_12"> + <feGaussianBlur + stdDeviation="0.5375" + id="imagebot_18" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + x1="43.709675" + y1="-254.4969" + x2="34.572056" + xlink:href="#linearGradient3928-8" + y2="-245.02541" + id="imagebot_9" /> + <filter + style="color-interpolation-filters:sRGB" + id="imagebot_16-6"> + <feGaussianBlur + stdDeviation="1.2625" + id="imagebot_21-1" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.90019155,1.1108747)" + x1="32.287571" + y1="-192.16943" + x2="33.162106" + xlink:href="#linearGradient3928-8" + y2="-235.34229" + id="imagebot_14-8" /> + <filter + style="color-interpolation-filters:sRGB" + height="1.215" + x="-0.041609999" + y="-0.1075" + width="1.0832" + id="imagebot_12-7"> + <feGaussianBlur + stdDeviation="0.5375" + id="imagebot_18-9" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + x1="43.709675" + y1="-254.4969" + x2="34.572056" + xlink:href="#linearGradient3928-8" + y2="-245.02541" + id="imagebot_9-2" /> + <filter + style="color-interpolation-filters:sRGB" + id="imagebot_16-2"> + <feGaussianBlur + stdDeviation="1.2625" + id="imagebot_21-8" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.90019155,1.1108747)" + x1="32.287571" + y1="-192.16943" + x2="33.162106" + xlink:href="#linearGradient3928-8" + y2="-235.34229" + id="imagebot_14-9" /> + <filter + style="color-interpolation-filters:sRGB" + height="1.215" + x="-0.041609999" + y="-0.1075" + width="1.0832" + id="imagebot_12-73"> + <feGaussianBlur + stdDeviation="0.5375" + id="imagebot_18-6" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + x1="43.709675" + y1="-254.4969" + x2="34.572056" + xlink:href="#linearGradient3928-8" + y2="-245.02541" + id="imagebot_9-1" /> + <filter + id="imagebot_16-0" + style="color-interpolation-filters:sRGB"> + <feGaussianBlur + stdDeviation="1.2625" + id="imagebot_21-7" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.90019155,1.1108747)" + x1="32.287571" + y1="-192.16943" + x2="33.162106" + xlink:href="#linearGradient3928-8" + y2="-235.34229" + id="imagebot_14-5" /> + <filter + height="1.215" + x="-0.041609999" + y="-0.1075" + width="1.0832" + id="imagebot_12-0" + style="color-interpolation-filters:sRGB"> + <feGaussianBlur + stdDeviation="0.5375" + id="imagebot_18-4" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + x1="43.709675" + y1="-254.4969" + x2="34.572056" + xlink:href="#linearGradient3928-8" + y2="-245.02541" + id="imagebot_9-8" /> + <filter + style="color-interpolation-filters:sRGB" + id="imagebot_16-02"> + <feGaussianBlur + stdDeviation="1.2625" + id="imagebot_21-9" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.90019155,1.1108747)" + x1="35.173683" + y1="43.90382" + x2="36.048218" + xlink:href="#linearGradient3928-8" + y2="0.73097426" + id="imagebot_14-4" /> + <filter + style="color-interpolation-filters:sRGB" + height="1.215" + x="-0.041609999" + y="-0.1075" + width="1.0832" + id="imagebot_12-3"> + <feGaussianBlur + stdDeviation="0.5375" + id="imagebot_18-5" /> + </filter> + <linearGradient + gradientUnits="userSpaceOnUse" + x1="43.709675" + y1="-254.4969" + x2="34.572056" + xlink:href="#linearGradient3928-8" + y2="-245.02541" + id="imagebot_9-17" /> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-3" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#00ff00;fill-opacity:1;fill-rule:evenodd;stroke:#00ff00;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-4" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-5" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="marker11618O" + orient="auto" + refY="0" + refX="0" + id="marker11618O" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path10547" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#00ff00;fill-opacity:1;fill-rule:evenodd;stroke:#00ff00;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-4" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#008000;fill-opacity:1;fill-rule:evenodd;stroke:#008000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-43" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-0" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-5-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-4-2" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#008000;fill-opacity:1;fill-rule:evenodd;stroke:#008000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-4-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-5-8" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-4-1-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-5-8-2" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-5-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-4-3" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#008000;fill-opacity:1;fill-rule:evenodd;stroke:#008000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-5-2-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-4-3-9" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#008000;fill-opacity:1;fill-rule:evenodd;stroke:#008000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-4-1-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-5-8-3" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-43-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-0-2" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-43-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-0-1" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + <marker + inkscape:stockid="Arrow1Mend" + orient="auto" + refY="0" + refX="0" + id="marker11618-6-43-1-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path11616-5-0-2-8" + d="M 0,0 5,-5 -12.5,0 5,5 Z" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1" + transform="matrix(-0.4,0,0,-0.4,-4,0)" /> + </marker> + </defs> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + transform="translate(60,-430.68225)" + id="layer1" + inkscape:groupmode="layer" + inkscape:label="Layer 1"> + <text + id="text3004" + y="430.68225" + x="104.51711" + style="font-style:normal;font-weight:normal;font-size:12.80000019px;line-height:0%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.06666672" + xml:space="preserve"><tspan + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:monospace;-inkscape-font-specification:monospace;stroke-width:1.06666672" + y="430.68225" + x="104.51711" + id="tspan3006" + sodipodi:role="line"> </tspan></text> + <text + id="text135" + y="608.18481" + x="14.893998" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#008000;fill-opacity:1;stroke:none" + xml:space="preserve"><tspan + id="tspan137" + y="608.18481" + x="14.893998" + sodipodi:role="line">true</tspan></text> + <text + id="text141" + y="532.97717" + x="187.32318" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none" + xml:space="preserve"><tspan + id="tspan143" + y="532.97717" + x="187.32318" + sodipodi:role="line">false</tspan></text> + <g + id="g177" + transform="translate(-145,124.99999)"> + <rect + style="fill:#000000;stroke-width:4.16333246;stroke-miterlimit:4;stroke-dasharray:none" + id="rect4803" + width="130" + height="40" + x="85" + y="647.51971" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="95" + y="677.51971" + id="text4462"><tspan + sodipodi:role="line" + id="tspan4460" + x="95" + y="677.51971">Block 1</tspan></text> + </g> + <circle + r="5" + cy="377.51971" + cx="55" + id="path4820" + style="fill:none;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <ellipse + ry="30" + rx="80" + cy="482.51971" + cx="130" + id="path4824" + style="fill:none;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <g + transform="translate(-84.403257,279.49453)" + id="g4849"> + <ellipse + style="fill:#000000;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path4828-7" + cx="285.07419" + cy="572.61981" + rx="15.003441" + ry="14.991529" /> + <ellipse + style="fill:none;stroke:#000000;stroke-width:0.90602088;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path4845" + cx="285.07285" + cy="572.5061" + rx="19.461161" + ry="19.497755" /> + </g> + <g + id="g541"> + <g + id="g536"> + <ellipse + ry="10.051409" + rx="9.9901352" + cy="467.49548" + cx="119.45428" + id="path4828" + style="fill:#000000;stroke:none;stroke-width:0.57854682;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + inkscape:connector-curvature="0" + id="path4851-6" + d="m 120,477.51972 v 30" + style="fill:none;stroke:#000000;stroke-width:2.26778674;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6)" + sodipodi:nodetypes="cc" /> + </g> + </g> + <path + inkscape:connector-curvature="0" + id="path4851-6-74" + d="M 10,552.51972 V 767.51971" + style="fill:none;stroke:#008000;stroke-width:2.89087248;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-5)" + sodipodi:nodetypes="cc" /> + <path + inkscape:connector-curvature="0" + id="path4851-6-7" + d="M 10,812.51971 V 852.5197 H 175" + style="fill:none;stroke:#000000;stroke-width:2.26778674;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-43)" + sodipodi:nodetypes="ccc" /> + <g + id="g242" + transform="translate(-30,-55)"> + <path + style="fill:#1a1a1a;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 45,607.51972 105,40 95,-40 -95,-40 z" + id="path145-6" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccc" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="100.79371" + y="604.76978" + id="text4458-7"><tspan + sodipodi:role="line" + id="tspan4456-5" + x="100.79371" + y="604.76978">Cond.</tspan><tspan + id="tspan200" + sodipodi:role="line" + x="100.79371" + y="644.76978"> 1</tspan></text> + </g> + <g + id="g182" + transform="translate(-201.66667,149.99999)"> + <rect + style="fill:#000000;stroke-width:4.16333246;stroke-miterlimit:4;stroke-dasharray:none" + id="rect4803-0" + width="130" + height="40" + x="285" + y="622.51971" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="295" + y="652.51971" + id="text4462-9"><tspan + sodipodi:role="line" + id="tspan4460-3" + x="295" + y="652.51971">Block 2</tspan></text> + </g> + <g + id="g187" + transform="translate(-78.333344,49.999988)" + inkscape:transform-center-x="-18.216351" + inkscape:transform-center-y="-9.9361914"> + <rect + style="fill:#000000;stroke-width:4.16333246;stroke-miterlimit:4;stroke-dasharray:none" + id="rect4803-6" + width="130" + height="40" + x="305" + y="722.51971" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="315" + y="752.51971" + id="text4462-0"><tspan + sodipodi:role="line" + id="tspan4460-6" + x="315" + y="752.51971">Block 3</tspan></text> + </g> + <g + transform="translate(230,85)" + id="g242-5"> + <path + style="fill:#1a1a1a;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 45,607.51972 105,40 95,-40 -95,-40 z" + id="path145-6-3" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccc" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="100.79371" + y="604.76978" + id="text4458-7-5"><tspan + sodipodi:role="line" + id="tspan4456-5-6" + x="100.79371" + y="604.76978">Cond.</tspan><tspan + id="tspan200-2" + sodipodi:role="line" + x="100.79371" + y="644.76978"> 3</tspan></text> + </g> + <g + transform="translate(100,15)" + id="g242-9"> + <path + style="fill:#1a1a1a;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 45,607.51972 105,40 95,-40 -95,-40 z" + id="path145-6-1" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccc" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="100.79371" + y="604.76978" + id="text4458-7-2"><tspan + sodipodi:role="line" + id="tspan4456-5-7" + x="100.79371" + y="604.76978">Cond.</tspan><tspan + id="tspan200-0" + sodipodi:role="line" + x="100.79371" + y="644.76978"> 2</tspan></text> + </g> + <g + id="g187-9" + transform="translate(64.999996,49.999988)"> + <rect + style="fill:#000000;stroke-width:4.16333246;stroke-miterlimit:4;stroke-dasharray:none" + id="rect4803-6-3" + width="130" + height="40" + x="305" + y="722.51971" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" + x="315" + y="752.51971" + id="text4462-0-6"><tspan + sodipodi:role="line" + id="tspan4460-6-0" + x="315" + y="752.51971">Block 4</tspan></text> + </g> + <path + sodipodi:nodetypes="ccc" + inkscape:connector-curvature="0" + id="path4851-6-2-7" + d="m 215,552.51972 h 35 v 25" + style="fill:none;stroke:#ff0000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-4-1)" /> + <path + sodipodi:nodetypes="cc" + inkscape:connector-curvature="0" + id="path4851-6-2-7-0" + d="m 475,692.51971 v 75" + style="fill:none;stroke:#ff0000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-4-1-9)" /> + <path + inkscape:connector-curvature="0" + id="path4851-6-74-7" + d="M 140,622.51972 V 767.51971" + style="fill:none;stroke:#008000;stroke-width:2.89087248;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-5-2)" + sodipodi:nodetypes="cc" /> + <path + inkscape:connector-curvature="0" + id="path4851-6-74-7-2" + d="m 270,692.51972 v 74.99999" + style="fill:none;stroke:#008000;stroke-width:2.89087248;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-5-2-5)" + sodipodi:nodetypes="cc" /> + <path + sodipodi:nodetypes="ccc" + inkscape:connector-curvature="0" + id="path4851-6-2-7-6" + d="m 345,622.51972 h 35 v 25" + style="fill:none;stroke:#ff0000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-4-1-7)" /> + <path + inkscape:connector-curvature="0" + id="path4851-6-7-9" + d="m 140,812.5197 v 35" + style="fill:none;stroke:#000000;stroke-width:2.26778674;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-43-1)" + sodipodi:nodetypes="cc" /> + <path + inkscape:connector-curvature="0" + id="path4851-6-7-94" + d="m 475,812.51969 v 40 l -250,10e-6" + style="fill:none;stroke:#000000;stroke-width:2.26778674;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-43-3)" + sodipodi:nodetypes="ccc" /> + <path + inkscape:connector-curvature="0" + id="path4851-6-7-9-4" + d="m 270,812.5197 v 35" + style="fill:none;stroke:#000000;stroke-width:2.26778674;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#marker11618-6-43-1-7)" + sodipodi:nodetypes="cc" /> + <text + id="text141-5" + y="600.87445" + x="313.24542" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none" + xml:space="preserve"><tspan + id="tspan143-0" + y="600.87445" + x="313.24542" + sodipodi:role="line">false</tspan></text> + <text + id="text141-3" + y="666.28778" + x="420.88751" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none" + xml:space="preserve"><tspan + id="tspan143-6" + y="666.28778" + x="420.88751" + sodipodi:role="line">false</tspan></text> + <text + id="text135-1" + y="674.55524" + x="147.18663" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#008000;fill-opacity:1;stroke:none" + xml:space="preserve"><tspan + id="tspan137-0" + y="674.55524" + x="147.18663" + sodipodi:role="line">true</tspan></text> + <text + id="text135-6" + y="740.22369" + x="274.76639" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:32px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans';letter-spacing:0px;word-spacing:0px;fill:#008000;fill-opacity:1;stroke:none" + xml:space="preserve"><tspan + id="tspan137-3" + y="740.22369" + x="274.76639" + sodipodi:role="line">true</tspan></text> + </g> + <script + id="sozi-script" + ns1:version="14.10-05142318">function namespace(b,d,a){var c=b;d.split(".").forEach(function(e){if(typeof c[e]==="undefined"){c[e]={}}c=c[e]});if(a){a(c,b)}return c}namespace(this,"sozi.events",function(b){var a={};b.listen=function(c,d){if(!a.hasOwnProperty(c)){a[c]=[]}a[c].push(d)};b.fire=function(d){var c=Array.prototype.slice.call(arguments,1);if(a.hasOwnProperty(d)){a[d].forEach(function(e){e.apply(null,c)})}}});namespace(this,"sozi.proto",function(a){a.Object={installConstructors:function(){function b(){}b.prototype=this;this.instance=function(){var c=new b();c.construct.apply(c,arguments);return c};this.subtype=function(d){var c=new b();c.augment(d);c.installConstructors();return c}},construct:function(){},augment:function(c){for(var b in c){if(c.hasOwnProperty(b)){this[b]=c[b]}}return this},bind:function(c){var b=this;return function(){return c.apply(b,arguments)}}};a.Object.installConstructors()});namespace(this,"sozi.actions",function(A,g){var u=namespace(g,"sozi.player");var v=namespace(g,"sozi.display");var n=g.document;var o=0;var w=1;var t=1.05;var y=5;var m=5;var r=false;var i=0;var h=0;function a(C,B,D){u.stop();v.viewPorts.player.zoom(C>0?t:1/t,B,D)}function x(B){u.stop();v.viewPorts.player.rotate(B>0?y:-y)}function s(){if(sozi.framelist.isVisible()){sozi.framelist.hide();u.restart()}else{u.stop();sozi.framelist.show()}}function d(B){return v.viewPorts.player.contains(B.clientX,B.clientY)}function f(B){if(!d(B)){return}if(B.button===o){n.documentElement.addEventListener("mousemove",q,false);r=false;i=B.clientX;h=B.clientY}else{if(B.button===w){s()}}B.stopPropagation();B.preventDefault()}function q(B){if(!d(B)){return}u.stop();if(!r&&(Math.abs(B.clientX-i)>m||Math.abs(B.clientY-h)>m)){r=true}if(r){sozi.events.fire("sozi.player.cleanup");v.viewPorts.player.drag(B.clientX-i,B.clientY-h);i=B.clientX;h=B.clientY}B.stopPropagation()}function c(B){if(!d(B)){return}if(B.button===o){n.documentElement.removeEventListener("mousemove",q,false)}B.stopPropagation();B.preventDefault()}function p(B){if(!d(B)){return}u.moveToPrevious();B.stopPropagation();B.preventDefault()}function e(B){if(!d(B)){return}if(!r&&B.button!==w){u.moveToNext()}B.stopPropagation();B.preventDefault()}function j(B){if(!d(B)){return}if(!B){B=g.event}var C=0;if(B.wheelDelta){C=B.wheelDelta}else{if(B.detail){C=-B.detail}}if(C!==0){if(B.shiftKey){x(C)}else{a(C,B.clientX,B.clientY)}}B.stopPropagation();B.preventDefault()}function l(B){if(B.altKey||B.ctrlKey||B.metaKey){return}switch(B.charCode||B.which){case 43:a(1,g.innerWidth/2,g.innerHeight/2);break;case 45:a(-1,g.innerWidth/2,g.innerHeight/2);break;case 61:u.moveToCurrent();break;case 70:case 102:u.showAll();break;case 84:case 116:s();break;case 82:x(-1);break;case 114:x(1);break;default:return}B.stopPropagation();B.preventDefault()}function b(B){if(B.altKey||B.ctrlKey||B.metaKey){return}switch(B.keyCode){case 36:if(B.shiftKey){u.jumpToFirst()}else{u.moveToFirst()}break;case 35:if(B.shiftKey){u.jumpToLast()}else{u.moveToLast()}break;case 38:case 33:case 37:if(B.shiftKey){u.jumpToPrevious()}else{u.moveToPrevious()}break;case 40:case 34:case 39:case 13:case 32:if(B.shiftKey){u.jumpToNext()}else{u.moveToNext()}break;default:return}B.stopPropagation();B.preventDefault()}function z(B){B.stopPropagation()}function k(){var C=n.getElementsByTagName("a");for(var D=0;D<C.length;D+=1){C[D].addEventListener("click",z,false);C[D].addEventListener("contextmenu",z,false)}var B=n.documentElement;B.addEventListener("click",e,false);B.addEventListener("mousedown",f,false);B.addEventListener("mouseup",c,false);B.addEventListener("contextmenu",p,false);B.addEventListener("DOMMouseScroll",j,false);g.onmousewheel=j;B.addEventListener("keypress",l,false);B.addEventListener("keydown",b,false)}sozi.events.listen("sozi.display.ready",k)});namespace(this,"sozi.animation",function(d,g){var h=g.mozRequestAnimationFrame||g.webkitRequestAnimationFrame||g.msRequestAnimationFrame||g.oRequestAnimationFrame;var k=function(){return g.performance&&g.performance.now?g.performance.now():Date.now()};d.setAnimationFrameHandlers=function(l,m){h=l;k=m};var i=40;var c;var j=[];function e(){if(j.length>0){if(h){h(e)}j.forEach(function(l){l.step(k())})}else{if(!h){g.clearInterval(c)}}}function b(){if(h){h(e)}else{c=g.setInterval(function(){e(k())},i)}}function a(l){j.push(l);if(j.length===1){b()}}function f(l){j.splice(j.indexOf(l),1)}d.Animator=sozi.proto.Object.subtype({construct:function(){this.durationMs=0;this.data=null;this.initialTime=0;this.started=false},start:function(l,m){this.durationMs=l;this.data=m;this.initialTime=k();this.onStep(0);if(!this.started){this.started=true;a(this)}},stop:function(){if(this.started){f(this);this.started=false}},step:function(m){var l=m-this.initialTime;if(l>=this.durationMs){this.stop();this.onStep(1);this.onDone()}else{this.onStep(l/this.durationMs)}},onStep:function(l){},onDone:function(){}});d.profiles={linear:function(l){return l},accelerate:function(l){return Math.pow(l,3)},"strong-accelerate":function(l){return Math.pow(l,5)},decelerate:function(l){return 1-Math.pow(1-l,3)},"strong-decelerate":function(l){return 1-Math.pow(1-l,5)},"accelerate-decelerate":function(l){var m=l<=0.5?l:1-l,n=Math.pow(2*m,3)/2;return l<=0.5?n:1-n},"strong-accelerate-decelerate":function(l){var m=l<=0.5?l:1-l,n=Math.pow(2*m,5)/2;return l<=0.5?n:1-n},"decelerate-accelerate":function(l){var m=l<=0.5?l:1-l,n=(1-Math.pow(1-2*m,2))/2;return l<=0.5?n:1-n},"strong-decelerate-accelerate":function(l){var m=l<=0.5?l:1-l,n=(1-Math.pow(1-2*m,3))/2;return l<=0.5?n:1-n},"immediate-beginning":function(l){return 1},"immediate-end":function(l){return l===1?1:0},"immediate-middle":function(l){return l>=0.5?1:0}}});namespace(this,"sozi.display",function(c,g){var f="http://www.w3.org/2000/svg";var b="http://www.w3.org/1999/xlink";var i=g.document;var k;var h;var j;c.viewPorts={};var e;c.CameraState=sozi.proto.Object.subtype({construct:function(){this.cx=this.cy=0;this.width=this.height=1;this.angle=0;this.clipped=true;this.transitionZoomPercent=0;this.transitionProfile=sozi.animation.profiles.linear;this.transitionPath=null},setCenter:function(l,m){this.cx=l;this.cy=m;return this},setSize:function(m,l){this.width=m;this.height=l;return this},setClipped:function(l){this.clipped=l;return this},setAngle:function(l){this.angle=(l+180)%360-180;return this},setRawAngle:function(l){this.angle=l;return this},setTransitionZoomPercent:function(l){this.transitionZoomPercent=l;return this},setTransitionProfile:function(l){this.transitionProfile=l;return this},setTransitionPath:function(l){this.transitionPath=l;return this},setAtElement:function(p){var s,o,t,m;if(p.nodeName==="rect"){s=p.x.baseVal.value;o=p.y.baseVal.value;t=p.width.baseVal.value;m=p.height.baseVal.value}else{var q=p.getBBox();s=q.x;o=q.y;t=q.width;m=q.height}var n=i.documentElement.createSVGPoint();n.x=s+t/2;n.y=o+m/2;var r=p.getCTM();n=n.matrixTransform(r);var l=Math.sqrt(r.a*r.a+r.b*r.b);return this.setCenter(n.x,n.y).setSize(t*l,m*l).setAngle(Math.atan2(r.b,r.a)*180/Math.PI)},setAtState:function(l){return this.setCenter(l.cx,l.cy).setSize(l.width,l.height).setAngle(l.angle).setClipped(l.clipped).setTransitionZoomPercent(l.transitionZoomPercent).setTransitionProfile(l.transitionProfile).setTransitionPath(l.transitionPath)},interpolatableAttributes:["width","height","angle"],interpolate:function(n,o,t,v,r){var p=1-t;for(var q=0;q<this.interpolatableAttributes.length;q+=1){var s=this.interpolatableAttributes[q];this[s]=o[s]*t+n[s]*p}var l=r?n.transitionPath:o.transitionPath;if(v&&l){var x=l.getTotalLength();if(r){var m=l.getPointAtLength(x);var u=l.getPointAtLength(0);var w=l.getPointAtLength(x*p)}else{var m=l.getPointAtLength(0);var u=l.getPointAtLength(x);var w=l.getPointAtLength(x*t)}this.cx=w.x+(o.cx-u.x)*t+(n.cx-m.x)*p;this.cy=w.y+(o.cy-u.y)*t+(n.cy-m.y)*p}else{this.cx=o.cx*t+n.cx*p;this.cy=o.cy*t+n.cy*p}}});c.Camera=c.CameraState.subtype({construct:function(n,o){c.CameraState.construct.call(this);this.viewPort=n;this.svgClipRect=i.createElementNS(f,"rect");var m=i.createElementNS(f,"clipPath");m.setAttribute("id","sozi-clip-path-"+n.id+"-"+o);m.appendChild(this.svgClipRect);n.svgGroup.appendChild(m);var l=i.createElementNS(f,"g");l.setAttribute("clip-path","url(#sozi-clip-path-"+n.id+"-"+o+")");n.svgGroup.appendChild(l);if(n.isPrimary){this.svgLayer=i.createElementNS(f,"g");this.svgLayer.appendChild(i.getElementById(o))}else{this.svgLayer=i.createElementNS(f,"use");this.svgLayer.setAttributeNS(b,"href","#"+o)}l.appendChild(this.svgLayer)},setAtState:function(l){return c.CameraState.setAtState.call(this,l).update()},getScale:function(){return Math.min(this.viewPort.width/this.width,this.viewPort.height/this.height)},rotate:function(l){return this.setAngle(this.angle+l).update()},zoom:function(m,l,n){return this.setSize(this.width/m,this.height/m).drag((1-m)*(l-this.viewPort.width/2),(1-m)*(n-this.viewPort.height/2))},drag:function(m,l){var q=this.getScale();var o=this.angle*Math.PI/180;var n=Math.sin(o);var p=Math.cos(o);return this.setCenter(this.cx-(m*p-l*n)/q,this.cy-(m*n+l*p)/q).setClipped(false).update()},update:function(){var q=this.getScale();var n=this.width*q;var m=this.height*q;var l=(this.viewPort.width-n)/2;var r=(this.viewPort.height-m)/2;this.svgClipRect.setAttribute("x",this.clipped?l:0);this.svgClipRect.setAttribute("y",this.clipped?r:0);this.svgClipRect.setAttribute("width",this.clipped?n:this.viewPort.width);this.svgClipRect.setAttribute("height",this.clipped?m:this.viewPort.height);var p=-this.cx+this.width/2+l/q;var o=-this.cy+this.height/2+r/q;this.svgLayer.setAttribute("transform","scale("+q+")translate("+p+","+o+")rotate("+(-this.angle)+","+this.cx+","+this.cy+")");return this}});c.ViewPort=sozi.proto.Object.subtype({construct:function(n,m,l){this.id=n;c.viewPorts[n]=this;this.isPrimary=!!l;if(this.isPrimary){if(e){throw"Failed to create a primary viewport. A primary viewport already exists."}else{e=this}}this.svgGroup=i.createElementNS(f,"g");this.svgGroup.setAttribute("class","sozi-viewport");this.svgGroup.setAttribute("id","sozi-viewport-"+n);i.documentElement.appendChild(this.svgGroup);this.setLocation(0,0).setSize(g.innerWidth,g.innerHeight);this.cameras={};m.forEach(function(o){this.cameras[o]=c.Camera.instance(this,o)},this)},setSize:function(m,l){this.width=m;this.height=l;return this},setLocation:function(l,m){this.x=l;this.y=m;return this},contains:function(l,m){return l>=this.x&&l<this.x+this.width&&m>=this.y&&m<this.y+this.height},getDocumentState:function(){var m=c.CameraState.instance().setCenter(k.x+k.width/2,k.y+k.height/2).setSize(k.width,k.height).setClipped(false);var l={};for(var n in this.cameras){l[n]=m}return l},update:function(){this.svgGroup.setAttribute("transform","translate("+this.x+","+this.y+")");for(var l in this.cameras){this.cameras[l].update()}return this},showFrame:function(l){for(var m in l.states){this.cameras[m].setAtState(l.states[m])}return this},drag:function(m,l){for(var n in this.cameras){this.cameras[n].drag(m,l)}return this},zoom:function(m,l,o){for(var n in this.cameras){this.cameras[n].zoom(m,l,o)}return this},rotate:function(l){for(var m in this.cameras){this.cameras[m].rotate(l)}return this},onWindowResize:function(m,l){this.setLocation(this.x*m,this.y*l).setSize(this.width*m,this.height*l).update()}});function d(){var l=i.documentElement;k=l.getBBox();h=g.innerWidth;j=g.innerHeight;l.setAttribute("width",h);l.setAttribute("height",j);sozi.events.fire("sozi.display.ready")}function a(){var l=i.documentElement;l.setAttribute("width",g.innerWidth);l.setAttribute("height",g.innerHeight);for(var m in c.viewPorts){c.viewPorts[m].onWindowResize(g.innerWidth/h,g.innerHeight/j)}h=g.innerWidth;j=g.innerHeight}sozi.events.listen("sozi.document.ready",d);g.addEventListener("resize",a,false)});namespace(this,"sozi.document",function(c,e){var g=e.document;var b="http://sozi.baierouge.fr";var d={title:"Untitled",sequence:"0",hide:"true",clip:"true","show-in-frame-list":"true","timeout-enable":"false","timeout-ms":"5000","transition-duration-ms":"1000","transition-zoom-percent":"0","transition-profile":"linear","transition-path-hide":"true"};var h=["g","image","path","rect","circle","ellipse","line","polyline","polygon","text","clippath"];c.frames=[];c.idLayerList=[];function j(l,k){return l.getAttributeNS(b,k)||d[k]}function i(o,p,k){var l=o.states[p]=o.states[p]||sozi.display.CameraState.instance();if(typeof l.transitionZoomPercent==="undefined"||k.hasAttributeNS(b,"transition-zoom-percent")){l.setTransitionZoomPercent(parseInt(j(k,"transition-zoom-percent"),10))}if(typeof l.transitionProfile==="undefined"||k.hasAttributeNS(b,"transition-profile")){l.setTransitionProfile(sozi.animation.profiles[j(k,"transition-profile")])}if(typeof l.transitionPath==="undefined"||k.hasAttributeNS(b,"transition-path")){var n=g.getElementById(k.getAttributeNS(b,"transition-path"));if(n&&n.nodeName==="path"){l.setTransitionPath(n);if(j(k,"transition-path-hide")==="true"){n.style.visibility="hidden"}}}if(k.hasAttributeNS(b,"refid")){var m=g.getElementById(k.getAttributeNS(b,"refid"));if(m){l.setAtElement(m);if(j(k,"hide")==="true"){m.style.visibility="hidden"}}}if(k.hasAttributeNS(b,"clip")){l.setClipped(j(k,"clip")==="true")}}function a(){var l=[];var p=g.getElementsByTagNameNS(b,"layer");for(var n=0;n<p.length;n+=1){var s=p[n].getAttributeNS(b,"group");if(s&&l.indexOf(s)===-1){l.push(s)}}var r=g.documentElement;var o="http://www.w3.org/2000/svg";var q=g.createElementNS(o,"g");var k=Array.prototype.slice.call(r.childNodes);k.forEach(function(u,t){if(!u.getAttribute){r.removeChild(u)}else{if(l.indexOf(u.getAttribute("id"))!==-1){if(q.firstChild){q.setAttribute("id","sozi-wrapper-"+t);c.idLayerList.push("sozi-wrapper-"+t);r.insertBefore(q,u);q=g.createElementNS(o,"g")}c.idLayerList.push(u.getAttribute("id"))}else{if(h.indexOf(u.localName.toLowerCase())!==-1){r.removeChild(u);q.appendChild(u)}}}});if(q.firstChild){q.setAttribute("id","sozi-wrapper-"+k.length);c.idLayerList.push("sozi-wrapper-"+k.length);r.appendChild(q)}var m=Array.prototype.slice.call(g.getElementsByTagNameNS(b,"frame"));m.sort(function(u,t){var w=parseInt(j(u,"sequence"),10);var v=parseInt(j(t,"sequence"),10);return w-v});m.forEach(function(v,u){var x={id:v.getAttribute("id"),title:j(v,"title"),showInFrameList:j(v,"show-in-frame-list")==="true",sequence:parseInt(j(v,"sequence"),10),timeoutEnable:j(v,"timeout-enable")==="true",timeoutMs:parseInt(j(v,"timeout-ms"),10),transitionDurationMs:parseInt(j(v,"transition-duration-ms"),10),states:{}};c.idLayerList.forEach(function(A){if(u===0||A.search("sozi-wrapper-[0-9]+")!==-1){i(x,A,v)}else{var z=x.states[A]=sozi.display.CameraState.instance();var y=c.frames[c.frames.length-1].states[A];z.setAtState(y)}});var t=Array.prototype.slice.call(v.getElementsByTagNameNS(b,"layer"));t.forEach(function(y){var z=y.getAttributeNS(b,"group");if(z&&c.idLayerList.indexOf(z)!==-1){i(x,z,y)}});for(var w in x.states){if(x.states.hasOwnProperty(w)){c.frames.push(x);break}}})}c.getFrameIndexForId=function(l){for(var k=0;k<c.frames.length;k+=1){if(c.frames[k].id===l){return k}}return -1};function f(){g.documentElement.removeAttribute("viewBox");a();sozi.events.fire("sozi.document.ready")}e.addEventListener("load",f,false)});namespace(this,"sozi.framelist",function(u,k){var o=k.document;var c=5;var i;var p;var j=0;var h;var s;var b;var v;var w;var t;var e=300;var f="decelerate";var a="http://www.w3.org/2000/svg";function n(z){var x=z.relatedTarget,y=o.documentElement;while(x&&x!==i&&x!==y){x=x.parentNode}if(x!==i){u.hide();sozi.player.restart();z.stopPropagation()}}function r(y){var x=p.getCTM().f;if(x<=-k.innerHeight/2){x+=k.innerHeight/2}else{if(x<0){x=0}}p.setAttribute("transform","translate(0,"+x+")");y.stopPropagation()}function d(y){var x=p.getCTM().f;if(x+j>=k.innerHeight*3/2){x-=k.innerHeight/2}else{if(x+j>k.innerHeight+2*c){x=k.innerHeight-j-4*c}}p.setAttribute("transform","translate(0,"+x+")");y.stopPropagation()}function g(x){return function(y){sozi.player.previewFrame(x);y.stopPropagation()}}function l(x){x.stopPropagation()}function q(){i=o.createElementNS(a,"g");i.setAttribute("id","sozi-toc");o.documentElement.appendChild(i);p=o.createElementNS(a,"g");i.appendChild(p);var y=o.createElementNS(a,"rect");y.setAttribute("id","sozi-toc-background");y.setAttribute("x",c);y.setAttribute("y",c);y.setAttribute("rx",c);y.setAttribute("ry",c);y.addEventListener("click",l,false);y.addEventListener("mousedown",l,false);y.addEventListener("mouseout",n,false);p.appendChild(y);var A=0;sozi.document.frames.forEach(function(D,E){if(D.showInFrameList){var C=o.createElementNS(a,"text");C.appendChild(o.createTextNode(D.title));C.setAttribute("id","sozi-toc-"+D.id);p.appendChild(C);if(E===sozi.player.currentFrameIndex){C.setAttribute("class","sozi-toc-current")}var B=C.getBBox().width;j+=C.getBBox().height;if(B>A){A=B}C.setAttribute("x",2*c);C.setAttribute("y",j+c);C.addEventListener("click",g(E),false);C.addEventListener("mousedown",l,false)}});var x=o.createElementNS(a,"path");x.setAttribute("class","sozi-toc-arrow");x.setAttribute("d","M"+(A+3*c)+","+(5*c)+" l"+(4*c)+",0 l-"+(2*c)+",-"+(3*c)+" z");x.addEventListener("click",r,false);x.addEventListener("mousedown",l,false);i.appendChild(x);var z=o.createElementNS(a,"path");z.setAttribute("class","sozi-toc-arrow");z.setAttribute("d","M"+(A+3*c)+","+(7*c)+" l"+(4*c)+",0 l-"+(2*c)+","+(3*c)+" z");z.addEventListener("click",d,false);z.addEventListener("mousedown",l,false);i.appendChild(z);y.setAttribute("width",A+7*c);y.setAttribute("height",j+2*c);h=-A-9*c;s=0;w=v=h;i.setAttribute("transform","translate("+h+",0)");t=sozi.animation.Animator.instance().augment({onStep:function(B){var D=sozi.animation.profiles[f](B),C=1-D;w=v*D+b*C;i.setAttribute("transform","translate("+w+",0)")}})}function m(x){var y=Array.prototype.slice.call(o.getElementsByClassName("sozi-toc-current"));y.forEach(function(A){A.removeAttribute("class")});var z=sozi.document.frames[x];if(z.showInFrameList){o.getElementById("sozi-toc-"+z.id).setAttribute("class","sozi-toc-current")}}u.show=function(){o.documentElement.appendChild(i);b=w;v=s;t.start(e)};u.hide=function(){b=w;v=h;t.start(e)};u.isVisible=function(){return v===s};sozi.events.listen("sozi.player.ready",q);sozi.events.listen("sozi.player.cleanup",u.hide);sozi.events.listen("sozi.player.framechange",m)});namespace(this,"sozi.framenumber",function(a,d){var g=d.document;var e;var k,i;var f;var b="http://www.w3.org/2000/svg";function h(){var m=k.getBBox(),n=Math.max(m.width,m.height)*0.75,l=n*1.25;f.setAttribute("r",n);e.setAttribute("transform","translate("+l+","+l+")")}function c(){e=g.createElementNS(b,"g");k=g.createElementNS(b,"text");f=g.createElementNS(b,"circle");e.setAttribute("id","sozi-framenumber");f.setAttribute("cx",0);f.setAttribute("cy",0);e.appendChild(f);i=g.createTextNode(sozi.player.currentFrameIndex+1);k.setAttribute("text-anchor","middle");k.setAttribute("dominant-baseline","central");k.setAttribute("x",0);k.setAttribute("y",0);k.appendChild(i);e.appendChild(k);g.documentElement.appendChild(e);h()}function j(l){i.nodeValue=l+1}sozi.events.listen("sozi.player.ready",c);sozi.events.listen("sozi.player.framechange",j)});namespace(this,"sozi.links",function(c,e){var b="http://www.w3.org/2000/svg";var a="http://www.w3.org/1999/xlink";function f(g){return function(h){sozi.player.moveToFrame(g);h.preventDefault();h.stopPropagation()}}function d(){var h=e.document.getElementsByTagNameNS(b,"a");for(var j=0;j<h.length;j+=1){var g=h[j].getAttributeNS(a,"href");if(g&&g[0]==="#"){h[j].addEventListener("click",f(sozi.location.getFrameIndexForHash(g)),false)}}}sozi.events.listen("sozi.document.ready",d)});namespace(this,"sozi.location",function(a,d){var b=false;a.getFrameIndex=function(){return a.getFrameIndexForHash(d.location.hash)};a.getFrameIndexForHash=function(g){var h=g?g.slice(1):"1";var f;if(/^[0-9]+$/.test(h)){f=parseInt(h,10)-1}else{f=sozi.document.getFrameIndexForId(h)}if(f<0){return 0}else{if(f>=sozi.document.frames.length){return sozi.document.frames.length-1}else{return f}}};function e(){var f=a.getFrameIndex();if(!b){sozi.player.moveToFrame(f)}b=false}function c(f){b=true;d.location.hash="#"+sozi.document.frames[f].id}d.addEventListener("hashchange",e,false);sozi.events.listen("sozi.player.framechange",c)});namespace(this,"sozi.player",function(d,g){var l;var c;var i;var e=500;var n=-10;var j="linear";var f=0;d.currentFrameIndex=0;var k=false;var m=false;function h(){if(sozi.document.frames[d.currentFrameIndex].timeoutEnable){m=true;var o=(d.currentFrameIndex+1)%sozi.document.frames.length;i=g.setTimeout(function(){d.moveToFrame(o)},sozi.document.frames[d.currentFrameIndex].timeoutMs)}}d.startFromIndex=function(o){k=true;m=false;f=o;d.currentFrameIndex=o;l.showFrame(sozi.document.frames[o]);h()};d.restart=function(){d.startFromIndex(d.currentFrameIndex)};d.stop=function(){c.stop();if(m){g.clearTimeout(i);m=false}k=false;f=d.currentFrameIndex};function b(o,y,w){var z={ss:((o<0)?Math.max(y,w):Math.min(y,w))*(100-o)/100,ts:0.5,k:0};if(o!==0){var s=y-w;var r=y-z.ss;var q=w-z.ss;if(s!==0){var p=Math.sqrt(r*q);var x=(r-p)/s;var t=(r+p)/s;z.ts=(x>0&&x<=1)?x:t}z.k=r/z.ts/z.ts}return z}d.jumpToFrame=function(o){d.stop();sozi.events.fire("sozi.player.cleanup");f=o;d.currentFrameIndex=o;l.showFrame(sozi.document.frames[o]);sozi.events.fire("sozi.player.framechange",o)};d.getAnimationData=function(o,q,s,p,v,t){var r={};for(var w in o){r[w]={initialState:sozi.display.CameraState.instance(),finalState:sozi.display.CameraState.instance(),useTransitionPath:v,reverseTransitionPath:t};r[w].profile=p||q[w].transitionProfile;r[w].initialState.setAtState(o[w]);if(q.hasOwnProperty(w)){r[w].finalState.setAtState(q[w])}else{r[w].finalState.setAtState(o[w])}if(r[w].finalState.angle-r[w].initialState.angle>180){r[w].finalState.setRawAngle(r[w].finalState.angle-360)}else{if(r[w].finalState.angle-r[w].initialState.angle<-180){r[w].initialState.setRawAngle(r[w].initialState.angle-360)}}var u=s||q[w].transitionZoomPercent;if(u&&q.hasOwnProperty(w)){r[w].zoomWidth=b(u,o[w].width,q[w].width);r[w].zoomHeight=b(u,o[w].height,q[w].height)}}return r};d.previewFrame=function(o){d.currentFrameIndex=o;c.start(e,d.getAnimationData(l.cameras,sozi.document.frames[o].states,n,sozi.animation.profiles[j]),false,false);sozi.events.fire("sozi.player.framechange",o)};d.moveToFrame=function(r){if(m){g.clearTimeout(i);m=false}var q,t,s,p,o;if(r===(d.currentFrameIndex-1)%sozi.document.frames.length){q=sozi.document.frames[d.currentFrameIndex].transitionDurationMs;t=undefined;s=undefined;p=true;o=true}else{if(r===(d.currentFrameIndex+1)%sozi.document.frames.length){q=sozi.document.frames[r].transitionDurationMs;t=undefined;s=undefined;p=true;o=false}else{q=e;t=n;s=sozi.animation.profiles[j];p=false;o=false}}sozi.events.fire("sozi.player.cleanup");k=true;d.currentFrameIndex=r;c.start(q,d.getAnimationData(l.cameras,sozi.document.frames[r].states,t,s,p,o));sozi.events.fire("sozi.player.framechange",r)};d.jumpToFirst=function(){d.jumpToFrame(0)};d.moveToFirst=function(){d.moveToFrame(0)};d.jumpToPrevious=function(){var o=d.currentFrameIndex;if(!c.started||f<=d.currentFrameIndex){o-=1}if(o>=0){d.jumpToFrame(o)}};d.moveToPrevious=function(){for(var o=d.currentFrameIndex-1;o>=0;o-=1){var p=sozi.document.frames[o];if(!p.timeoutEnable||p.timeoutMs!==0){d.moveToFrame(o);break}}};d.jumpToNext=function(){var o=d.currentFrameIndex;if(!c.started||f>=d.currentFrameIndex){o+=1}if(o<sozi.document.frames.length){d.jumpToFrame(o)}};d.moveToNext=function(){if(d.currentFrameIndex<sozi.document.frames.length-1||sozi.document.frames[d.currentFrameIndex].timeoutEnable){d.moveToFrame((d.currentFrameIndex+1)%sozi.document.frames.length)}};d.jumpToLast=function(){d.jumpToFrame(sozi.document.frames.length-1)};d.moveToLast=function(){d.moveToFrame(sozi.document.frames.length-1)};d.moveToCurrent=function(){d.moveToFrame(d.currentFrameIndex)};d.showAll=function(){d.stop();sozi.events.fire("sozi.player.cleanup");c.start(e,d.getAnimationData(l.cameras,l.getDocumentState(),n,sozi.animation.profiles[j],false,false))};function a(){l=sozi.display.ViewPort.instance("player",sozi.document.idLayerList,true);d.startFromIndex(sozi.location.getFrameIndex());g.setTimeout(l.bind(l.update),1);sozi.events.fire("sozi.player.ready")}d.onAnimationStep=function(o,q){for(var s in q){var p=l.cameras[s];p.interpolate(q[s].initialState,q[s].finalState,q[s].profile(o),q[s].useTransitionPath,q[s].reverseTransitionPath);var r;if(q[s].zoomWidth&&q[s].zoomWidth.k!==0){r=o-q[s].zoomWidth.ts;p.width=q[s].zoomWidth.k*r*r+q[s].zoomWidth.ss}if(q[s].zoomHeight&&q[s].zoomHeight.k!==0){r=o-q[s].zoomHeight.ts;p.height=q[s].zoomHeight.k*r*r+q[s].zoomHeight.ss}p.setClipped(q[s].finalState.clipped)}l.update()};c=sozi.animation.Animator.instance().augment({onStep:function(o){d.onAnimationStep(o,this.data)},onDone:function(){for(var o in this.data){l.cameras[o].setAtState(this.data[o].finalState)}l.update();f=d.currentFrameIndex;if(k){h()}}});sozi.events.listen("sozi.display.ready",a)});</script> + <style + id="sozi-style" + ns1:version="14.10-05142318">#sozi-toc text{fill:#eff;font-family:Verdana,sans-serif;font-size:12pt}#sozi-toc text:hover{fill:#0cf;cursor:pointer}#sozi-toc text.sozi-toc-current{fill:#fa4}#sozi-toc-background{stroke:#222;stroke-opacity:.1;stroke-width:10;fill:#222;fill-opacity:.9}.sozi-toc-arrow{fill:#eff;fill-opacity:.75;stroke:none}.sozi-toc-arrow:hover{fill:#0cf}#sozi-framenumber circle{stroke:#222;stroke-opacity:.1;stroke-width:4;fill:#222;fill-opacity:.9}#sozi-framenumber text{fill:#eff;font-family:Verdana,sans-serif;font-size:12pt}</style> + <ns1:frame + ns1:refid="rect10351" + ns1:title="Gcd implementation" + ns1:sequence="1" + ns1:hide="true" + ns1:clip="true" + ns1:show-in-frame-list="true" + ns1:timeout-enable="false" + ns1:timeout-ms="5000.0" + ns1:transition-duration-ms="1000.0" + ns1:transition-zoom-percent="0.0" + ns1:transition-profile="linear" + ns1:transition-path-hide="true" /> + <ns1:frame + ns1:transition-path-hide="true" + ns1:transition-profile="linear" + ns1:transition-zoom-percent="0.0" + ns1:transition-duration-ms="1000.0" + ns1:timeout-ms="5000.0" + ns1:timeout-enable="false" + ns1:show-in-frame-list="true" + ns1:clip="true" + ns1:hide="true" + ns1:sequence="2" + ns1:title="Gcd maven packaging" + ns1:refid="rect10841" /> + <ns1:frame + ns1:refid="rect11089" + ns1:title="Using Math.getGcd()" + ns1:sequence="3" + ns1:hide="true" + ns1:clip="true" + ns1:show-in-frame-list="true" + ns1:timeout-enable="false" + ns1:timeout-ms="5000.0" + ns1:transition-duration-ms="1000.0" + ns1:transition-zoom-percent="0.0" + ns1:transition-profile="linear" + ns1:transition-path-hide="true" /> + <ns1:frame + ns1:transition-path-hide="true" + ns1:transition-profile="linear" + ns1:transition-zoom-percent="0.0" + ns1:transition-duration-ms="1000.0" + ns1:timeout-ms="5000.0" + ns1:timeout-enable="false" + ns1:show-in-frame-list="true" + ns1:clip="true" + ns1:hide="true" + ns1:sequence="4" + ns1:title="Fraction project" + ns1:refid="rect11381" /> + <ns1:frame + ns1:refid="rect11637" + ns1:title="Maven dependency definition" + ns1:sequence="5" + ns1:hide="true" + ns1:clip="true" + ns1:show-in-frame-list="true" + ns1:timeout-enable="false" + ns1:timeout-ms="5000.0" + ns1:transition-duration-ms="1000.0" + ns1:transition-zoom-percent="0.0" + ns1:transition-profile="linear" + ns1:transition-path-hide="true" /> + <ns1:frame + ns1:transition-path-hide="true" + ns1:transition-profile="linear" + ns1:transition-zoom-percent="0" + ns1:transition-duration-ms="1000" + ns1:timeout-ms="5000" + ns1:timeout-enable="false" + ns1:show-in-frame-list="true" + ns1:clip="true" + ns1:hide="true" + ns1:sequence="6" + ns1:title="Fraction depends on Gcd" + ns1:refid="rect11895" /> +</svg> diff --git a/Doc/Sd1/coreClasses.xml b/Doc/Sd1/coreClasses.xml index cbc21c705..f0eedab1e 100644 --- a/Doc/Sd1/coreClasses.xml +++ b/Doc/Sd1/coreClasses.xml @@ -1,13 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<chapter version="5.1" xml:id="sw1ChapterCoreClasses" - xmlns="http://docbook.org/ns/docbook" - xmlns:xlink="http://www.w3.org/1999/xlink" - xmlns:xi="http://www.w3.org/2001/XInclude" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns:ns="http://docbook.org/ns/transclusion" - xmlns:m="http://www.w3.org/1998/Math/MathML" - xmlns:html="http://www.w3.org/1999/xhtml" - xmlns:db="http://docbook.org/ns/docbook"> +<chapter version="5.1" xml:id="sw1ChapterCoreClasses" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="http://docbook.org/ns/transclusion" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:db="http://docbook.org/ns/docbook"> <title>Core Classes</title> <section xml:id="sd1SectVarargsFormat"> @@ -17,12 +9,7 @@ <qandadiv> <qandaentry> <question> - <para>This exercise aims at a better understanding of - <code>System.out.<link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format()</link></code> - already being used in <xref - linkend="sd1SectIntermediateMultiplication"/> and other exercises. - Consider the following snippet:</para> + <para>This exercise aims at a better understanding of <code>System.out.<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format()</link></code> already being used in <xref linkend="sd1QandaSquareNumberTableFormatted"/> and other exercises. Consider the following snippet:</para> <programlisting language="java"> int value = 33; double secondValue = 114.317; @@ -31,10 +18,7 @@ System.out.format("An integer %3d and a double value %6.2f\n", value, secondValue);</programlisting> - <para>Something seems to be odd here: The format() method is being - called with a different number of arguments. Actually we may call - it with an arbitrary number of one or more arguments. Answer the - following two questions:</para> + <para>Something seems to be odd here: The format() method is being called with a different number of arguments. Actually we may call it with an arbitrary number of one or more arguments. Answer the following two questions:</para> <orderedlist> <listitem> @@ -42,8 +26,7 @@ </listitem> <listitem> - <para>What is the role of the <quote>%...</quote> format - strings?</para> + <para>What is the role of the <quote>%...</quote> format strings?</para> </listitem> </orderedlist> </question> @@ -51,32 +34,13 @@ <answer> <orderedlist> <listitem> - <para>At first sight these method calls appear as if the - format() method had been multiply overloaded. This observation - is misleading despite the fact that a related <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.util.Locale-java.lang.String-java.lang.Object...-">overloaded - method</link> providing an additional locale argument does - indeed exist.</para> - - <para>According to <code>System.out.<methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format(...)</methodname></code> - the first argument must be of type <code - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</code>. - Additional arguments of <emphasis>arbitrary</emphasis> type - may be added in accordance with the <quote>%...</quote> <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax">format - strings</link> inside the first argument. It uses the - <acronym>varargs</acronym> mechanism being described in the - <link - xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc2_html_5#toc2">Java - classes section of chapter 4</link>.</para> + <para>At first sight these method calls appear as if the format() method had been multiply overloaded. This observation is misleading despite the fact that a related <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.util.Locale-java.lang.String-java.lang.Object...-">overloaded method</link> providing an additional locale argument does indeed exist.</para> + + <para>According to <code>System.out.<methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format(...)</methodname></code> the first argument must be of type <code xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</code>. Additional arguments of <emphasis>arbitrary</emphasis> type may be added in accordance with the <quote>%...</quote> <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax">format strings</link> inside the first argument. It uses the <acronym>varargs</acronym> mechanism being described in the <link xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc2_html_5#toc2">Java classes section of chapter 4</link>.</para> </listitem> <listitem> - <para>There is a one to one correspondence between each %... - format string and a corresponding argument. Thus if n further - arguments exist the format string must contain at least n - <quote>%</quote> format specifiers.</para> + <para>There is a one to one correspondence between each %... format string and a corresponding argument. Thus if n further arguments exist the format string must contain at least n <quote>%</quote> format specifiers.</para> </listitem> </orderedlist> @@ -92,16 +56,13 @@ <screen>v=33, d=114.32, color=ff</screen> - <para>We may prettify our code to better reflect the one to one - correspondence between format strings and variables:</para> + <para>We may prettify our code to better reflect the one to one correspondence between format strings and variables:</para> <programlisting language="java"> System.out.format("v=%d, d=%5.2f, color=%2x\n", v, d, color);</programlisting> <caution> - <para>A failure in providing appropriate numbers of arguments - having appropriate types likely results in a runtime - exception:</para> + <para>A failure in providing appropriate numbers of arguments having appropriate types likely results in a runtime exception:</para> <programlisting language="java">System.out.format("v=%d, d=%d, color=%2x\n", // Error: Using %s // rather than %f. @@ -118,25 +79,17 @@ java.util.IllegalFormatConversionException: <emphasis role="bold">d != java.lang </section> <section xml:id="sw1SectionCoreClassesUsingMath"> - <title>Using class <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname></title> + <title>Using class <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname></title> - <para><classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname> - is yet another class belonging to the core set of the <xref - linkend="glo_Java"/> programing language.</para> + <para><classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname> is yet another class belonging to the core set of the <xref linkend="glo_Java"/> programing language.</para> <qandaset defaultlabel="qanda" xml:id="sw1QandaCircleAreaMathPackage"> - <title>Using constants from <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">java.lang.Math</classname>.</title> + <title>Using constants from <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">java.lang.Math</classname>.</title> <qandadiv> <qandaentry> <question> - <para>In Exercise <xref linkend="sw1QandaCircleAreaFinal"/> you - calculated a given circle's area protecting variables against - accidental redefinition using the <code>final</code> - modifier:</para> + <para>In Exercise <xref linkend="sw1QandaCircleAreaFinal"/> you calculated a given circle's area protecting variables against accidental redefinition using the <code>final</code> modifier:</para> <programlisting language="java">public static void main(String[] args) { @@ -148,23 +101,14 @@ java.util.IllegalFormatConversionException: <emphasis role="bold">d != java.lang System.out.println(area); }</programlisting> - <para>You may have wondered why you had to punch in the value of - <inlineequation> + <para>You may have wondered why you had to punch in the value of <inlineequation> <m:math display="inline"> <m:mi>π</m:mi> </m:math> - </inlineequation> yourself. Actually <xref linkend="glo_Java"/> - predefines constants in <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">java.lang.Math</classname> - class. Read its documentation to rewrite your code thereby - replacing your own variable <code>pi</code>'s definition .</para> + </inlineequation> yourself. Actually <xref linkend="glo_Java"/> predefines constants in <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">java.lang.Math</classname> class. Read its documentation to rewrite your code thereby replacing your own variable <code>pi</code>'s definition .</para> <tip> - <para>You may want to read the <quote - xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc11_html_2">Static - Members</quote> and <quote - xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc6_html_4">Java - Packages</quote> sections .</para> + <para>You may want to read the <quote xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc11_html_2">Static Members</quote> and <quote xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc6_html_4">Java Packages</quote> sections .</para> </tip> </question> @@ -179,16 +123,9 @@ java.util.IllegalFormatConversionException: <emphasis role="bold">d != java.lang System.out.println(area); }</programlisting> - <para>In case you bother about using the somewhat clumsy <varname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI">Math.PI</varname> - expression rather than just using <varname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI">PI</varname> - itself some syntactic sugar is on offer by means of a <link - xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc13_html">static - import</link> statement:</para> + <para>In case you bother about using the somewhat clumsy <varname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI">Math.PI</varname> expression rather than just using <varname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI">PI</varname> itself some syntactic sugar is on offer by means of a <link xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc13_html">static import</link> statement:</para> - <programlisting language="java" linenumbering="unnumbered"><emphasis - role="bold">import static java.lang.Math.PI;</emphasis> + <programlisting language="java" linenumbering="unnumbered"><emphasis role="bold">import static java.lang.Math.PI;</emphasis> public class CircleAreaCalculator { @@ -196,16 +133,12 @@ public class CircleAreaCalculator { double radius = 2.31; // A circle having a radius (given e.g. in mm). - final double area = <emphasis role="bold">PI</emphasis> * radius * radius; // <emphasis - role="bold">This actually refers to Math.PI</emphasis> + final double area = <emphasis role="bold">PI</emphasis> * radius * radius; // <emphasis role="bold">This actually refers to Math.PI</emphasis> System.out.println(area); } }</programlisting> - <para>We dig a little deeper to fully understand the underlying - concepts. Obtaining a <xref linkend="glo_JDK"/>'s source code and - browsing its implementation <filename>Math.java</filename> - reveals:</para> + <para>We dig a little deeper to fully understand the underlying concepts. Obtaining a <xref linkend="glo_JDK"/>'s source code and browsing its implementation <filename>Math.java</filename> reveals:</para> <programlisting language="java">/* * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. @@ -226,16 +159,11 @@ public final class Math { <emphasis role="bold">public static final double PI = 3.14159265358979323846;</emphasis> ...</programlisting> - <para>This accounts for using the expression <code><varname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#field.summary">Math.PI</varname></code>.</para> + <para>This accounts for using the expression <code><varname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#field.summary">Math.PI</varname></code>.</para> - <para>The careful reader may have expected an <code>import</code> - statement in order to use the <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname> - class:</para> + <para>The careful reader may have expected an <code>import</code> statement in order to use the <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname> class:</para> - <programlisting language="java">import java.lang.<emphasis - role="bold">Math</emphasis>; // Optional: Classes from java.lang are imported + <programlisting language="java">import java.lang.<emphasis role="bold">Math</emphasis>; // Optional: Classes from java.lang are imported // implicitely as per the Java language specification. public class CircleAreaCalculator { @@ -249,12 +177,7 @@ public class CircleAreaCalculator { } }</programlisting> - <para>But since the <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html">Math</classname> - class belongs to the <package - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/package-frame.html">java.lang</package> - package it is present by default and does not have to be - imported.</para> + <para>But since the <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html">Math</classname> class belongs to the <package xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/package-frame.html">java.lang</package> package it is present by default and does not have to be imported.</para> </answer> </qandaentry> </qandadiv> @@ -268,18 +191,10 @@ public class CircleAreaCalculator { <qandadiv> <qandaentry> <question> - <para>Solve all remaining exercises from the <link - xlink:href="http://codingbat.com/java/String-1">String-1</link> - section and <link - xlink:href="http://codingbat.com/prob/p191914">Warmup-1 > - notString</link>. Then solve the examples from the <link - xlink:href="http://codingbat.com/java/String-2">String-2</link> - section.</para> + <para>Solve all remaining exercises from the <link xlink:href="http://codingbat.com/java/String-1">String-1</link> section and <link xlink:href="http://codingbat.com/prob/p191914">Warmup-1 > notString</link>. Then solve the examples from the <link xlink:href="http://codingbat.com/java/String-2">String-2</link> section.</para> <tip> - <para>You may want to use the Eclipse IDE and then copy/paste - your code to the CodingBat web interface to avoid tedious syntax - related fiddling.</para> + <para>You may want to use the Eclipse IDE and then copy/paste your code to the CodingBat web interface to avoid tedious syntax related fiddling.</para> </tip> </question> </qandaentry> @@ -294,12 +209,7 @@ public class CircleAreaCalculator { <qandadiv> <qandaentry> <question> - <para>In this exercise we go one step beyond <xref - linkend="sd1_qanda_exerciseEmoticons"/>. Consider the <xref - linkend="glo_unicode"/> emoticon definitions. Write a suitable - nested loop to mimic the <link - xlink:href="https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)#Block">emoticon - table</link>. Your output shall read:</para> + <para>In this exercise we go one step beyond <xref linkend="sd1_qanda_exerciseEmoticons"/>. Consider the <xref linkend="glo_unicode"/> emoticon definitions. Write a suitable nested loop to mimic the <link xlink:href="https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)#Block">emoticon table</link>. Your output shall read:</para> <mediaobject> <imageobject> @@ -308,17 +218,12 @@ public class CircleAreaCalculator { </mediaobject> <tip> - <para>The method <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html">StringBuffer</classname>.<methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html#appendCodePoint-int-">appendCodePoint</methodname> - allows the conversion of integer <xref linkend="glo_unicode"/> - values to the corresponding character sequence.</para> + <para>The method <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html">StringBuffer</classname>.<methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html#appendCodePoint-int-">appendCodePoint</methodname> allows the conversion of integer <xref linkend="glo_unicode"/> values to the corresponding character sequence.</para> </tip> </question> <answer> - <para>We need two nested loops creating the desired table by - traversing the <xref linkend="glo_unicode"/> block:</para> + <para>We need two nested loops creating the desired table by traversing the <xref linkend="glo_unicode"/> block:</para> <programlisting language="java"> public static void main(String[] args) { @@ -345,8 +250,7 @@ public class CircleAreaCalculator { <qandadiv> <qandaentry> <question> - <para>Consider the following string (excluding the - comment):</para> + <para>Consider the following string (excluding the comment):</para> <screen>73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 @@ -360,8 +264,7 @@ public class CircleAreaCalculator { 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 -821663704844031<emphasis role="bold">9989</emphasis>0008895243450658541227588666881 <co - xml:id="sw1Sequence9989"/> (boldface highlighting) +821663704844031<emphasis role="bold">9989</emphasis>0008895243450658541227588666881 <co xml:id="sw1Sequence9989"/> (boldface highlighting) 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 @@ -370,24 +273,16 @@ public class CircleAreaCalculator { 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450</screen> - <para>The above sequence is meant to form a single string which - has just been arranged in lines for convenience reasons.</para> + <para>The above sequence is meant to form a single string which has just been arranged in lines for convenience reasons.</para> - <para>In the above example the greatest product of four adjacent - digits is 9 × 9 × 8 × 9 = 5832 due to the presence of - <quote>9989</quote> <coref linkend="sw1Sequence9989"/></para> + <para>In the above example the greatest product of four adjacent digits is 9 × 9 × 8 × 9 = 5832 due to the presence of <quote>9989</quote> <coref linkend="sw1Sequence9989"/></para> - <para>Write a program that computes the maximum product value of - 13 adjacent digits within the above string.</para> + <para>Write a program that computes the maximum product value of 13 adjacent digits within the above string.</para> <tip> <orderedlist> <listitem> - <para>Representing the above string in a <xref - linkend="glo_Java"/> program may be cumbersome due to its - excessive length discouraging a single line representation. - You may favor assembling it from smaller string - literals:</para> + <para>Representing the above string in a <xref linkend="glo_Java"/> program may be cumbersome due to its excessive length discouraging a single line representation. You may favor assembling it from smaller string literals:</para> <programlisting language="java">final String input = "731671765 ... 94934" + ... @@ -395,20 +290,11 @@ public class CircleAreaCalculator { </listitem> <listitem> - <para>The <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> - class does contain a method to retrieve a substring starting - and ending at given index positions. Read its documentation - to find it.</para> + <para>The <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> class does contain a method to retrieve a substring starting and ending at given index positions. Read its documentation to find it.</para> </listitem> <listitem> - <para>The <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> - class does contain a method returning the <code - xlink:href="https://proquest.safaribooksonline.com/book/programming/java/9780992133047/chapter-2-language-fundamentals/toc3_html_3">char</code> - value at a given index. Read the documentation to find - it.</para> + <para>The <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> class does contain a method returning the <code xlink:href="https://proquest.safaribooksonline.com/book/programming/java/9780992133047/chapter-2-language-fundamentals/toc3_html_3">char</code> value at a given index. Read the documentation to find it.</para> </listitem> <listitem> @@ -419,14 +305,7 @@ public class CircleAreaCalculator { </question> <answer> - <para>We present a step by step solution. We start by coding a - loop creating the set of all substrings of length 13. Reading the - <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> - documentation the method<methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#substring-int-int-"> - substring(...)</methodname> allows for accessing the set of all - substrings of 13 adjacent digits:</para> + <para>We present a step by step solution. We start by coding a loop creating the set of all substrings of length 13. Reading the <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> documentation the method<methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#substring-int-int-"> substring(...)</methodname> allows for accessing the set of all substrings of 13 adjacent digits:</para> <programlisting language="java"> public static void main(String[] args) { final String @@ -469,13 +348,7 @@ public class CircleAreaCalculator { 3042075296345 0420752963450</screen> - <para>The method <methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#charAt-int-">charAt(int - index)</methodname> allows us to access each character within our - string individually. We need to write a method which converts a - digit like '4' to the value 4. Remember: The Unicode value of e.g. - character '4' equals its ASCII value which is just 52. Thus we - need a translation like:</para> + <para>The method <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#charAt-int-">charAt(int index)</methodname> allows us to access each character within our string individually. We need to write a method which converts a digit like '4' to the value 4. Remember: The Unicode value of e.g. character '4' equals its ASCII value which is just 52. Thus we need a translation like:</para> <programlisting language="java"> private static int getDigitValue (final char digit) { switch(digit) { @@ -496,10 +369,7 @@ public class CircleAreaCalculator { } }</programlisting> - <para>Next we must compute a given string's product of digits. - Taking the first value <code>7316717653133</code> from above we - are looking for 7 × 3 ×1 × 6 ×7 × 1 ×7 × 6 × 5 × 3 × 1 × 3 × 3 = - 5000940. We define:</para> + <para>Next we must compute a given string's product of digits. Taking the first value <code>7316717653133</code> from above we are looking for 7 × 3 ×1 × 6 ×7 × 1 ×7 × 6 × 5 × 3 × 1 × 3 × 3 = 5000940. We define:</para> <programlisting language="java"> private static int getDigitProduct(final String digitWord) { int product = 1; @@ -509,26 +379,11 @@ public class CircleAreaCalculator { return product; }</programlisting> - <para>Unfortunately this method sometimes returns weird results: - The argument <code>"5397536978179"</code> for example returns - -1594459696. This negative value is due to an arithmetic overflow: - The product 5 × 3 × 9 × 7 × 5 × 3 × 6 × 9 × 7 × 8 × 1 × 7 × 9 is - actually 2,700,507,600. This exceeds <code - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#MAX_VALUE">MAX_VALUE</code> - of 2,147,483,647 <link - xlink:href="https://proquest.safaribooksonline.com/book/programming/java/9780992133047/chapter-2-language-fundamentals/toc3_html_3">being - representable by a 4 byte <code>int</code> variable</link>.</para> - - <para>Luckily a <code>long</code> variable <link - xlink:href="https://proquest.safaribooksonline.com/book/programming/java/9780992133047/chapter-2-language-fundamentals/toc3_html_3">will - be able to hold positive values up to - 9,223,372,036,854,775,807</link>. This is much larger than our - <quote>worst case</quote> 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × - 9 × 9 × 9 = 2,541,865,828,329 value. We thus change our data type - from <code>int</code> to <code>long</code>:</para> - - <programlisting language="java"> private static <emphasis - role="bold">long</emphasis> getDigitProduct(final String digitWord) { + <para>Unfortunately this method sometimes returns weird results: The argument <code>"5397536978179"</code> for example returns -1594459696. This negative value is due to an arithmetic overflow: The product 5 × 3 × 9 × 7 × 5 × 3 × 6 × 9 × 7 × 8 × 1 × 7 × 9 is actually 2,700,507,600. This exceeds <code xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#MAX_VALUE">MAX_VALUE</code> of 2,147,483,647 <link xlink:href="https://proquest.safaribooksonline.com/book/programming/java/9780992133047/chapter-2-language-fundamentals/toc3_html_3">being representable by a 4 byte <code>int</code> variable</link>.</para> + + <para>Luckily a <code>long</code> variable <link xlink:href="https://proquest.safaribooksonline.com/book/programming/java/9780992133047/chapter-2-language-fundamentals/toc3_html_3">will be able to hold positive values up to 9,223,372,036,854,775,807</link>. This is much larger than our <quote>worst case</quote> 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 × 9 = 2,541,865,828,329 value. We thus change our data type from <code>int</code> to <code>long</code>:</para> + + <programlisting language="java"> private static <emphasis role="bold">long</emphasis> getDigitProduct(final String digitWord) { <emphasis role="bold">long</emphasis> product = 1; for (int i = 0; i < digitWord.length(); i++) { product *= getDigitValue(digitWord.charAt(i)); @@ -536,8 +391,7 @@ public class CircleAreaCalculator { return product; }</programlisting> - <para>Assembling these pieces leaves us with the following - <code>main(...)</code> method:</para> + <para>Assembling these pieces leaves us with the following <code>main(...)</code> method:</para> <programlisting language="java"> public static void main(String[] args) { @@ -545,10 +399,8 @@ public class CircleAreaCalculator { input = "73167176531330624919225119674426574742355349194934" + "96983520312774506326239578318016984801869478851843" + "85861560789112949495459501737958331952853208805511" - + "12540698747158523863050715693290963295227443043<emphasis - role="bold">557</emphasis>" - + "<emphasis role="bold">6689664895</emphasis>0445244523161731856403098711121722383113" <co - xml:id="sd1CoMaxProductSequence"/> + + "12540698747158523863050715693290963295227443043<emphasis role="bold">557</emphasis>" + + "<emphasis role="bold">6689664895</emphasis>0445244523161731856403098711121722383113" <co xml:id="sd1CoMaxProductSequence"/> + "62229893423380308135336276614282806444486645238749" + "30358907296290491560440772390713810515859307960866" + "70172427121883998797908792274921901699720888093776" @@ -580,11 +432,7 @@ public class CircleAreaCalculator { "' yields the largest product value " + getDigitProduct(maxDigitString) + "."); }</programlisting> - <para>The largest product of 13 successive digits stems from the - substring <code>"5576689664895</code>" <coref - linkend="sd1CoMaxProductSequence"/> starting with the last three - digits in the fourth definition line of <code>String input = - ...</code>.</para> + <para>The largest product of 13 successive digits stems from the substring <code>"5576689664895</code>" <coref linkend="sd1CoMaxProductSequence"/> starting with the last three digits in the fourth definition line of <code>String input = ...</code>.</para> <screen>The substring '5576689664895' yields the largest product value 23514624000.</screen> </answer> @@ -624,10 +472,7 @@ public class CircleAreaCalculator { </listitem> <listitem> - <para>Read the documentation of <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#identityHashCode-java.lang.Object-">System.identityHashCode(Object - o)</link> and <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--">Object.hashCode()</link>.</para> + <para>Read the documentation of <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#identityHashCode-java.lang.Object-">System.identityHashCode(Object o)</link> and <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--">Object.hashCode()</link>.</para> </listitem> </itemizedlist> </tip> @@ -636,82 +481,42 @@ public class CircleAreaCalculator { <answer> <para>Execution yields:</para> - <programlisting language="java">a1 == a2: true <co - linkends="answerCoStringOperatorEquality-1" - xml:id="answerCoStringOperatorEquality-1-co"/> + <programlisting language="java">a1 == a2: true <co linkends="answerCoStringOperatorEquality-1" xml:id="answerCoStringOperatorEquality-1-co"/> a1.equals(a2): true -b1 == b2: false <co linkends="answerCoStringOperatorEquality-2" - xml:id="answerCoStringOperatorEquality-2-co"/> +b1 == b2: false <co linkends="answerCoStringOperatorEquality-2" xml:id="answerCoStringOperatorEquality-2-co"/> b1.equals(b2): true </programlisting> <calloutlist> - <callout arearefs="answerCoStringOperatorEquality-1-co" - xml:id="answerCoStringOperatorEquality-1"> - <para>The string literal <code>"TestA"</code> is being - instantiated only once: The <xref linkend="glo_Java"/> - compiler implementation allocates only one instance of class - String per string literal.</para> - - <para>The string literal "TestA" (even if being defined within - different classes) always represents the same object. Thus the - two distinct variables <code>a1</code> and <code>a2</code> are - being assigned an identical reference pointing to this unique - instance. As per definition the operator == compares two - object references for equality and thus returns true. You - might as well write:</para> - - <programlisting language="java">System.out.println(<emphasis - role="bold">"TestA" == "TestA"</emphasis>);</programlisting> - - <para>The method <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#identityHashCode-java.lang.Object-">System.identityHashCode(Object - o)</link> returns <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--">Object.hashCode()</link> - rather then <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode--">String.hashCode()</link>. - This hash code from <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html">java.lang.Object</link> - has a one to one correspondence to an object's reference and - thus helps to understand the underlying object - references:</para> + <callout arearefs="answerCoStringOperatorEquality-1-co" xml:id="answerCoStringOperatorEquality-1"> + <para>The string literal <code>"TestA"</code> is being instantiated only once: The <xref linkend="glo_Java"/> compiler implementation allocates only one instance of class String per string literal.</para> + + <para>The string literal "TestA" (even if being defined within different classes) always represents the same object. Thus the two distinct variables <code>a1</code> and <code>a2</code> are being assigned an identical reference pointing to this unique instance. As per definition the operator == compares two object references for equality and thus returns true. You might as well write:</para> + + <programlisting language="java">System.out.println(<emphasis role="bold">"TestA" == "TestA"</emphasis>);</programlisting> + + <para>The method <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#identityHashCode-java.lang.Object-">System.identityHashCode(Object o)</link> returns <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--">Object.hashCode()</link> rather then <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode--">String.hashCode()</link>. This hash code from <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html">java.lang.Object</link> has a one to one correspondence to an object's reference and thus helps to understand the underlying object references:</para> <programlisting language="java">System.out.println("Hashcode a1 == " + System.identityHashCode(a1) + ", Hashcode a2 == " + System.identityHashCode(a2));</programlisting> <screen>Hashcode a1 == 366712642, Hashcode a2 == 366712642</screen> - <para>So <code>a1</code> and <code>a2</code> indeed point to - the same object resulting in true when using the <methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-">equals()</methodname> - method for comparison.</para> + <para>So <code>a1</code> and <code>a2</code> indeed point to the same object resulting in true when using the <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-">equals()</methodname> method for comparison.</para> </callout> - <callout arearefs="answerCoStringOperatorEquality-2-co" - xml:id="answerCoStringOperatorEquality-2"> - <para>Every call to the <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#String-java.lang.String-">String - constructor</link> will create a new string instance. Thus - <code>b1</code> and <code>b2</code> will hold two distinct - references pointing to different String instances albeit these - two instances contain identical values. Following the above - reasoning we may execute:</para> + <callout arearefs="answerCoStringOperatorEquality-2-co" xml:id="answerCoStringOperatorEquality-2"> + <para>Every call to the <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#String-java.lang.String-">String constructor</link> will create a new string instance. Thus <code>b1</code> and <code>b2</code> will hold two distinct references pointing to different String instances albeit these two instances contain identical values. Following the above reasoning we may execute:</para> <programlisting language="java">System.out.println("Hashcode b1 == " + System.identityHashCode(b1) + ", Hashcode b2 == " + System.identityHashCode(b2));</programlisting> - <para>This yields different values corresponding to two - different objects:</para> + <para>This yields different values corresponding to two different objects:</para> <screen>Hashcode b1 == 1829164700, Hashcode b2 == 2018699554</screen> - <para>Comparing these two reference values for equality the - <quote>==</quote> operator thus returns - <code>false</code>.</para> + <para>Comparing these two reference values for equality the <quote>==</quote> operator thus returns <code>false</code>.</para> - <para>The <methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-">equals()</methodname> - method however still returns a value of true since both - distinct objects carry an identical value.</para> + <para>The <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-">equals()</methodname> method however still returns a value of true since both distinct objects carry an identical value.</para> </callout> </calloutlist> </answer> @@ -746,16 +551,13 @@ b1.equals(b2): true </programlisting> <para>Execute the above code.</para> - <para>The following code differs only in the way the variable - <varname>name</varname> <coref - linkend="sd1CoNamedefByConcatMethod"/> is being defined:</para> + <para>The following code differs only in the way the variable <varname>name</varname> <coref linkend="sd1CoNamedefByConcatMethod"/> is being defined:</para> <programlisting language="java"> public static void main(String[] args) { final String reference = "Anton"; - <emphasis role="bold">final String name = "An".concat("ton");</emphasis> <co - xml:id="sd1CoNamedefByConcatMethod"/> + <emphasis role="bold">final String name = "An".concat("ton");</emphasis> <co xml:id="sd1CoNamedefByConcatMethod"/> System.out.println("Content:" + name); @@ -771,34 +573,23 @@ b1.equals(b2): true </programlisting> <tip> <orderedlist> <listitem> - <para>The <link - xlink:href="https://prog.mi.hdm-stuttgart.de/java_visualize">Java - visualizer</link> may be helpful.</para> + <para>The <link xlink:href="https://prog.mi.hdm-stuttgart.de/java_visualize">Java visualizer</link> may be helpful.</para> </listitem> <listitem> - <para>Think about compile time and run time - considerations.</para> + <para>Think about compile time and run time considerations.</para> </listitem> </orderedlist> </tip> </question> <answer> - <para>Having <code>name = "An" + "ton"</code> in place we - get:</para> + <para>Having <code>name = "An" + "ton"</code> in place we get:</para> <screen>Content:Anton <emphasis role="bold">Instances are equal</emphasis></screen> - <para>The Java compiler performs a clever optimization: The - expression <code>"An" + "ton"</code> is being evaluated at compile - time. Its value is identical to the string literal - <code>"Anton"</code> and thus both variables - <varname>name</varname> and <varname>reference</varname> will be - initialized to a common <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> - instance:</para> + <para>The Java compiler performs a clever optimization: The expression <code>"An" + "ton"</code> is being evaluated at compile time. Its value is identical to the string literal <code>"Anton"</code> and thus both variables <varname>name</varname> and <varname>reference</varname> will be initialized to a common <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> instance:</para> <informalfigure> <mediaobject> @@ -808,21 +599,12 @@ b1.equals(b2): true </programlisting> </mediaobject> </informalfigure> - <para>When starting from <code>name = "An".concat("ton")</code> - the result is different:</para> + <para>When starting from <code>name = "An".concat("ton")</code> the result is different:</para> <screen>Content:Anton <emphasis role="bold">Instances are not equal</emphasis></screen> - <para>This time the Java compiler is unable to dynamically resolve - the expression <code>"An".concat("ton")</code> at compile time. - Instead the method <methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#concat-java.lang.String-">concat(...)</methodname>will - be called at runtime resulting in a second <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> - instance which by coincidence contains an identical value. Thus - <varname>name</varname> and <varname>reference</varname> point to - different objects:</para> + <para>This time the Java compiler is unable to dynamically resolve the expression <code>"An".concat("ton")</code> at compile time. Instead the method <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#concat-java.lang.String-">concat(...)</methodname>will be called at runtime resulting in a second <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">String</classname> instance which by coincidence contains an identical value. Thus <varname>name</varname> and <varname>reference</varname> point to different objects:</para> <informalfigure> <mediaobject> @@ -844,13 +626,9 @@ b1.equals(b2): true </programlisting> <qandadiv> <qandaentry> <question> - <para>Regarding relative and absolute path specifications you may - want to read the first three paragraphs of section <quote>File - Systems and Paths</quote> in chapter 16.</para> + <para>Regarding relative and absolute path specifications you may want to read the first three paragraphs of section <quote>File Systems and Paths</quote> in chapter 16.</para> - <para>Depending on your operating system of choice absolute - (=fully qualified) filenames are being represented in different - ways:</para> + <para>Depending on your operating system of choice absolute (=fully qualified) filenames are being represented in different ways:</para> <glosslist> <glossentry> @@ -934,11 +712,7 @@ b1.equals(b2): true </programlisting> </glossentry> </glosslist> - <para>Implement a class <classname>FileMetaInfo</classname> to be - instantiated from ordinary strings describing absolute or relative - filenames. Your class shall have several immutable attributes - corresponding to the previously described values. Consider the - following usage example:</para> + <para>Implement a class <classname>FileMetaInfo</classname> to be instantiated from ordinary strings describing absolute or relative filenames. Your class shall have several immutable attributes corresponding to the previously described values. Consider the following usage example:</para> <programlisting language="java">public class WindowsExample { @@ -957,8 +731,7 @@ b1.equals(b2): true </programlisting> } }</programlisting> - <para>On a Windows system the following output is being - expected:</para> + <para>On a Windows system the following output is being expected:</para> <screen>Filename is relative? false Drive letter:C @@ -966,27 +739,19 @@ Directory path: \users\heinz\Desktop File basename: index File extension: html</screen> - <para>Due to the possible presence of drive letters Windows - pathnames are more difficult to parse. We illustrate a possible - strategy dissecting - <filename>C:\programms\openvpn\conf\hdm.ovpn</filename> into the - desired constituents:</para> + <para>Due to the possible presence of drive letters Windows pathnames are more difficult to parse. We illustrate a possible strategy dissecting <filename>C:\programms\openvpn\conf\hdm.ovpn</filename> into the desired constituents:</para> <glosslist> <glossentry> <glossterm>Decomposing path components:</glossterm> <glossdef> - <para><filename>C:\programms\openvpn\conf\hdm.ovpn</filename> - → {<code>"C:"</code>, <code>"programms"</code>, - <code>"openvpn"</code>, <code>"conf"</code>, - <code>"hdm.ovpn"</code>}.</para> + <para><filename>C:\programms\openvpn\conf\hdm.ovpn</filename> → {<code>"C:"</code>, <code>"programms"</code>, <code>"openvpn"</code>, <code>"conf"</code>, <code>"hdm.ovpn"</code>}.</para> </glossdef> </glossentry> <glossentry> - <glossterm>Drive letter string to character - conversion</glossterm> + <glossterm>Drive letter string to character conversion</glossterm> <glossdef> <para>"C:" → <code>'C'</code></para> @@ -997,8 +762,7 @@ File extension: html</screen> <glossterm>Decomposing filename (if required)</glossterm> <glossdef> - <para><code>"hdm.ovpn"</code> → {<code>"hdm"</code>, - <code>"ovpn"</code>}</para> + <para><code>"hdm.ovpn"</code> → {<code>"hdm"</code>, <code>"ovpn"</code>}</para> </glossdef> </glossentry> </glosslist> @@ -1006,93 +770,47 @@ File extension: html</screen> <tip> <orderedlist> <listitem> - <para>You will have to deal with absolute and relative (e.g. - <filename>../../Desktop/var.png</filename>) filename - specifications.</para> + <para>You will have to deal with absolute and relative (e.g. <filename>../../Desktop/var.png</filename>) filename specifications.</para> </listitem> <listitem> - <para>You will have to deal with files having no extensions - like e.g. <filename>/usr/bin/firefox</filename>. In this - case the <code>extension</code> attribute is expected to be - <code>null</code>.</para> + <para>You will have to deal with files having no extensions like e.g. <filename>/usr/bin/firefox</filename>. In this case the <code>extension</code> attribute is expected to be <code>null</code>.</para> </listitem> <listitem> - <para>For the sake of limiting complexity you do not have to - consider filenames starting with a period (like - <filename>/home/heinz/.bashrc</filename>) or containing - multiple periods like - <filename>../arrow.right.png</filename>.</para> + <para>For the sake of limiting complexity you do not have to consider filenames starting with a period (like <filename>/home/heinz/.bashrc</filename>) or containing multiple periods like <filename>../arrow.right.png</filename>.</para> </listitem> <listitem> - <para>To distinguish the above mentioned system defaults for - filename path conventions read the - <classname>java.lang.System</classname> section of chapter 5 - <link - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html">along - with its API</link>. The book's table of system properties - will enable your implementation to work both on Windows and - non-Windows systems accordingly.</para> + <para>To distinguish the above mentioned system defaults for filename path conventions read the <classname>java.lang.System</classname> section of chapter 5 <link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html">along with its API</link>. The book's table of system properties will enable your implementation to work both on Windows and non-Windows systems accordingly.</para> </listitem> <listitem> - <para>You will have to parse filenames like - <code>"/usr/share/openvpn/hdm.conf"</code>. Exercise 7 from - the <quote>Quiz</quote> section of chapter 5 shows an - example dissecting a string containing tokens being - separated by space characters using the <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/StringTokenizer.html">java.util.StringTokenizer</classname> - class. Read its documentation and learn how to specify - string delimiters other than default space <code>' '</code>. - It'll allow you to dissect paths using separators '/' (Unix) - or '\' (Windows) to break paths into components.</para> - - <para>Likewise you may split filenames into basename / - extension by using <code>'.'</code> as separator.</para> + <para>You will have to parse filenames like <code>"/usr/share/openvpn/hdm.conf"</code>. Exercise 7 from the <quote>Quiz</quote> section of chapter 5 shows an example dissecting a string containing tokens being separated by space characters using the <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/StringTokenizer.html">java.util.StringTokenizer</classname> class. Read its documentation and learn how to specify string delimiters other than default space <code>' '</code>. It'll allow you to dissect paths using separators '/' (Unix) or '\' (Windows) to break paths into components.</para> + + <para>Likewise you may split filenames into basename / extension by using <code>'.'</code> as separator.</para> </listitem> <listitem> - <para>Assembling path components may be effected by either - using a <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html">StringBuffer</classname> - or a <classname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/StringJoiner.html">StringJoiner</classname> - instance. Mind the distinction between relative and absolute - paths!</para> + <para>Assembling path components may be effected by either using a <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html">StringBuffer</classname> or a <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/StringJoiner.html">StringJoiner</classname> instance. Mind the distinction between relative and absolute paths!</para> </listitem> <listitem> - <para>The methods <methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-int-">indexOf(...)</methodname> - and <methodname - xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#substring-int-int-">substring(...)</methodname> - come in handy when dissecting filenames into basename and - extension.</para> + <para>The methods <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-int-">indexOf(...)</methodname> and <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#substring-int-int-">substring(...)</methodname> come in handy when dissecting filenames into basename and extension.</para> </listitem> <listitem> - <para>The backslash <quote>\</quote> must be escaped when - being part of a <xref linkend="glo_Java"/> String - literal:</para> + <para>The backslash <quote>\</quote> must be escaped when being part of a <xref linkend="glo_Java"/> String literal:</para> <screen> String path = "C:\\programms\\openvpn\\conf\\hdm.ovpn";</screen> </listitem> <listitem> - <para>Unit tests may be written for Windows and non-Windows - systems separately. Read <uri - xlink:href="https://www.thekua.com/atwork/2008/09/running-tests-on-a-specific-os-under-junit4">https://www.thekua.com/atwork/2008/09/running-tests-on-a-specific-os-under-junit4</uri> - how to use <methodname>Assume.assumeFalse()</methodname> / - <methodname>Assume.assumeTrue(...)</methodname> to separate - Windows from Unix tests.</para> + <para>Unit tests may be written for Windows and non-Windows systems separately. Read <uri xlink:href="https://www.thekua.com/atwork/2008/09/running-tests-on-a-specific-os-under-junit4">https://www.thekua.com/atwork/2008/09/running-tests-on-a-specific-os-under-junit4</uri> how to use <methodname>Assume.assumeFalse()</methodname> / <methodname>Assume.assumeTrue(...)</methodname> to separate Windows from Unix tests.</para> </listitem> <listitem> - <para>Test your implementation both on Windows and Unix-type - platforms. The following tests may be used as a starting - point:</para> + <para>Test your implementation both on Windows and Unix-type platforms. The following tests may be used as a starting point:</para> <programlisting language="java">public class MetaInfoUnixTest { diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index 99685bfc5..91ce12449 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -156,7 +156,7 @@ <title>The if conditional statement</title> <figure xml:id="sd1_fig_if"> - <title><code>if</code> ... <code>else</code> for block selection</title> + <title><code>if</code> block execution selection</title> <informaltable border="1"> <tr> @@ -178,7 +178,7 @@ if (100000 <= initialAmount) { </figure> <figure xml:id="sd1_fig_ifElse"> - <title><code>if</code> ... <code>else</code> for block selection</title> + <title><code>if</code> ... <code>else</code> block execution selection</title> <informaltable border="1"> <tr> @@ -227,36 +227,6 @@ if (100000 <= initialAmount) { </informaltable> </figure> - <figure xml:id="sd1_fig_IfElseIf"> - <title><code>if</code> ... <code>else if</code> ... <code>else</code> for block selection</title> - - <programlisting language="java">double initialAmount = 3200; - -if (100000 <= initialAmount) { // Rich customer, higher interest rate - System.out.println("Interest:" + 1.2 * initialAmount / 100); -} else if (1000 <= initialAmount){ // Joe customer, standard interest rate - System.out.println("Interest:" + 0.8 * initialAmount / 100); -} else { // Capitalism: Sorry, but ... - System.out.println("Interest:" + 0); -}</programlisting> - - <informaltable border="1"> - <tr> - <td><itemizedlist> - <listitem> - <para>One added branch per <code>else if</code></para> - </listitem> - </itemizedlist></td> - - <td><itemizedlist> - <listitem> - <para>May (still) have a final branch.</para> - </listitem> - </itemizedlist></td> - </tr> - </informaltable> - </figure> - <qandaset defaultlabel="qanda" xml:id="sd1_qanda_booleanEqual"> <title>Comparing for equality</title> @@ -359,7 +329,7 @@ int main(int argc, char **args) { <qandadiv> <qandaentry> <question> - <para>A computer newbie did not yet read about the <code>else if(...)</code> branch construct but nevertheless tries to implement the logic being shown in <xref linkend="sd1_fig_IfElseIf"/>. Please help by just using <code>if(...) ... else</code> statements!</para> + <para>A computer newbie did not yet read about the <code>else if(...)</code> branch construct but nevertheless tries to implement the logic being shown in <xref linkend="sd1_fig_ifElse"/>. Please help by just using <code>if(...)</code> (having no <code>else</code> branch) statements!</para> <tip> <para>As the title suggests you may want to use two nested <code>if</code> constructs.</para> @@ -617,6 +587,30 @@ System.out.println("Failed!");</programlisting> </qandadiv> </qandaset> + <figure xml:id="sd1_fig_ifElse_else"> + <title><code>if ... else if ... else</code></title> + + <informaltable border="1"> + <tr> + <td valign="top"><programlisting language="java">if ('A' == grade || 'B' == grade) { + result = "Excellent"; +} else if ('C' == grade) { + result = "O.k."; +} else if ('D' == grade) { + result = "Passed"; +} else { + result = "Failed"; +}</programlisting></td> + + <td valign="top"><mediaobject> + <imageobject> + <imagedata fileref="Ref/Statements/if_elseIf_else.svg"/> + </imageobject> + </mediaobject></td> + </tr> + </informaltable> + </figure> + <figure xml:id="sd1_fig_useScannerClass"> <title>User input by <link xlink:href="https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html">Scanner</link></title> @@ -628,6 +622,74 @@ System.out.println("You entered " + value);</programlisting> <para>See <methodname xlink:href="https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextBoolean()">nextBoolean()</methodname>, <methodname><link xlink:href="https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextByte()">nextByte()</link></methodname> and friends.</para> </figure> + <qandaset defaultlabel="qanda" xml:id="sw1QandaPostExamBonuspoints"> + <title>Post modifying an exam's marking</title> + + <qandadiv> + <qandaentry> + <question> + <para>After completely marking an examination a lecturer decides to globally add a number extra bonus points to a specific task . The task does have an upper limit of points to be awarded at maximum. We provide an example:</para> + + <para>On completely fulfilling a given task 12 points will be awarded. So after marking the exam participants' points range from 0 to 12 points being represented by the variable <code>pointsReached</code>.</para> + + <para>After completing his marking our lecturer wants to add three more points to all participants without breaching the 12 point limit.</para> + + <para>Complete the following code by assigning this modified number of points to the variable <code>newResult</code>.</para> + + <programlisting language="java"> public static void main(String[] args) { + + int pointsReached = 1; + int maximumPoints = 12; + int pointsToAdd = 3; + + final int newResult; + + // TODO: Assignment to variable newResult + + System.out.println("New Result:" + newResult); + }</programlisting> + </question> + + <answer> + <para>The basic task is to add up the values of <code>pointsReached</code> and <code>pointsToAdd</code>. When exceeding the limit we just assign the limit itself:</para> + + <programlisting language="java"> public static void main(String[] args) { + + int pointsReached = 1; + int maximumPoints = 12; + int pointsToAdd = 3; + + final int newResult; + + if (maximumPoints <= pointsReached + pointsToAdd) { + newResult = maximumPoints; + } else { + newResult = pointsReached + pointsToAdd; + } + + System.out.println("New Result:" + newResult); + }</programlisting> + + <para>This basically means calculating the minimum of the two expressions <code>pointsReached + pointsToAdd</code> and <code>maximumPoints</code>. This may as well be be implemented by:</para> + + <programlisting language="java"> public static void main(String[] args) { + + int pointsReached = 1; + int maximumPoints = 12; + int pointsToAdd = 3; + + final int newResult = Math.min(maximumPoints, pointsReached + pointsToAdd); + + System.out.println("New Result:" + newResult); + + }</programlisting> + + <para>You will fully understand the above expression <classname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html">Math</classname>.<methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#min-int-int-">min(...)</methodname> after finishing the <quote xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc12_html">Static Final Variables</quote> section.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + <qandaset defaultlabel="qanda" xml:id="sd1QandaAtTheBar"> <title>At the bar</title> @@ -740,77 +802,6 @@ public class BarOrder { </qandadiv> </qandaset> - <qandaset defaultlabel="qanda" xml:id="sd1QandaLeapYear"> - <title>Leap years</title> - - <qandadiv> - <qandaentry> - <question> - <para>We want to write an application telling whether a given year is a leap year or not. The following dialogue may serve as an example:</para> - - <screen>Enter a year:>1980 -Year 1980 is a leap year</screen> - - <screen>Enter a year:>1900 -Year 1900 is no leap year</screen> - - <para>You may reuse the user input handling code from the previous example .</para> - - <tip> - <para>Read about the Gregorian Calendar which defines rules governing leap years.</para> - </tip> - </question> - - <answer> - <para>A first straightforward rule translation based solution reads:</para> - - <programlisting language="java">package start; - -import java.util.Scanner; - -public class LeapYear { - - public static void main(String[] args) { - - final Scanner scan = new Scanner(System.in); // Read user input - System.out.print("Enter a year:>"); - final int year = scan.nextInt(); - scan.close(); - - if (0 == year % 400) { <emphasis role="bold"> // Every 400 years we do have a leap year.</emphasis> - System.out.println( - "Year " + year + " is a leap year"); - } else if (0 == year % 4 && <emphasis role="bold"> // Every 4 years we do have a leap year</emphasis> - 0 != year % 100) { <emphasis role="bold"> // unless year is a multiple of 100.</emphasis> - System.out.println("Year " + year + " is a leap year"); - } else { - System.out.println("Year " + year + " is no leap year"); - } - } -}</programlisting> - - <para>This solution contains two identical print statements. Developers don't favour redundancies. Combining the first two <code>if</code> branches into one resolves the issue:</para> - - <programlisting language="java"> public static void main(String[] args) { - - final Scanner scan = new Scanner(System.in); // Read user input - System.out.print("Enter a year:>"); - final int year = scan.nextInt(); - scan.close(); - - if (0 == year % 400 || <emphasis role="bold">// Every 400 years we do have a leap year.</emphasis> - (0 == year % 4 && <emphasis role="bold">// Every 4 years we do have a leap year</emphasis> - 0 != year % 100)) { <emphasis role="bold">// unless year is a multiple of 100.</emphasis> - System.out.println("Year " + year + " is a leap year"); - } else { - System.out.println("Year " + year + " is no leap year"); - } - }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - <qandaset defaultlabel="qanda" xml:id="sd1QandaRomanNumeralsIf"> <title>Roman numerals</title> @@ -1329,6 +1320,77 @@ Midweek</screen> </qandaentry> </qandadiv> </qandaset> + + <qandaset defaultlabel="qanda" xml:id="sd1QandaLeapYear"> + <title>Leap years</title> + + <qandadiv> + <qandaentry> + <question> + <para>We want to write an application telling whether a given year is a leap year or not. The following dialogue may serve as an example:</para> + + <screen>Enter a year:>1980 +Year 1980 is a leap year</screen> + + <screen>Enter a year:>1900 +Year 1900 is no leap year</screen> + + <para>You may reuse the user input handling code from the previous example .</para> + + <tip> + <para>Read about the Gregorian Calendar which defines rules governing leap years.</para> + </tip> + </question> + + <answer> + <para>A first straightforward rule translation based solution reads:</para> + + <programlisting language="java">package start; + +import java.util.Scanner; + +public class LeapYear { + + public static void main(String[] args) { + + final Scanner scan = new Scanner(System.in); // Read user input + System.out.print("Enter a year:>"); + final int year = scan.nextInt(); + scan.close(); + + if (0 == year % 400) { <emphasis role="bold"> // Every 400 years we do have a leap year.</emphasis> + System.out.println( + "Year " + year + " is a leap year"); + } else if (0 == year % 4 && <emphasis role="bold"> // Every 4 years we do have a leap year</emphasis> + 0 != year % 100) { <emphasis role="bold"> // unless year is a multiple of 100.</emphasis> + System.out.println("Year " + year + " is a leap year"); + } else { + System.out.println("Year " + year + " is no leap year"); + } + } +}</programlisting> + + <para>This solution contains two identical print statements. Developers don't favour redundancies. Combining the first two <code>if</code> branches into one resolves the issue:</para> + + <programlisting language="java"> public static void main(String[] args) { + + final Scanner scan = new Scanner(System.in); // Read user input + System.out.print("Enter a year:>"); + final int year = scan.nextInt(); + scan.close(); + + if (0 == year % 400 || <emphasis role="bold">// Every 400 years we do have a leap year.</emphasis> + (0 == year % 4 && <emphasis role="bold">// Every 4 years we do have a leap year</emphasis> + 0 != year % 100)) { <emphasis role="bold">// unless year is a multiple of 100.</emphasis> + System.out.println("Year " + year + " is a leap year"); + } else { + System.out.println("Year " + year + " is no leap year"); + } + }</programlisting> + </answer> + </qandaentry> + </qandadiv> + </qandaset> </section> <section xml:id="sd1_sect_loops"> @@ -1478,42 +1540,132 @@ Do not copy!</screen></td> </mediaobject></td> </tr> </informaltable> - </figure></para> + </figure><qandaset defaultlabel="qanda" xml:id="sd1_qanda_tellEvenOdd"> + <title>Even or odd?</title> + + <qandadiv> + <qandaentry> + <question> + <para>Write an application which asks for integer values telling its user whether a given value is even or odd. Providing the special value 0 shall terminate your application:</para> + + <screen>Enter an integer (0 to terminate): 77 + 77 is an odd number +Enter an integer (0 to terminate): -3 + -3 is an odd number +Enter an integer (0 to terminate): 26 + 26 is an even number +Enter an integer (0 to terminate): 0 + 0 is an even number +Goodbye!</screen> + + <tip> + <orderedlist> + <listitem> + <para>Remember the modulo <quote>%</quote> operator.</para> + </listitem> + + <listitem> + <para>Think twice choosing an appropriate loop type.</para> + </listitem> + </orderedlist> + </tip> + </question> + + <answer> + <para><parameter>We obviously need a loop to ask for further input unless the last entered value was 0. In any case the loop's statement will be executed at least once:</parameter><screen>Enter an integer (0 to terminate): 0 + 0 is an even number +Goodbye!</screen>We thus use a <code>do ... while</code> loop entering the loop's body <emphasis role="bold">before</emphasis> any check is about to happen:<programlisting language="java">try(final Scanner scanner = new Scanner(System.in)){ + + int userInput; + do { + System.out.print("Enter an integer (0 to terminate): "); + userInput = scanner.nextInt(); + if (0 == userInput % 2) { + System.out.println(" " + userInput + " is an even number"); + } else { + System.out.println(" " + userInput + " is an odd number"); + } + } while (0 != userInput); + System.out.println("Goodbye!"); +}</programlisting></para> + </answer> + </qandaentry> + </qandadiv> + </qandaset></para> </section> <section xml:id="sd1_sect_for"> <title>for</title> - <para/> - </section> - </section> + <figure xml:id="sd1_fig_forConsider"> + <title>Common usage of <code>while</code></title> + + <programlisting language="java">int i = 1; <co linkends="sd1_callout_whileLoopJustCounting-1" xml:id="sd1_callout_whileLoopJustCounting-1-co"/> + +while (i < 5 <co linkends="sd1_callout_whileLoopJustCounting-2" xml:id="sd1_callout_whileLoopJustCounting-2-co"/>) { + ... + i++; <co linkends="sd1_callout_whileLoopJustCounting-3" xml:id="sd1_callout_whileLoopJustCounting-3-co"/> +}</programlisting> + + <calloutlist> + <callout arearefs="sd1_callout_whileLoopJustCounting-1-co" xml:id="sd1_callout_whileLoopJustCounting-1"> + <para>Declaring and initializing a loop termination related variable.</para> + </callout> - <section xml:id="ex"> - <title>Exercises</title> + <callout arearefs="sd1_callout_whileLoopJustCounting-2-co" xml:id="sd1_callout_whileLoopJustCounting-2"> + <para>Check for termination.</para> + </callout> - <section xml:id="sd1StatementsLoops"> - <title>Loops</title> + <callout arearefs="sd1_callout_whileLoopJustCounting-3-co" xml:id="sd1_callout_whileLoopJustCounting-3"> + <para>Progressing.</para> + </callout> + </calloutlist> - <section xml:id="sd1SectOnlyEven"> + <para>More concise syntax?</para> + </figure> + + <figure xml:id="sd1_fig_for"> + <title>Replacing <code>while</code> by <code>for</code></title> + + <programlisting language="java">for (int i = 0 <co linkends="sd1_callout_for-1" xml:id="sd1_callout_for-1-co"/>; i < 5 <co linkends="sd1_callout_for-2" xml:id="sd1_callout_for-2-co"/>; i++ <co linkends="sd1_callout_for-3" xml:id="sd1_callout_for-3-co"/>) { + ... +}</programlisting> + + <calloutlist> + <callout arearefs="sd1_callout_for-1-co" xml:id="sd1_callout_for-1"> + <para>Declaring and initializing a loop termination related variable.</para> + </callout> + + <callout arearefs="sd1_callout_for-2-co" xml:id="sd1_callout_for-2"> + <para>Check for termination.</para> + </callout> + + <callout arearefs="sd1_callout_for-3-co" xml:id="sd1_callout_for-3"> + <para>Progressing.</para> + </callout> + </calloutlist> + </figure> + + <qandaset defaultlabel="qanda" xml:id="sd1QandaOnlyEven"> <title>Printing even numbers</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaOnlyEven"> - <qandadiv> - <qandaentry> - <question> - <para>The following slightly modified snippet has been taken from the <quote>Statements</quote> section of <xref linkend="bib_Kurniawan2015"/>:</para> + <qandadiv> + <qandaentry> + <question> + <para>Consider:</para> - <programlisting language="java"> final int limit = 14; - - for (int i = 0; i < limit; i++) { - if (i % 2 == 0) { - System.out.println(i); - } - }</programlisting> + <programlisting language="java">final int limit = 14; +int i = 0; +while (i < limit) { + if (i % 2 == 0) { + System.out.println(i); + } + i++; +}</programlisting> - <para>This code effectively filters odd numbers and prints only even ones:</para> + <para>This code effectively filters odd numbers and prints only even ones:</para> - <screen>0 + <screen>0 2 4 6 @@ -1521,35 +1673,54 @@ Do not copy!</screen></td> 10 12</screen> - <para>Modify this code to work without requiring the inner <quote>if</quote> statement.</para> + <para>Modify this code:</para> - <tip> - <para>Rather then filtering unwanted values try to avoid them in the first place by modifying the enclosing loop.</para> - </tip> - </question> + <orderedlist> + <listitem> + <para>no <quote>if</quote> statement shall be used.</para> - <answer> - <programlisting language="java"> final int limit = 14; + <tip> + <para>Rather then filtering unwanted values try to avoid them in the first place by modifying the enclosing loop.</para> + </tip> + </listitem> + + <listitem> + <para>Use a <code>for</code> loop in favour of <code>while</code>.</para> + </listitem> + </orderedlist> + </question> + + <answer> + <para>Rather than filtering unwanted values we use a <code>for</code> loop having a step width of 2:</para> + + <programlisting language="java">final int limit = 14; - for (int i = 0; i < limit; i += 2) { - System.out.println(i); - }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> +for (int i = 0; i < limit; i += 2) { + System.out.println(i); +}</programlisting> + + <para>Even the original code could have been modified in this fashion:</para> + + <programlisting language="java">final int limit = 14; +int i = 0; +while (i < limit) { + System.out.println(i); + i += 2; // Increment by 2 rather than by 1 +}</programlisting> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sw1SectXmas"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaXmasTree"> <title>Merry Xmas</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaXmasTree"> - <qandadiv> - <qandaentry> - <question> - <para>Write an application to print an ASCII art Xmas tree. Provide a configurable parameter <code>numberOfRows</code> which allows for controlling the tree's size. The following example shows a tree spanning 6 rows excluding the top (X) and the two bottom (###) lines (possibly bad page break in the printed version of this document):</para> + <qandadiv> + <qandaentry> + <question> + <para>Write an application to print an ASCII art Xmas tree. Provide a configurable parameter <code>numberOfRows</code> which allows for controlling the tree's size. The following example shows a tree spanning 6 rows excluding the top (X) and the two bottom (###) lines:</para> - <screen> X + <screen> X * *** ***** @@ -1559,45 +1730,163 @@ Do not copy!</screen></td> ### ###</screen> - <tip> - <para>The following example printing a triangle may serve as a starting point:</para> - - <informaltable border="1"> - <colgroup width="47%"/> + <tip> + <orderedlist> + <listitem> + <para>The following code snippet printing a triangle may serve as a starting point:</para> - <colgroup width="5%"/> + <informaltable border="1"> + <colgroup width="47%"/> - <colgroup width="48%"/> + <colgroup width="5%"/> - <tr> - <td valign="top"><programlisting language="java"> public static void main(String[] args) { + <colgroup width="48%"/> - int numberOfRows = 7; + <tr> + <td valign="top"><programlisting language="java">final int numberOfRows = 7; <co linkends="sd1_callout_printTriangle-1" xml:id="sd1_callout_printTriangle-1-co"/> - for (int row = 0; row < numberOfRows; row++) { - for (int x = 0; x <row; x++) { - System.out.print('*'); - } - System.out.println('*'); - } - }</programlisting></td> +for (int row = 0; row < numberOfRows; row++) { <co linkends="sd1_callout_printTriangle-2" xml:id="sd1_callout_printTriangle-2-co"/> + for (int x = 0; x <= row; x++) { <co linkends="sd1_callout_printTriangle-3" xml:id="sd1_callout_printTriangle-3-co"/> + System.out.print('*'); <co linkends="sd1_callout_printTriangle-4" xml:id="sd1_callout_printTriangle-4-co"/> + } + System.out.println(); <co linkends="sd1_callout_printTriangle-5" xml:id="sd1_callout_printTriangle-5-co"/> +}</programlisting></td> - <td align="center">⟹</td> + <td align="center">⟹</td> - <td valign="top"><screen>* + <td valign="top"><screen>* ** *** **** ***** ****** *******</screen></td> - </tr> - </informaltable> - </tip> - </question> + </tr> + </informaltable> - <answer> - <programlisting language="java"> public static void main(String[] args) { + <calloutlist> + <callout arearefs="sd1_callout_printTriangle-1-co" xml:id="sd1_callout_printTriangle-1"> + <para>The number of rows to be printed. Adjusting is easy and allows for printing larger or smaller triangles retaining its shape:</para> + + <informaltable border="1"> + <colgroup width="47%"/> + + <colgroup width="5%"/> + + <colgroup width="48%"/> + + <tr> + <td valign="top"><programlisting language="java">final int numberOfRows = 3; +...</programlisting></td> + + <td align="center">⟹</td> + + <td valign="top"><screen>* +** +***</screen></td> + </tr> + </informaltable> + </callout> + + <callout arearefs="sd1_callout_printTriangle-2-co" xml:id="sd1_callout_printTriangle-2"> + <para>The <quote>outer</quote> loop. Each step will:</para> + + <orderedlist> + <listitem> + <para>Print one more line.</para> + </listitem> + + <listitem> + <para>Advance the subsequent <quote>inner</quote> loop by one '*'.</para> + </listitem> + </orderedlist> + </callout> + + <callout arearefs="sd1_callout_printTriangle-3-co" xml:id="sd1_callout_printTriangle-3"> + <para>Print a number of '*' characters. The exact number equals the outer loop's <code>row</code> value plus 1. So a value of <code>row == 4</code> will print 4 + 1 '*' characters.</para> + </callout> + + <callout arearefs="sd1_callout_printTriangle-4-co" xml:id="sd1_callout_printTriangle-4"> + <para>Print an individual character. Notice the presence of a <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#print-java.lang.String-">print(....)</methodname> rather than a <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println-java.lang.String-">println()</methodname> method call. This way printing continues within a given line rather than breaking to a new one.</para> + </callout> + + <callout arearefs="sd1_callout_printTriangle-5-co" xml:id="sd1_callout_printTriangle-5"> + <para>After each line we need a line break <code>'\n'</code> for starting the next one using <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println--">println()</methodname>. If you prefer explicit code you may use <package xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html">System</package>.<parameter xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#out">out</parameter>. <methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#print-char-">print('\n')</methodname> instead.</para> + </callout> + </calloutlist> + </listitem> + + <listitem> + <para>Before coding the actual tree start by modifying the above triangle code to produce:</para> + + <screen> * + ** + *** + **** + ***** + ****** +*******</screen> + + <para>Hint: You will need a second loop inside the <quote>outer</quote> loop for creating spaces using the <code>' '</code> character.</para> + </listitem> + </orderedlist> + </tip> + </question> + + <answer> + <para>We start coding the proposed helper exercise:</para> + + <informaltable border="1"> + <colgroup width="47%"/> + + <colgroup width="5%"/> + + <colgroup width="48%"/> + + <tr> + <td valign="top"><programlisting language="java">final int numberOfRows = 7; + +for (int row = 0; row < numberOfRows; row++) { + // Start line print preceeding white spaces + for (int x = 1; x < numberOfRows - row; x++) { + System.out.print(' '); + } + // continue line printing asterisks + for (int x = 0; x <= row; x++) { + System.out.print('*'); + } + System.out.println(); +}</programlisting></td> + + <td align="center">⟹</td> + + <td valign="top"><screen> * + ** + *** + **** + ***** + ****** +*******</screen></td> + </tr> + </informaltable> + + <para>The actual tree requires:</para> + + <orderedlist> + <listitem> + <para>Printing the top.</para> + </listitem> + + <listitem> + <para>Printing the body in a similar fashion as in the above triangle adjusting the loop parameters.</para> + </listitem> + + <listitem> + <para>Printing the trunk.</para> + </listitem> + </orderedlist> + + <programlisting language="java"> public static void main(String[] args) { // Example: 6 rows, tree's body loop index ranging from 0 to 5 // @@ -1649,22 +1938,20 @@ Do not copy!</screen></td> } //part ... System.out.println("###"); // ... finished. }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sw1SectXmasMoreFun"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaXmasMoreFun"> <title>More fun with Xmas trees</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaXmasMoreFun"> - <qandadiv> - <qandaentry> - <question> - <para>Producing the following ASCII art for configurable Xmas tree sizes is more challenging :</para> + <qandadiv> + <qandaentry> + <question> + <para>Producing the following ASCII art for configurable Xmas tree sizes is more challenging :</para> - <screen> \ / + <screen> \ / -->*<-- /_\ /_\_\ @@ -1679,15 +1966,15 @@ Do not copy!</screen></td> /_/_/_/_/_/_/_\ [___]</screen> - <tip> - <para>Inside a string literal a backslash <quote>\</quote> has to be escaped by using a double backslash <quote>\\</quote>.</para> - </tip> - </question> + <tip> + <para>Inside a string literal a backslash <quote>\</quote> has to be escaped by using a double backslash <quote>\\</quote>.</para> + </tip> + </question> - <answer> - <para>We start from a version being fully covered by our current knowledge:</para> + <answer> + <para>We start from a version being fully covered by our current knowledge:</para> - <programlisting language="java"> public static void main(String[] args) { + <programlisting language="java"> public static void main(String[] args) { // Example: 5 row groups, tree's body loop index ranging from 0 to 4 @@ -1764,87 +2051,120 @@ Do not copy!</screen></td> System.out.print(' '); } System.out.println("[___]"); // printing the trunk. - }</programlisting> - - <para>This solution is a bit cumbersome: It involves a repeating task namely indenting lines by a given amount of spaces.</para> - - <para>So far we have not yet introduced methods. In anticipation of upcoming lessons we provide an alternate solution by introducing a method <methodname>printIndented(...)</methodname> which prints a string being indented by a given number of whitespace characters. The System.out.format(...) method will be explained in <xref linkend="sw1SectSquareNumbersFormatted"/>.</para> - - <para>This enhances our code's readability:</para> - - <programlisting language="java">public class XmasTree { - - private static void printIndent(int indentation, String s) { - if (0 < indentation) { - final String format = "%" + indentation + "s%s"; - System.out.format(format, "", s); - } else { - System.out.print(s); - } - } - - public static void main(String[] args) { - - // Example: 5 row groups, tree's body loop index ranging from 0 to 4 + }</programlisting> - // \ / The tree's top. - // -->*<-- - // /_\ - // 0 /_\_\ Start of tree's body - // /_/_/_\ - // 1 /_\_\_\ - // /_/_/_/_\ - // 2 /_\_\_\_\ - // /_/_/_/_/_\ - // 3 /_\_\_\_\_\ - // /_/_/_/_/_/_\ - // 4 /_\_\_\_\_\_\ - // /_/_/_/_/_/_/_\ End of tree's body - // [___] Bottom trunk line. + <para>This solution is a bit cumbersome: It involves a repeating task namely indenting lines by a given amount of spaces.</para> + <para>So far we have not yet introduced methods. In anticipation of <link linkend="sd1SectStaticMembers">upcoming lessons</link> we provide an alternate solution by introducing a method <methodname>printIndented(...)</methodname> which prints a string a configurable number of times being indented by a given number of whitespace characters using <package xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html">System</package>.<parameter xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#out">out</parameter>.<methodname xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format(...)</methodname> as in <xref linkend="sd1QandaSquareNumberTableFormatted"/>.</para> - final int numberOfRowGroups = 5; // You may easily change this value. - - printIndent(numberOfRowGroups + 1, "\\ /" + "\n"); // The tree's top. - printIndent(numberOfRowGroups - 1, "-->*<--" + "\n"); - printIndent(numberOfRowGroups + 1, "/_\\" + "\n"); + <para>Using <methodname>printIndented(...)</methodname> considerable enhances our code's readability. We do no longer need the <quote>inner</quote> loops. On the downside fiddling with values describing indentations and repetitions is still being required:</para> + <programlisting language="java">public class XmasTree { - // Part two: The tree's body - // - for (int rowGroup = 0; // Outer loop printing the - rowGroup < numberOfRowGroups; rowGroup++) { // tree's body. + // Helper method. + // + // Print string s a number of times defined by the repeat value being preceded by a number + // of whitespace characters ' ' given by the indentation value. + // Thus printIndent(5, "axb", 2) will generate "_____axbaxb" with "_" denoting white space. + // + private static void printIndent(final int indentation, final String s, final int repeat) { + if (0 < indentation) { + final String format = "%" + indentation + "s"; + System.out.format(format, ""); + } + for (int i = 0; i < repeat; i++) { + System.out.print(s); + } + } - printIndent(numberOfRowGroups - rowGroup,"/");// Starting first line of row - for (int x = 0; x < rowGroup + 2; x++) { // group with (numberOfRows - - System.out.print("_\\"); // row) tree body content. - } - System.out.println(); // Finishing current line. + public static void main(String[] args) { - // Second body line of current group - // - printIndent(numberOfRowGroups - rowGroup - 1, ""); // Starting second line - for (int x = 0; x < rowGroup + 3;x++) { // of row group with - System.out.print("/_"); // (numberOfRows - row - 1) - } // tree body content. - System.out.println("\\"); // Finishing current line. - } + // Example: 5 row groups of two lines each, tree's body loop index ranging from 0 to 4 + // + // Each groups consists of two lines having identical structure among all groups: + // Group n: /_\_\ ... _\ »/« followed by repeating »_\« n+2 times + // /_/_ ... /_\ Repeating »/_« n+3 times ending with »\« + + // \ / The tree's top. + // -->*<-- + // /_\ + // 0 /_\_\ Start of tree's body + // /_/_/_\ + // 1 /_\_\_\ + // /_/_/_/_\ + // 2 /_\_\_\_\ + // /_/_/_/_/_\ + // 3 /_\_\_\_\_\ + // /_/_/_/_/_/_\ + // 4 /_\_\_\_\_\_\ + // /_/_/_/_/_/_/_\ End of tree's body + // [___] Bottom trunk line. + + + final int numberOfRowGroups = 5; // You may easily change this value. + + // Part one: The tree's top + // + printIndent(numberOfRowGroups + 1, "\\ /\n" ,1); + printIndent(numberOfRowGroups - 1, "-->*<--\n",1); + printIndent(numberOfRowGroups + 1, "/_\\\n" ,1); + + // Part two: The tree's body + // + for (int rowGroup = 0; // Outer loop printing the + rowGroup < numberOfRowGroups; rowGroup++) { // tree's body group by group. + + printIndent(numberOfRowGroups - rowGroup,"/", 1);// Starting first line of group + printIndent(0,"_\\", rowGroup + 2); // print leaves + System.out.println(); // Finishing first line of group. + + // Second body line of current group + // + printIndent(numberOfRowGroups - rowGroup - 1, "", 1); // Starting second line + printIndent(0, "/_", rowGroup + 3); // of row group + + System.out.println("\\"); // Finish second line of group. + } - // Part three: The tree's bottom trunk - // - printIndent (numberOfRowGroups, "[___]"); // Indenting the bottom trunk ... - } + // Part three: The tree's bottom trunk + // + printIndent (numberOfRowGroups, "[___]", 1); // Indenting the bottom trunk ... + } }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + + <para>Both variants allow for setting e.g. <code>final int numberOfRowGroups = 8</code> creating a larger tree (albeit having the same trunk size):</para> + + <screen> \ / + -->*<-- + /_\ + /_\_\ + /_/_/_\ + /_\_\_\ + /_/_/_/_\ + /_\_\_\_\ + /_/_/_/_/_\ + /_\_\_\_\_\ + /_/_/_/_/_/_\ + /_\_\_\_\_\_\ + /_/_/_/_/_/_/_\ + /_\_\_\_\_\_\_\ + /_/_/_/_/_/_/_/_\ + /_\_\_\_\_\_\_\_\ + /_/_/_/_/_/_/_/_/_\ + /_\_\_\_\_\_\_\_\_\ +/_/_/_/_/_/_/_/_/_/_\ + [___]</screen> + </answer> + </qandaentry> + </qandadiv> + </qandaset> <section xml:id="sd1SectSquareNumberTable"> <title>A table of square numbers</title> <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareNumberTable"> + <title>A basic square number table</title> + <qandadiv> <qandaentry> <question> @@ -1889,16 +2209,15 @@ Do not copy!</screen></td> </qandadiv> </qandaset> - <section xml:id="sw1SectSquareNumbersFormatted"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareNumberTableFormatted"> <title>Tidy up the mess!</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareNumberTableFormatted"> - <qandadiv> - <qandaentry> - <question> - <para>Running the previous code for values beyond 9 suffers from ugly formatting:</para> + <qandadiv> + <qandaentry> + <question> + <para>Running the previous code for values beyond 9 suffers from ugly formatting:</para> - <screen>n | n * n + <screen>n | n * n --+------ 0 | 0 1 | 1 @@ -1912,19 +2231,19 @@ Do not copy!</screen></td> 19 | 361 20 | 400</screen> - <para>Modify your code by:</para> + <para>Modify your code by:</para> - <orderedlist> - <listitem> - <para>introducing a single integer constant to define the number of values to be printed (i.e. 20 in the above example).</para> - </listitem> + <orderedlist> + <listitem> + <para>introducing a single integer constant to define the number of values to be printed (i.e. 20 in the above example).</para> + </listitem> - <listitem> - <para>Right indent all integer values being printed.</para> - </listitem> - </orderedlist> + <listitem> + <para>Right indent all integer values being printed.</para> + </listitem> + </orderedlist> - <para>Your application's output shall look like:<screen> n | n * n + <para>Your application's output shall look like:<screen> n | n * n ---+------ 0| 0 1| 1 @@ -1936,14 +2255,14 @@ Do not copy!</screen></td> ... 19| 361 20| 400</screen><tip> - <para>Read the track <link xlink:href="https://docs.oracle.com/javase/tutorial/java/data/numberformat.html">Formatting Numeric Print Output</link> and learn how to style numeric output.</para> - </tip></para> - </question> + <para>Read the track <link xlink:href="https://docs.oracle.com/javase/tutorial/java/data/numberformat.html">Formatting Numeric Print Output</link> and learn how to style numeric output.</para> + </tip></para> + </question> - <answer> - <para>The key difference is replacing <methodname><link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#out">System.out</link>.<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println--">println</link>(...)</methodname> statements by <methodname><link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#out">System.out</link>.<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format</link>(...)</methodname>:</para> + <answer> + <para>The key difference is replacing <methodname><link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#out">System.out</link>.<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println--">println</link>(...)</methodname> statements by <methodname><link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#out">System.out</link>.<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-">format</link>(...)</methodname>:</para> - <programlisting language="java"> public static void main(String[] args) { + <programlisting language="java"> public static void main(String[] args) { final int limit = 20; // The number of records to be printed @@ -1956,22 +2275,20 @@ Do not copy!</screen></td> i , i * i); // Values being inserted in above format } // string. }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sw1SectSquareNumbersHtmlFormatted"> + <qandaset defaultlabel="qanda" xml:id="sw1QandaSquareNumbersHtmlFormatted"> <title>HTML-ify me</title> - <qandaset defaultlabel="qanda" xml:id="sw1QandaSquareNumbersHtmlFormatted"> - <qandadiv> - <qandaentry> - <question> - <para>Modify the previous code to generate HTML output instead of pure text and watch the result in a WEB browser:</para> + <qandadiv> + <qandaentry> + <question> + <para>Modify the previous code to generate HTML output instead of pure text and watch the result in a WEB browser:</para> - <programlisting language="xml"><html xmlns='http://www.w3.org/1999/xhtml'> + <programlisting language="xml"><html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>A square table</title> </head> @@ -1993,10 +2310,10 @@ Do not copy!</screen></td> </table> </body> </html></programlisting> - </question> + </question> - <answer> - <programlisting language="java"> public static void main(String[] args) { + <answer> + <programlisting language="java"> public static void main(String[] args) { final int limit = 20; // The number of records to be printed @@ -2026,22 +2343,20 @@ Do not copy!</screen></td> + " </body>\n" + "</html>\n"); }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sd1SectIntermediateMultiplication"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaIntermediateMultiplyTable1"> <title>Auxiliary Example, part 1: A multiplication table</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaIntermediateMultiplyTable1"> - <qandadiv> - <qandaentry> - <question> - <para>In order to prepare a more sophisticated square number table we supply a slightly different exercise producing a multiplication table:</para> + <qandadiv> + <qandaentry> + <question> + <para>In order to prepare a more sophisticated square number table we supply a slightly different exercise producing a multiplication table:</para> - <screen> * | 1 2 3 4 5 6 7 8 9 10 + <screen> * | 1 2 3 4 5 6 7 8 9 10 ---+-------------------------------------------------- 1| 1 2 3 4 5 6 7 8 9 10 2| 2 4 6 8 10 12 14 16 18 20 @@ -2054,22 +2369,22 @@ Do not copy!</screen></td> 9| 9 18 27 36 45 54 63 72 81 90 10| 10 20 30 40 50 60 70 80 90 100 </screen> - <para>The number of rows and columns are equal. Provide an appropriate parameter <code>final int limit = ...</code> so that your implementation works for different values just by changing its value.</para> + <para>The number of rows and columns are equal. Provide an appropriate parameter <code>final int limit = ...</code> so that your implementation works for different values just by changing its value.</para> - <tip> - <para>You'll need an inner loop nested within an outer one like:</para> + <tip> + <para>You'll need an inner loop nested within an outer one like:</para> - <programlisting language="java">for (int y = 0; ...){ + <programlisting language="java">for (int y = 0; ...){ for (int x = 0; ... ) { ... } }</programlisting> - </tip> - </question> + </tip> + </question> - <answer> - <programlisting language="java"> public static void main(String[] args) { + <answer> + <programlisting language="java"> public static void main(String[] args) { final int limit = 10; // Parameter is subject to change. @@ -2094,22 +2409,20 @@ Do not copy!</screen></td> System.out.println(); } }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sd1SectIntermediateMultiplication2"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaIntermediateMultiplyTable2"> <title>Auxiliary Example, part 2: Avoiding redundant entries</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaIntermediateMultiplyTable2"> - <qandadiv> - <qandaentry> - <question> - <para>It does not make sense to supply both results like e.g. 3 * 4 and 4 * 3. Modify your application to generate:</para> + <qandadiv> + <qandaentry> + <question> + <para>It does not make sense to supply both results like e.g. 3 * 4 and 4 * 3. Modify your application to generate:</para> - <screen> 1| 1 + <screen> 1| 1 2| 2 4 3| 3 6 9 4| 4 8 12 16 @@ -2121,12 +2434,12 @@ Do not copy!</screen></td> 10| 10 20 30 40 50 60 70 80 90 100 ---+-------------------------------------------------- * | 1 2 3 4 5 6 7 8 9 10 </screen> - </question> + </question> - <answer> - <para>We have to move the header to the table's bottom. Apart from that the required change with respect to your previous exercise is tiny: The <quote>inner</quote> loop must end when reaching the current row's index:</para> + <answer> + <para>We have to move the header to the table's bottom. Apart from that the required change with respect to your previous exercise is tiny: The <quote>inner</quote> loop must end when reaching the current row's index:</para> - <programlisting language="java"> final int limit = 10; // Parameter is subject to change. + <programlisting language="java"> final int limit = 10; // Parameter is subject to change. for (int row = 1; row <= limit; row++) { // Printing rows. System.out.format("%3d| ", row); @@ -2148,22 +2461,20 @@ Do not copy!</screen></td> } System.out.println(); </programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sd1SectSquareTableBlocks"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareTableBlocks"> <title>Creating a <quote>real</quote> square table</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareTableBlocks"> - <qandadiv> - <qandaentry> - <question> - <para>The last square number table solution is only appropriate for smaller amounts of data. Growing number of elements require rearranging values in blocks in order to limit wasting space:</para> + <qandadiv> + <qandaentry> + <question> + <para>The last square number table solution is only appropriate for smaller amounts of data. Growing number of elements require rearranging values in blocks in order to limit wasting space:</para> - <screen> n | n*n n | n*n n | n*n n | n*n n | n*n + <screen> n | n*n n | n*n n | n*n n | n*n n | n*n ----+--------------+--------------+--------------+--------------+---------- 0 | 0 20 | 400 40 | 1600 60 | 3600 80 | 6400 1 | 1 21 | 441 41 | 1681 61 | 3721 81 | 6561 @@ -2187,27 +2498,27 @@ Do not copy!</screen></td> 18 | 324 38 | 1444 58 | 3364 78 | 6084 98 | 9604 19 | 361 39 | 1521 59 | 3481 79 | 6241 99 | 9801</screen> - <para>Building a table this way requires some parameters:</para> + <para>Building a table this way requires some parameters:</para> - <itemizedlist> - <listitem> - <para>The number of blocks in x-direction (5 in the above example)</para> - </listitem> + <itemizedlist> + <listitem> + <para>The number of blocks in x-direction (5 in the above example)</para> + </listitem> - <listitem> - <para>The number of blocks in y-direction (2 in the above example)</para> - </listitem> + <listitem> + <para>The number of blocks in y-direction (2 in the above example)</para> + </listitem> - <listitem> - <para>The number of entries per block (10 in the above example)</para> - </listitem> - </itemizedlist> + <listitem> + <para>The number of entries per block (10 in the above example)</para> + </listitem> + </itemizedlist> - <para>You may have to nest three loops within each other.</para> - </question> + <para>You may have to nest three loops within each other.</para> + </question> - <answer> - <programlisting language="java"> public static void main(String[] args) { + <answer> + <programlisting language="java"> public static void main(String[] args) { final int numBlocksHorizontal = 5, @@ -2243,50 +2554,48 @@ Do not copy!</screen></td> } } }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> - <section xml:id="sd1SectSquareTableBlocksHtml"> + <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareTableBlocksHtml"> <title>Creating a sophisticated HTML version of your square table</title> - <qandaset defaultlabel="qanda" xml:id="sd1QandaSquareTableBlocksHtml"> - <qandadiv> - <qandaentry> - <question> - <para>A HTML of version of the previous square number table may look like <link xlink:href="/Sd1/Ref/Src/squareTable.html">squareTable.html</link>. Inspect this generated HTML 5 code and modify your console output from the previous exercise in order to produce identical or similar HTML code.</para> + <qandadiv> + <qandaentry> + <question> + <para>A HTML of version of the previous square number table may look like <link xlink:href="/Sd1/Ref/Src/squareTable.html">squareTable.html</link>. Inspect this generated HTML 5 code and modify your console output from the previous exercise in order to produce identical or similar HTML code.</para> - <para>Depending on your advance in HTML and <xref linkend="glo_CSS"/> you may want to postpone this exercise until <xref linkend="glo_HTML"/> and <xref linkend="glo_CSS"/> have been thoroughly covered in <link xlink:href="https://www.hdm-stuttgart.de/studenten/stundenplan/vorlesungsverzeichnis/vorlesung_detail?vorlid=5213267">related lectures</link>.</para> + <para>Depending on your advance in HTML and <xref linkend="glo_CSS"/> you may want to postpone this exercise until <xref linkend="glo_HTML"/> and <xref linkend="glo_CSS"/> have been thoroughly covered in <link xlink:href="https://www.hdm-stuttgart.de/studenten/stundenplan/vorlesungsverzeichnis/vorlesung_detail?vorlid=5213267">related lectures</link>.</para> - <tip> - <para>The <xref linkend="glo_HTML"/> standard allows for quoting of attribute values either by double or by single quotes:</para> + <tip> + <para>The <xref linkend="glo_HTML"/> standard allows for quoting of attribute values either by double or by single quotes:</para> - <itemizedlist> - <listitem> - <para><code><col span="2"/></code></para> - </listitem> + <itemizedlist> + <listitem> + <para><code><col span="2"/></code></para> + </listitem> - <listitem> - <para><code><col span='2'/></code></para> - </listitem> - </itemizedlist> + <listitem> + <para><code><col span='2'/></code></para> + </listitem> + </itemizedlist> - <para>The latter is more convenient when being embedded in <xref linkend="glo_Java"/> code since it does not interfere with string literal delimiters:</para> + <para>The latter is more convenient when being embedded in <xref linkend="glo_Java"/> code since it does not interfere with string literal delimiters:</para> - <programlisting language="java">System.out.print("<col span='2'/>\n");</programlisting> + <programlisting language="java">System.out.print("<col span='2'/>\n");</programlisting> - <para>rather than the more clumsy:</para> + <para>rather than the more clumsy:</para> - <programlisting language="java">System.out.print("<col span=\"2\"/>\n");</programlisting> - </tip> - </question> + <programlisting language="java">System.out.print("<col span=\"2\"/>\n");</programlisting> + </tip> + </question> - <answer> - <para>The following solution uses <xref linkend="glo_CSS"/> style definitions in the generated HTML's header section which are subsequently being referenced from the document's body.</para> + <answer> + <para>The following solution uses <xref linkend="glo_CSS"/> style definitions in the generated HTML's header section which are subsequently being referenced from the document's body.</para> - <programlisting language="java"> public static void main(String[] args) { + <programlisting language="java"> public static void main(String[] args) { final int numBlocksHorizontal = 5, numBlocksVertical = 2, entriesPerBlock = 10; @@ -2346,24 +2655,23 @@ Do not copy!</screen></td> System.out.print("" + " </table>\n" + " </body>\n" + "</html>\n"); }</programlisting> - <para>Viewing the generated <xref linkend="glo_HTML"/> results in:</para> - - <screenshot> - <info> - <title>A <xref linkend="glo_HTML"/> square table till 20*20.</title> - </info> - - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/squareTable.png"/> - </imageobject> - </mediaobject> - </screenshot> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + <para>Viewing the generated <xref linkend="glo_HTML"/> results in:</para> + + <screenshot> + <info> + <title>A <xref linkend="glo_HTML"/> square table till 20*20.</title> + </info> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/squareTable.png"/> + </imageobject> + </mediaobject> + </screenshot> + </answer> + </qandaentry> + </qandadiv> + </qandaset> </section> <section xml:id="sd1SectPlayingLottery"> @@ -2373,7 +2681,7 @@ Do not copy!</screen></td> <qandadiv> <qandaentry> <question> - <para>Many lotteries randomly dram numbers from a given set like:</para> + <para>Common lotteries randomly draw numbers from a given set like:</para> <glosslist> <glossentry> @@ -2421,7 +2729,7 @@ Do not copy!</screen></td> </glossentry> </glosslist> - <para>This category of lottery does not care about ordering (apart from so called jolly numbers). The number of possibilities drawing n out of m numbers ignoring their order is being given by the <link xlink:href="https://en.wikipedia.org/wiki/Binomial_coefficient">binomial coefficient <inlineequation> + <para>This category of lottery does not care about ordering (apart from so called jolly numbers). The number of possibilities for drawing k out of n numbers ignoring their ordering is being given by the <link xlink:href="https://en.wikipedia.org/wiki/Binomial_coefficient">binomial coefficient</link> <inlineequation> <m:math display="inline"> <m:mrow> <m:mrow> @@ -2447,7 +2755,7 @@ Do not copy!</screen></td> </m:mrow> </m:mrow> </m:math> - </inlineequation></link>:</para> + </inlineequation>:</para> <informalequation> <m:math display="block"> @@ -2517,7 +2825,7 @@ Do not copy!</screen></td> </m:math> </informalequation> - <para>Write an application which allows for calculation of probabilistic success rates. For the German <quote xml:lang="de">Glücksspirale</quote> a possible output reads:</para> + <para>Write an application which allows for determining the probabilistic success rates by calculating this coefficient. For the German <quote xml:lang="de">Glücksspirale</quote> a possible output reads:</para> <screen>Your chance to win when drawing 6 out of 49 is 1 : 13983816</screen> @@ -2956,31 +3264,47 @@ for (int i = 2; i <= number; i++) { <qandadiv> <qandaentry> <question> - <para>Write a program which randomly chooses an integer number between zero and a fixed upper limit e.g. 10.</para> + <para>Write a simple game where the user tries to guess a randomly selected number.</para> - <para>On execution the user is asked to guess this secret value. Each time entering a new guess the program shall respond with either of:</para> + <para>Your program will randomly choose an integer number between zero and a configurable fixed upper limit e.g. 10. The user will have an again configurable number of tries to guess the number in question. Each time after entering a number your program will respond with either of the following:</para> - <itemizedlist> - <listitem> - <para>You won!</para> - </listitem> + <glosslist> + <glossentry> + <glossterm>User wins</glossterm> - <listitem> - <para>Game over, try another run?</para> - </listitem> + <glossdef> + <para>You won!</para> + </glossdef> + </glossentry> - <listitem> - <para>Number is too low</para> - </listitem> + <glossentry> + <glossterm>User looses</glossterm> - <listitem> - <para>Number is too high</para> - </listitem> - </itemizedlist> + <glossdef> + <para>Game over, try another run?</para> + </glossdef> + </glossentry> + + <glossentry> + <glossterm>Game continues, either of:</glossterm> + + <glossdef> + <itemizedlist> + <listitem> + <para>Number is too low</para> + </listitem> + + <listitem> + <para>Number is too high</para> + </listitem> + </itemizedlist> + </glossdef> + </glossentry> + </glosslist> - <para>The system offers a maximum number of tries, say 5 for example. In the following example the system randomly generates the secret number 5. A possible dialogue looks like:</para> + <para>The system offers a maximum number of tries e.g. 6. In the following example the system randomly generated the secret number 5 internally. A possible dialogue looks like:</para> - <screen>Try to guess my number in the range between 0 and 10: + <screen>Try to guess my secret number between 0 and 10: You have 5 attempts Input your guess:4 Value is too low @@ -2989,17 +3313,16 @@ Value is too high Input your guess:5 Congratulations! you won!</screen> - <para>Regarding user input reading and random number generating methods please use the following recipe to get started:</para> + <para>Regarding reading user input and creating random numbers please use the following recipe to get started:</para> <programlisting language="java">package ... import java.util.Random; ... public static void main(String[] args) { - final short maxValueInclusive = 10; // Upper inclusive limit for selecting - // random - final int randomValue = new Random() // a random value ranging from 0 to - .<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#nextInt--">nextInt(maxValueInclusive + 1)</link>; // maxValueInclusive. + + final int randomValue = new Random() // Selecting a pseudo random value + .<link xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#nextInt--">nextInt(10)</link>; // between 0 and 10 (inclusive). final Scanner scan = new Scanner(System.in); System.out.print("Input a number:"); @@ -3010,113 +3333,39 @@ import java.util.Random; </question> <answer> - <programlisting language="java"> public static void main(String[] args) { + <programlisting language="java">final int maxValueInclusive = 10, // Guessing a value from 0 to this value (inclusive) + numOfUserAttempts = 5, // User will have this number of tries guessing the random value. + randomValue = // Create a random value between 0 + new Random().nextInt( // and maxValueInclusive. + maxValueInclusive + 1); - final int maxValueInclusive = 10, numOfUserAttempts = 5, - randomValue = new Random() - .nextInt(maxValueInclusive + 1); // Create a random value between 0 - // and maxValueInclusive +System.out.println("Try to guess my secret number in between 0 and " + + maxValueInclusive + ":"); - System.out.println("Try to guess my number in the range between 0 and " - + maxValueInclusive + ":"); - System.out.println("You have " + numOfUserAttempts + " attempts"); +System.out.println("You have " + numOfUserAttempts + " attempts"); - final Scanner scan = new Scanner(System.in); - - boolean numberWasFound = false; +try (final Scanner scan = new Scanner(System.in)) { + boolean numberWasFound = false; - for (int i = 0; i < numOfUserAttempts; i++) { - System.out.print("Input your guess:"); - final int userGuess = scan.nextInt(); - if (userGuess < randomValue) { + for (int i = 0; i < numOfUserAttempts; i++) { + System.out.print("Input your guess:"); + final int userGuess = scan.nextInt(); + if (userGuess < randomValue) { System.out.println("Value is too low"); - } else if (randomValue < userGuess) { + } else if (randomValue < userGuess) { System.out.println("Value is too high"); - } else { + } else { numberWasFound = true; break; - } - } - scan.close(); - - if (numberWasFound) { - System.out.println("Congratulations! you won!"); - } else { - System.out.println("Game over, try another run?"); - } - }</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> - - <section xml:id="sw1SectionPostExamMarking"> - <title>Post modifying an exam's marking</title> - - <qandaset defaultlabel="qanda" xml:id="sw1QandaPostExamBonuspoints"> - <title>Exam bonus points</title> - - <qandadiv> - <qandaentry> - <question> - <para>After completely marking an examination a lecturer decides to globally add a number extra bonus points to a specific task . The task does have an upper limit of points to be awarded at maximum. We provide an example:</para> - - <para>On completely fulfilling a task 12 points will be awarded. So after marking the exam participants' points range from 0 to 12 points being represented by the variable <code>pointsReached</code>.</para> - - <para>After completing his marking our lecturer wants to add three more points to all participants without breaching the 12 point limit.</para> - - <para>Complete the following code by assigning this modified number of points to the variable <code>newResult</code>.</para> - - <programlisting language="java"> public static void main(String[] args) { - - int pointsReached = 1; - int maximumPoints = 12; - int pointsToAdd = 3; - - final int newResult; - - // TODO: Assignment to variable newResult - - System.out.println("New Result:" + newResult); - }</programlisting> - </question> - - <answer> - <para>The basic task is to add up the values of <code>pointsReached</code> and <code>pointsToAdd</code>. When exceeding the limit we just assign the limit itself:</para> - - <programlisting language="java"> public static void main(String[] args) { - - int pointsReached = 1; - int maximumPoints = 12; - int pointsToAdd = 3; - - final int newResult; - - if (maximumPoints <= pointsReached + pointsToAdd) { - newResult = maximumPoints; - } else { - newResult = pointsReached + pointsToAdd; - } - - System.out.println("New Result:" + newResult); - }</programlisting> - - <para>This basically means calculating the minimum of the two expressions <code>pointsReached + pointsToAdd</code> and <code>maximumPoints</code>. This may as well be be implemented by:</para> - - <programlisting language="java"> public static void main(String[] args) { - - int pointsReached = 1; - int maximumPoints = 12; - int pointsToAdd = 3; - - final int newResult = Math.min(maximumPoints, pointsReached + pointsToAdd); - - System.out.println("New Result:" + newResult); - - }</programlisting> + } + } - <para>You will fully understand the above expression <function>Math.min(...)</function> after finishing the <quote xlink:href="https://proquest.safaribooksonline.com/9780992133047/toc12_html">Static Final Variables</quote> section.</para> + if (numberWasFound) { + System.out.println("Congratulations! you won!"); + } else { + System.out.println("Game over, try another run?"); + } +}</programlisting> </answer> </qandaentry> </qandadiv> @@ -3877,7 +4126,7 @@ import java.util.Random; </tr> </informaltable> - <para>Why does a value of 838 rather then 840 appears here?</para> + <para>Why does an upper value of 838 rather then the proposed sum value of 840 appears here?</para> <para>This list mostly contains values like <inlineequation> <m:math display="inline"> @@ -4221,7 +4470,7 @@ import java.util.Random; </m:math> </inlineequation>.</para> - <para>We thus only need two nested loops for generating all possible triples: If the value of b is being incremented by 1 then c has to be decremented by 1 as well.</para> + <para>We thus only need two nested loops for generating all possible triples: If the value of b is being incremented by 1 then c has to be decremented by 1 as well and is thus fully dependent.</para> <para>For convenience reasons we introduce a variable <code>int sum = 840</code> representing our sum of all three values. Our filter condition now only needs to check for the remaining Pythagorean condition <inlineequation> <m:math display="inline"> @@ -4279,7 +4528,7 @@ for (int a = 1; a <= sum / 3; a++) { (210, 280, 350) (240, 252, 348)</screen> - <para>The above code can be simplified further. We introduce the variable s being shorthand for <code>sum</code> in our <xref linkend="glo_Java"/> code. The inner <code>for</code> loop so far starts with a value of <inlineequation> + <para>The above code can be simplified even further. We introduce the variable s being shorthand for <code>sum</code> in our <xref linkend="glo_Java"/> code. The inner <code>for</code> loop so far starts with a value of <inlineequation> <m:math display="inline"> <m:mrow> <m:mi>b</m:mi> @@ -4484,7 +4733,7 @@ for (int a = 1; a <= sum / 3; a++) { </m:math> </informalequation> - <para>So for each given value of a there is either no or exactly one possible solution (since <code>n</code> is of integer type). Our inner loop thus becomes obsolete.</para> + <para>So for each given value of a there is either no or exactly one possible solution (since <code>n</code> is of integer type). Our <quote>inner</quote> nested loop becomes obsolete.</para> <para>The above equation must hold for integer arithmetic leaving no fractional remainder. We introduce two variables <code>numerator</code> and <code>denominator</code> representing the above terms <inlineequation> <m:math display="inline"> @@ -4550,7 +4799,7 @@ for (int a = 1; a <= sum / 3; a++) { </m:mrow> </m:mrow> </m:math> - </inlineequation>.The <quote>remainder of modulus</quote> operator <code>%</code> testing for a zero remainder filters the desired triples:</para> + </inlineequation>. The <quote>remainder of modulus</quote> operator <code>%</code> testing for a zero remainder filters the desired triples:</para> <programlisting language="java">final int sum = 840; @@ -4566,28 +4815,28 @@ for (int a = 1; a <= sum / 3; a++) { } }</programlisting> - <para>This yields the same result as before but execution is (again) ways faster. This will pay off when looking for larger values of <code>sum</code>.</para> + <para>This yields the same result as before but execution is (again) ways faster paying off when looking for larger values of <code>sum</code>.</para> </answer> </qandaentry> </qandadiv> </qandaset> </section> </section> + </section> - <section xml:id="sd1SectExternalLogicExercises"> - <title>Logic related external exercises</title> + <section xml:id="sd1SectExternalLogicExercises"> + <title>Logic related external exercises</title> - <para>Solve:</para> + <para>Solve:</para> - <itemizedlist> - <listitem> - <para><link xlink:href="http://codingbat.com/java/Warmup-1">Warmup-1</link> excluding <link xlink:href="http://codingbat.com/prob/p191914">Warmup-1 > notString</link>.</para> - </listitem> + <itemizedlist> + <listitem> + <para><link xlink:href="http://codingbat.com/java/Warmup-1">Warmup-1</link> excluding <link xlink:href="http://codingbat.com/prob/p191914">Warmup-1 > notString</link>.</para> + </listitem> - <listitem> - <para><link xlink:href="http://codingbat.com/java/Logic-1">Logic-1</link>.</para> - </listitem> - </itemizedlist> - </section> + <listitem> + <para><link xlink:href="http://codingbat.com/java/Logic-1">Logic-1</link>.</para> + </listitem> + </itemizedlist> </section> </chapter> -- GitLab