<div class="page"> <div class="cover text-center"> <img class="mx-auto" src=/itb/images/logo_mislata.png alt="logo"> # Solució Exercici: Estats - Comptaquilòmetres cotxe <div class="text-end fit-content ms-auto my-3 mt-auto pt-3"> <p><strong>Autor:</strong> Joan Puigcerver Ibáñez</p> <p><strong>Correu electrònic:</strong> j.puigcerveribanez@edu.gva.es</p> <p><strong>Curs:</strong> 2024/2025</p> </div> <div> <p>Aquest material és una obra derivada a partir del material de: <strong>Sergio Badal</strong></p> <p class="fw-bold mb-0">Llicència: BY-NC-SA</p> <p class="d-none d-md-block">(Reconeixement - No Comercial - Compartir Igual)</p> <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.ca" target="_blank"> <img class="mx-auto" src="/itb/images/license.png" alt="Licence"/> </a> </div><!--license--> </div><!--cover--> </div><!--page--> {:toc} # Diagrama d'estats cotxe Volem modelar els diferents estats i accions que hi poden haver en la pantalla d'un cotxe. Aquesta pantalla pot estar en 3 estats: - __Compta quilòmetres__: El compta quilòmetres total mostra la distància total recorreguda pel vehicle. - __Comptador viatge__: Mostra la distància recorreguda pel vehicle des del moment en què es va reiniciar per última vegada. Només aquest és reiniciable. - __Consum__: Mostra els litres cada 100 km consumits. Apretant un botó es permet alternar entre els 3 modes, sempre en l'ordre anterior sense possiblitat de tornar enrere. En el mode __comptador viatge__, podem mantindre apretat el botó per reiniciar el comptador. Si no es manté apretat, passa al següent estat. Cal utilitzar __entry__, __do__, __exit__ quan siga necessari. ## Solució ::: solution <div class="mxgraph" style="max-width:100%;border:1px solid transparent;" data-mxgraph="{&quot;highlight&quot;:&quot;#0000ff&quot;,&quot;nav&quot;:true,&quot;resize&quot;:true,&quot;toolbar&quot;:&quot;zoom layers tags lightbox&quot;,&quot;edit&quot;:&quot;_blank&quot;,&quot;xml&quot;:&quot;&lt;mxfile host=\&quot;app.diagrams.net\&quot; modified=\&quot;2024-04-22T09:46:02.898Z\&quot; agent=\&quot;Mozilla&#x2F;5.0 (X11; Linux x86_64) AppleWebKit&#x2F;537.36 (KHTML, like Gecko) Chrome&#x2F;123.0.0.0 Safari&#x2F;537.36\&quot; etag=\&quot;d-SYxsBRrvEuuRM_D038\&quot; version=\&quot;24.2.7\&quot; type=\&quot;google\&quot;&gt;\n &lt;diagram name=\&quot;Page-1\&quot; id=\&quot;2YBvvXClWsGukQMizWep\&quot;&gt;\n &lt;mxGraphModel dx=\&quot;2074\&quot; dy=\&quot;1114\&quot; grid=\&quot;1\&quot; gridSize=\&quot;10\&quot; guides=\&quot;1\&quot; tooltips=\&quot;1\&quot; connect=\&quot;1\&quot; arrows=\&quot;1\&quot; fold=\&quot;1\&quot; page=\&quot;1\&quot; pageScale=\&quot;1\&quot; pageWidth=\&quot;850\&quot; pageHeight=\&quot;1100\&quot; math=\&quot;0\&quot; shadow=\&quot;0\&quot;&gt;\n &lt;root&gt;\n &lt;mxCell id=\&quot;0\&quot; &#x2F;&gt;\n &lt;mxCell id=\&quot;1\&quot; parent=\&quot;0\&quot; &#x2F;&gt;\n &lt;mxCell id=\&quot;Wbr10UhurKWa1ZI_zyCr-31\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;\&quot; parent=\&quot;1\&quot; source=\&quot;Wbr10UhurKWa1ZI_zyCr-1\&quot; target=\&quot;rUmXZGd3vIKuDlGXPuo1-1\&quot; edge=\&quot;1\&quot;&gt;\n &lt;mxGeometry relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;mxPoint x=\&quot;200\&quot; y=\&quot;160\&quot; as=\&quot;targetPoint\&quot; &#x2F;&gt;\n &lt;&#x2F;mxGeometry&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;Wbr10UhurKWa1ZI_zyCr-1\&quot; value=\&quot;\&quot; style=\&quot;ellipse;html=1;shape=startState;fillColor=#000000;strokeColor=#ff0000;\&quot; parent=\&quot;1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;235\&quot; y=\&quot;80\&quot; width=\&quot;30\&quot; height=\&quot;30\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-3\&quot; value=\&quot;Apretar el botó\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;\&quot; parent=\&quot;1\&quot; source=\&quot;rUmXZGd3vIKuDlGXPuo1-1\&quot; target=\&quot;IcmS1CPiVGpFXhYCCC_2-1\&quot; edge=\&quot;1\&quot;&gt;\n &lt;mxGeometry relative=\&quot;1\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;rUmXZGd3vIKuDlGXPuo1-1\&quot; value=\&quot;Compta quilòmetres\&quot; style=\&quot;swimlane;fontStyle=1;align=center;verticalAlign=middle;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=0;resizeLast=1;container=0;fontColor=#000000;collapsible=0;rounded=1;arcSize=30;strokeColor=#ff0000;fillColor=#ffffc0;swimlaneFillColor=#ffffc0;dropTarget=0;\&quot; parent=\&quot;1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;155\&quot; y=\&quot;160\&quot; width=\&quot;190\&quot; height=\&quot;100\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;rUmXZGd3vIKuDlGXPuo1-2\&quot; value=\&quot;&amp;lt;b&amp;gt;entry&#x2F; &amp;lt;&#x2F;b&amp;gt;Mostrar quilòmetres&amp;lt;div&amp;gt;&amp;lt;b&amp;gt;do&#x2F; &amp;lt;&#x2F;b&amp;gt;Actualitzar els quilòmetres&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;exit&#x2F;&amp;lt;&#x2F;b&amp;gt;&amp;amp;nbsp;Amagar quilòmetres&amp;lt;&#x2F;div&amp;gt;\&quot; style=\&quot;text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;fontColor=#000000;\&quot; parent=\&quot;rUmXZGd3vIKuDlGXPuo1-1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry y=\&quot;30\&quot; width=\&quot;190\&quot; height=\&quot;70\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-6\&quot; value=\&quot;Apretar el botó\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;\&quot; parent=\&quot;1\&quot; source=\&quot;IcmS1CPiVGpFXhYCCC_2-1\&quot; target=\&quot;IcmS1CPiVGpFXhYCCC_2-4\&quot; edge=\&quot;1\&quot;&gt;\n &lt;mxGeometry relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;Array as=\&quot;points\&quot;&gt;\n &lt;mxPoint x=\&quot;250\&quot; y=\&quot;450\&quot; &#x2F;&gt;\n &lt;mxPoint x=\&quot;250\&quot; y=\&quot;450\&quot; &#x2F;&gt;\n &lt;&#x2F;Array&gt;\n &lt;&#x2F;mxGeometry&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-1\&quot; value=\&quot;Distància recorreguda\&quot; style=\&quot;swimlane;fontStyle=1;align=center;verticalAlign=middle;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=0;resizeLast=1;container=0;fontColor=#000000;collapsible=0;rounded=1;arcSize=30;strokeColor=#ff0000;fillColor=#ffffc0;swimlaneFillColor=#ffffc0;dropTarget=0;\&quot; parent=\&quot;1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;160\&quot; y=\&quot;320\&quot; width=\&quot;180\&quot; height=\&quot;110\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-2\&quot; value=\&quot;&amp;lt;b&amp;gt;entry&#x2F; &amp;lt;&#x2F;b&amp;gt;Mostrar distància recorreguda&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;exit&#x2F;&amp;lt;&#x2F;b&amp;gt;&amp;amp;nbsp;Amagar distància recorreguda\&quot; style=\&quot;text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;fontColor=#000000;\&quot; parent=\&quot;IcmS1CPiVGpFXhYCCC_2-1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry y=\&quot;30\&quot; width=\&quot;180\&quot; height=\&quot;80\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-4\&quot; value=\&quot;Consum\&quot; style=\&quot;swimlane;fontStyle=1;align=center;verticalAlign=middle;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=0;resizeLast=1;container=0;fontColor=#000000;collapsible=0;rounded=1;arcSize=30;strokeColor=#ff0000;fillColor=#ffffc0;swimlaneFillColor=#ffffc0;dropTarget=0;\&quot; parent=\&quot;1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;170\&quot; y=\&quot;500\&quot; width=\&quot;160\&quot; height=\&quot;100\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-5\&quot; value=\&quot;&amp;lt;b&amp;gt;entry&#x2F; &amp;lt;&#x2F;b&amp;gt;Mostrar el consum&amp;lt;div&amp;gt;&amp;lt;b&amp;gt;do&#x2F; &amp;lt;&#x2F;b&amp;gt;Actualitzar el consum&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;exit&#x2F;&amp;lt;&#x2F;b&amp;gt;&amp;amp;nbsp;Amagar el consum&amp;lt;&#x2F;div&amp;gt;\&quot; style=\&quot;text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;fontColor=#000000;\&quot; parent=\&quot;IcmS1CPiVGpFXhYCCC_2-4\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry y=\&quot;30\&quot; width=\&quot;160\&quot; height=\&quot;70\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-8\&quot; value=\&quot;Reiniciar distància recorreguda\&quot; style=\&quot;swimlane;fontStyle=1;align=center;verticalAlign=middle;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=0;resizeLast=1;container=0;fontColor=#000000;collapsible=0;rounded=1;arcSize=30;strokeColor=#ff0000;fillColor=#ffffc0;swimlaneFillColor=#ffffc0;dropTarget=0;\&quot; parent=\&quot;1\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;440\&quot; y=\&quot;345\&quot; width=\&quot;210\&quot; height=\&quot;60\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-9\&quot; value=\&quot;&amp;lt;b&amp;gt;do&#x2F; &amp;lt;&#x2F;b&amp;gt;Reiniciar distància recorreguda\&quot; style=\&quot;text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;fontColor=#000000;\&quot; parent=\&quot;IcmS1CPiVGpFXhYCCC_2-8\&quot; vertex=\&quot;1\&quot;&gt;\n &lt;mxGeometry y=\&quot;30\&quot; width=\&quot;210\&quot; height=\&quot;30\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-12\&quot; value=\&quot;Mantindre botó apretat\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.25;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;\&quot; parent=\&quot;1\&quot; source=\&quot;IcmS1CPiVGpFXhYCCC_2-2\&quot; target=\&quot;IcmS1CPiVGpFXhYCCC_2-8\&quot; edge=\&quot;1\&quot;&gt;\n &lt;mxGeometry x=\&quot;0.1858\&quot; y=\&quot;10\&quot; relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;mxPoint x=\&quot;1\&quot; as=\&quot;offset\&quot; &#x2F;&gt;\n &lt;&#x2F;mxGeometry&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-14\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;\&quot; parent=\&quot;1\&quot; source=\&quot;IcmS1CPiVGpFXhYCCC_2-9\&quot; target=\&quot;IcmS1CPiVGpFXhYCCC_2-2\&quot; edge=\&quot;1\&quot;&gt;\n &lt;mxGeometry relative=\&quot;1\&quot; as=\&quot;geometry\&quot; &#x2F;&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;mxCell id=\&quot;IcmS1CPiVGpFXhYCCC_2-15\&quot; value=\&quot;Apretar el botó\&quot; style=\&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;\&quot; parent=\&quot;1\&quot; source=\&quot;IcmS1CPiVGpFXhYCCC_2-4\&quot; target=\&quot;rUmXZGd3vIKuDlGXPuo1-1\&quot; edge=\&quot;1\&quot;&gt;\n &lt;mxGeometry relative=\&quot;1\&quot; as=\&quot;geometry\&quot;&gt;\n &lt;Array as=\&quot;points\&quot;&gt;\n &lt;mxPoint x=\&quot;100\&quot; y=\&quot;565\&quot; &#x2F;&gt;\n &lt;mxPoint x=\&quot;100\&quot; y=\&quot;203\&quot; &#x2F;&gt;\n &lt;&#x2F;Array&gt;\n &lt;mxPoint x=\&quot;100\&quot; y=\&quot;150\&quot; as=\&quot;targetPoint\&quot; &#x2F;&gt;\n &lt;&#x2F;mxGeometry&gt;\n &lt;&#x2F;mxCell&gt;\n &lt;&#x2F;root&gt;\n &lt;&#x2F;mxGraphModel&gt;\n &lt;&#x2F;diagram&gt;\n&lt;&#x2F;mxfile&gt;\n\n&quot;}"></div><script type="text/javascript" src="https://viewer.diagrams.net/js/viewer-static.min.js"></script> <figcaption>Figura 1: Diagrama d'estats d'un comptaquilòmetres</figcaption>