{"id":15259,"date":"2021-11-12T04:30:34","date_gmt":"2021-11-12T04:30:34","guid":{"rendered":"https:\/\/assignmenttutors.net\/blog\/java-programming-1-p2-h2\/"},"modified":"2021-11-12T04:30:34","modified_gmt":"2021-11-12T04:30:34","slug":"java-programming-1-p2-h2","status":"publish","type":"post","link":"https:\/\/assignmenttutors.net\/blog\/java-programming-1-p2-h2\/","title":{"rendered":"Java programming 1 p2, h2"},"content":{"rendered":"<div>\n<p><strong>Project 2<\/strong><\/p>\n<p>\u00a0<\/p>\n<h2>Description:<\/h2>\n<p>Using <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/wpollock.com\/lister.php?file=Java\/GUIGreet.java&amp;nodir&amp;dl&amp;linenums\">GUIGreet.java<\/a> as a model, create a Java stand-alone GUI program that displays a Fahrenheit to Celsius temperature conversion table in an AWT <code>Frame<\/code> or a swing <code>JFrame<\/code>.\u00a0 The table should run from 0\u00a0degrees Fahrenheit to 250\u00a0degrees Fahrenheit, in steps of 10 degrees.\u00a0 Round the Celsius temperature values to the nearest integer.<\/p>\n<p>Display any temperatures below the freezing point of water (32o Fahrenheit) in blue and any temperatures above the boiling point of water (212o Fahrenheit) in red (the rest in black).<\/p>\n<p>The formula to use is:<\/p>\n<p>Degrees Celsius = ( 5 \u00f7 9 ) \u00d7 ( Degrees Fahrenheit &#8211; 32 Degrees )<\/p>\n<p>See <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/wpollock.com\/Java\/TempConv\/TempConv.jar\">TempConv.jar<\/a> model solution for a sample chart; just download and double-click to run.\u00a0<\/p>\n<h2>Other Requirements:<\/h2>\n<p>You must turn in a stand-alone AWT or swing program, not an <code>Applet<\/code> or <code>JApplet<\/code> nor a JavaFx program.\u00a0 You must meet all the requirements from the description above.\u00a0 If you include any creative extras, be sure your program still performs the basic chart as described above.\u00a0 Creative extras are <em>extras<\/em>, and you are not free to modify the project requirements.<\/p>\n<p>It is <strong>not acceptable<\/strong> to pre-compute each Celsius value, and just have many \u201c<code>g.drawString()<\/code>\u201d statements.\u00a0 You need to use Java to calculate each value using the correct formula, and use various control structures.<\/p>\n<p>GUI Greet Java<\/p>\n<p>\u00a0<\/p>\n<pre><code>\/\/ A stand-alone GUI Java program to display a friendly greeting.<br\/><strong> 2: <\/strong>\/\/ Also added code to close the application when the user clicks<br\/><strong> 3: <\/strong>\/\/ the mouse in the close box.<br\/><strong> 4: <\/strong><br\/><strong> 5: <\/strong>\/\/ Written by Wayne Pollock, Tampa, FL USA, 1999<br\/><strong> 6: <\/strong><br\/><strong> 7: <\/strong>import java.awt.*;<br\/><strong> 8: <\/strong>import java.awt.event.*;<br\/><strong> 9: <\/strong><br\/><strong>10: <\/strong>public class GUIGreet extends Frame<br\/><strong>11: <\/strong>{<br\/><strong>12: <\/strong>\u00a0\u00a0\u00a0private String message = \"Hello, World!\";<br\/><strong>13: <\/strong><br\/><strong>14: <\/strong>\u00a0\u00a0\u00a0public GUIGreet ()<br\/><strong>15: <\/strong>\u00a0\u00a0\u00a0{<br\/><strong>16: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setTitle( \"A Friendly Greeting\" );<br\/><strong>17: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setSize( 300, 200 );<br\/><strong>18: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setVisible( true );<br\/><strong>19: <\/strong><br\/><strong>20: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0addWindowListener(<br\/><strong>21: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new WindowAdapter()<br\/><strong>22: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0public void windowClosing( WindowEvent e )<br\/><strong>23: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \u00a0System.exit( 0 );<br\/><strong>24: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<br\/><strong>25: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<br\/><strong>26: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);<br\/><strong>27: <\/strong>\u00a0\u00a0\u00a0}<br\/><strong>28: <\/strong><br\/><strong>29: <\/strong>\u00a0\u00a0\u00a0public static void main ( String [] args )<br\/><strong>30: <\/strong>\u00a0\u00a0\u00a0{<br\/><strong>31: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0GUIGreet me = new GUIGreet();<br\/><strong>32: <\/strong>\u00a0\u00a0\u00a0}<br\/><strong>33: <\/strong><br\/><strong>34: <\/strong>\u00a0\u00a0\u00a0public void paint ( Graphics g )<br\/><strong>35: <\/strong>\u00a0\u00a0\u00a0{<br\/><strong>36: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0g.setColor( Color.RED );<br\/><strong>37: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0g.drawRect( 30, 40, 240, 130 );<br\/><strong>38: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0g.setColor( Color.BLUE );<br\/><strong>39: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0g.setFont( new Font( \"SansSerif\", Font.BOLD, 24 ) );<br\/><strong>40: <\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0g.drawString( message, 70, 110 ); \u00a0\/\/ Position determined<br\/><strong>41: <\/strong>\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ by trial and error!<br\/><strong>42: <\/strong>}<\/code><\/pre>\n<p><strong>Homework 2<\/strong><\/p>\n<p>\u00a0<\/p>\n<ol>\n<li>C<strong>an the following three conversions involving casting be allowed?\u00a0 If so, find the converted result. \u00a0\u00a0\u00a0boolean b = true; \u00a0\u00a0\u00a0\u00a0int i = (int) b; \u00a0\u00a0\u00a0\u00a0\u00a0int i = 1; \u00a0\u00a0\u00a0\u00a0boolean b = (boolean) i; \u00a0\u00a0\u00a0\u00a0\u00a0int i = 1; \u00a0\u00a0\u00a0\u00a0String s = (String) i;<\/strong><\/li>\n<li><strong>What is the printout of the code in (a) and (b): if <\/strong><code><strong>number<\/strong><\/code><strong> is <\/strong><code><strong>30<\/strong><\/code><strong>?\u00a0 If <\/strong><code><strong>number<\/strong><\/code><strong> is <\/strong><code><strong>35<\/strong><\/code><strong>?<\/strong>\n<ol>\n<li><strong>\u00a0\u00a0\u00a0\u00a0if (number % 2 == 0) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(number + &#8221; is even.&#8221;); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(number + &#8221; is odd.&#8221;);<\/strong><\/li>\n<li><strong>\u00a0\u00a0\u00a0\u00a0if (number % 2 == 0) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(number + &#8221; is even.&#8221;); \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(number + &#8221; is odd.&#8221;);<\/strong><\/li>\n<\/ol>\n<\/li>\n<li><strong>How do you generate a random integer <\/strong><code><strong>i<\/strong><\/code><strong> such that<\/strong>\n<ol>\n<li><code><strong>0 \u2264 i &lt; 20<\/strong><\/code><strong>?<\/strong><\/li>\n<li><code><strong>10 \u2264 i &lt; 20<\/strong><\/code><strong>?<\/strong><\/li>\n<li><code><strong>10 \u2264 i \u2264 50<\/strong><\/code><strong>?<\/strong><\/li>\n<\/ol>\n<\/li>\n<li><strong>What is the value of the expression:\u00a0 <\/strong><code><strong>(ch &gt;= 'A' &amp;&amp; ch &lt;= 'Z')<\/strong><\/code>\n<ol>\n<li><strong>if <\/strong><code><strong>ch<\/strong><\/code><strong> is <\/strong><code><strong>'A'<\/strong><\/code><strong>?<\/strong><\/li>\n<li><strong>if <\/strong><code><strong>ch<\/strong><\/code><strong> is <\/strong><code><strong>'p'<\/strong><\/code><strong>?<\/strong><\/li>\n<li><strong>if <\/strong><code><strong>ch<\/strong><\/code><strong> is <\/strong><code><strong>'E'<\/strong><\/code><strong>?<\/strong><\/li>\n<li><strong>if <\/strong><code><strong>ch<\/strong><\/code><strong> is <\/strong><code><strong>'5'<\/strong><\/code><strong>?<\/strong><\/li>\n<\/ol>\n<\/li>\n<li><strong>Write a Boolean expression that evaluates <\/strong><code><strong>true<\/strong><\/code><strong> if <\/strong><code><strong>weight<\/strong><\/code><strong> is greater than <\/strong><code><strong>50<\/strong><\/code><strong> pounds or <\/strong><code><strong>height<\/strong><\/code><strong> is greater than <\/strong><code><strong>60<\/strong><\/code><strong> inches.<\/strong><\/li>\n<li><strong>Write a switch statement that assigns to a <\/strong><code><strong>String<\/strong><\/code><strong> variable <\/strong><code><strong>dayName<\/strong><\/code><strong> with <\/strong><code><strong>Sunday<\/strong><\/code><strong>, <\/strong><code><strong>Monday<\/strong><\/code><strong>, <\/strong><code><strong>Tuesday<\/strong><\/code><strong>, <\/strong><code><strong>Wednesday<\/strong><\/code><strong>, <\/strong><code><strong>Thursday<\/strong><\/code><strong>, <\/strong><code><strong>Friday<\/strong><\/code><strong>, and <\/strong><code><strong>Saturday<\/strong><\/code><strong>, if the <\/strong><code><strong>int<\/strong><\/code><strong> variable <\/strong><code><strong>day<\/strong><\/code><strong> is <\/strong><code><strong>0<\/strong><\/code><strong>, <\/strong><code><strong>1<\/strong><\/code><strong>, <\/strong><code><strong>2<\/strong><\/code><strong>, <\/strong><code><strong>3<\/strong><\/code><strong>, <\/strong><code><strong>4<\/strong><\/code><strong>, <\/strong><code><strong>5<\/strong><\/code><strong>, and <\/strong><code><strong>6<\/strong><\/code><strong>, accordingly.<\/strong><\/li>\n<li><strong>Evaluate the following two expressions: \u00a0\u00a0\u00a0\u00a0\u00a02 * 2 &#8211; 3 &gt; 2 &amp;&amp; 4 &#8211; 2 &gt; 5 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02 * 2 &#8211; 3 &gt; 2 || 4 &#8211; 2 &gt; 5<\/strong><\/li>\n<li><strong>Do the following two loops result in the same value in sum?<\/strong>\n<ol>\n<li><strong>1: \u00a0\u00a0\u00a0\u00a0\u00a0int sum = 0; 2: \u00a0\u00a0\u00a0\u00a0\u00a0for ( int i = 0; i &lt; 10; ++i ) { 3: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sum += i; 4: \u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/li>\n<li><strong>1: \u00a0\u00a0\u00a0\u00a0\u00a0int sum = 0; 2: \u00a0\u00a0\u00a0\u00a0\u00a0for ( int i = 0; i &lt; 10; i++ ) { 3: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sum += i; 4: \u00a0\u00a0\u00a0\u00a0\u00a0}<\/strong><\/li>\n<\/ol>\n<\/li>\n<li><strong>If a variable is declared in the for loop control, can it be used after the loop exits?<\/strong><\/li>\n<li><strong>The <\/strong><code><strong>for<\/strong><\/code><strong> loop on the left is converted into the <\/strong><code><strong>while<\/strong><\/code><strong> loop on the right.\u00a0 What is wrong?\u00a0 Correct it.1: int sum = 0; 2: for (int i = 1; i &lt;= 4; i++) { 3: \u00a0\u00a0\u00a0if (i % 3 == 0) \u00a0continue; 4: \u00a0\u00a0\u00a0sum += i; 5: }1: int i = 1, sum = 0; 2: while (i &lt;= 4) { 3: \u00a0\u00a0\u00a0if (i % 3 == 0) \u00a0continue; 4: \u00a0\u00a0\u00a0sum += i; 5: \u00a0\u00a0\u00a0i++; 6: }<\/strong>\n<ol>\n<li><strong>After the <\/strong><code><strong>break<\/strong><\/code><strong> statement is executed in the following loop, which statement is executed?\u00a0 Show the output.1: for (int i = 1; i &lt; 4; i++) { 2: \u00a0\u00a0\u00a0for (int j = 1; j &lt; 4; j++) { 3: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (i * j &gt; 2) 4: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break; 5: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(i * j); 6: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} 7: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(i); 8: }<\/strong><\/li>\n<li><strong>After the <\/strong><code><strong>continue<\/strong><\/code><strong> statement is executed in the following loop, which statement is executed?\u00a0 Show the output.1: for (int i = 1; i &lt; 4; i++) { 2: \u00a0\u00a0\u00a0for (int j = 1; j &lt; 4; j++) { 3: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (i * j &gt; 2) 4: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0continue; 5: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(i * j); 6: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} 7: \u00a0\u00a0\u00a0System.out.println(i); 8: }<\/strong><\/li>\n<\/ol>\n<\/li>\n<li><strong>Write a Java regular expression (\u201cregex\u201d), that matches en_US (standard Americian) formatted whole numbers.\u00a0 Such numbers are composed of only digits and commas.\u00a0 For example:InputResult From<br \/>Correct Regex,0False,False1,20False1,234,False0True12True123True1,234True0,000True100,000True<\/strong><\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Project 2 \u00a0 Description: Using GUIGreet.java as a model, create a Java stand-alone GUI program that displays a Fahrenheit to Celsius temperature conversion table in an AWT Frame or a swing JFrame.\u00a0 The table should run from 0\u00a0degrees Fahrenheit to 250\u00a0degrees Fahrenheit, in steps of 10 degrees.\u00a0 Round the Celsius temperature values to the nearest [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-15259","post","type-post","status-publish","format-standard","hentry","category-homework-help"],"_links":{"self":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts\/15259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/comments?post=15259"}],"version-history":[{"count":0,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/posts\/15259\/revisions"}],"wp:attachment":[{"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/media?parent=15259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/categories?post=15259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmenttutors.net\/blog\/wp-json\/wp\/v2\/tags?post=15259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}