{"id":3122,"date":"2024-03-03T00:00:10","date_gmt":"2024-03-03T00:00:10","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=3122"},"modified":"2024-04-23T07:42:43","modified_gmt":"2024-04-23T07:42:43","slug":"gravity-calculator-java-example","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/gravity-calculator-java-example\/","title":{"rendered":"Gravity Calculator Java Example"},"content":{"rendered":"<h2>GRAVITY CALCULATOR JAVA TASK:<\/h2>\n<p>Create Java gravity calculator, able to determine the object&#8217;s final position after falling through the Earth&#8217;s atmosphere through the predetermined time. The initial parameters include: gravity (-9.81), falling time (10 seconds), as well as initial position and initial velocity of the object (both set to 0 by default). However the user should be able to modify the last 3 parameters according to his liking, with the calculator providing him with corresponding final position each time one of parameters changes.<!--more--><\/p>\n<h2>SOLUTION:<\/h2>\n<p>In this sample we will need to use an equation to determine the final position of the object:<br \/>\n<span style=\"font-size: 1.2em; display: block; white-space: nowrap; text-align: center;\"><i>x(t)\u00a0=\u00a00.5\u00a0\u00d7\u00a0a\u00a0\u00d7\u00a0t<sup style=\"font-size: 11px;\">2<\/sup>\u00a0+\u00a0v<sub style=\"font-size: 11px;\">i<\/sub>\u00a0\u00d7\u00a0t\u00a0+\u00a0x<sub style=\"font-size: 11px;\">i,<\/sub><\/i><\/span><br \/>\nwhere<span style=\"padding-left: 55px; display: block;\"><i>a<\/i> &#8211; gravity = acceleration<br \/>\n<i>t<\/i> &#8211; time<br \/>\n<i>v<sub style=\"font-size: 11px;\">i<\/sub><\/i> &#8211; initial velocity<br \/>\n<i>x<sub style=\"font-size: 11px;\">i<\/sub><\/i> &#8211; initial position<br \/>\n<\/span><\/p>\n<p>With our variables:<br \/>\n<a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3128\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/01.png\" alt=\"Variables\" width=\"529\" height=\"118\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/01.png 529w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/01-300x67.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/a><\/p>\n<p>Given these variables, our equation will look as following:<\/p>\n<pre>finalPosition = 0.5*gravity*fallingTime*fallingTime \r\n                     +initialVelocity*fallingTime + initialPosition;\r\n<\/pre>\n<p>We will use do&#8230;while cycle in or application, each time keeping the user updated with the current state of variables as well as final position of the object derived from them (based on equation):<br \/>\n<a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3138\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/03.png\" alt=\"System.out.println\" width=\"751\" height=\"318\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/03.png 751w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/03-300x127.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/a><\/p>\n<p>We will use a set of if&#8230;else in order to react to the commands signalling about the user&#8217;s desire to change of the variables:<br \/>\n<a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/04.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3144\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/04.png\" alt=\"if...else\" width=\"658\" height=\"459\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/04.png 658w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/04-300x209.png 300w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><\/a><\/p>\n<p>This part of code makes sure that the user will be able to input nothing but digits (of double type) by ignoring the other kinds of input:<\/p>\n<pre>while (!in.hasNextDouble())  \r\n\tin.next();\r\n\r\n<\/pre>\n<p>Therefore, the final code for our application (with console window format in mind) will look like this:<br \/>\n<a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/05-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3152\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/05-1.png\" alt=\"Final code\" width=\"833\" height=\"1464\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/05-1.png 833w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/05-1-171x300.png 171w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/05-1-768x1350.png 768w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/05\/05-1-583x1024.png 583w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/a><\/p>\n<h2>Java Homework Assistance Online<\/h2>\n<blockquote><p><em>We hope you found our gravity calculator Java sample useful and it will help you to cope with your own <a href=\"https:\/\/assignmentshark.com\/do-my-java-homework.html\" target=\"_blank\" rel=\"noopener\">Java homework<\/a> projects. In case you still experience problems with IT assignment, you can count on us. We will provide <a href=\"https:\/\/assignmentshark.com\/java-help.html\" target=\"_blank\" rel=\"noopener noreferrer\"><span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;java homework help&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:515,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16043212},&quot;12&quot;:0}\">Java homework help<\/span><\/a> with tasks of any difficulty level and deadline.<\/em><\/p>\n<p><em>Check out also <a href=\"https:\/\/assignmentshark.com\/blog\/java-program-for-magic-square\/\" target=\"_blank\" rel=\"noopener noreferrer\">Java program for magic square<\/a> sample that may come in handy in your studies.<\/em><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>GRAVITY CALCULATOR JAVA TASK: Create Java gravity calculator, able to determine the object&#8217;s final position after falling through the Earth&#8217;s atmosphere through the predetermined time. The initial parameters include: gravity (-9.81), falling time (10 seconds), as well as initial position and initial velocity of the object (both set to 0 by default). However the user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-3122","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/3122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=3122"}],"version-history":[{"count":34,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/3122\/revisions"}],"predecessor-version":[{"id":13573,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/3122\/revisions\/13573"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=3122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=3122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=3122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}