Java programming 1 p2, h2

[ad_1]

Project 2

 

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.  The table should run from 0 degrees Fahrenheit to 250 degrees Fahrenheit, in steps of 10 degrees.  Round the Celsius temperature values to the nearest integer.

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).

The formula to use is:

Degrees Celsius = ( 5 ÷ 9 ) × ( Degrees Fahrenheit – 32 Degrees )

See TempConv.jar model solution for a sample chart; just download and double-click to run. 

Other Requirements:

You must turn in a stand-alone AWT or swing program, not an Applet or JApplet nor a JavaFx program.  You must meet all the requirements from the description above.  If you include any creative extras, be sure your program still performs the basic chart as described above.  Creative extras are extras, and you are not free to modify the project requirements.

It is not acceptable to pre-compute each Celsius value, and just have many “g.drawString()” statements.  You need to use Java to calculate each value using the correct formula, and use various control structures.

GUI Greet Java

 

// A stand-alone GUI Java program to display a friendly greeting.
2: // Also added code to close the application when the user clicks
3: // the mouse in the close box.
4:
5: // Written by Wayne Pollock, Tampa, FL USA, 1999
6:
7: import java.awt.*;
8: import java.awt.event.*;
9:
10: public class GUIGreet extends Frame
11: {
12:    private String message = "Hello, World!";
13:
14:    public GUIGreet ()
15:    {
16:       setTitle( "A Friendly Greeting" );
17:       setSize( 300, 200 );
18:       setVisible( true );
19:
20:       addWindowListener(
21:          new WindowAdapter()
22:          {  public void windowClosing( WindowEvent e )
23:             {  System.exit( 0 );
24:             }
25:          }
26:       );
27:    }
28:
29:    public static void main ( String [] args )
30:    {
31:       GUIGreet me = new GUIGreet();
32:    }
33:
34:    public void paint ( Graphics g )
35:    {
36:       g.setColor( Color.RED );
37:       g.drawRect( 30, 40, 240, 130 );
38:       g.setColor( Color.BLUE );
39:       g.setFont( new Font( "SansSerif", Font.BOLD, 24 ) );
40:       g.drawString( message, 70, 110 );  // Position determined
41:    }                                     // by trial and error!
42: }

Homework 2

 

  1. Can the following three conversions involving casting be allowed?  If so, find the converted result.    boolean b = true;     int i = (int) b;      int i = 1;     boolean b = (boolean) i;      int i = 1;     String s = (String) i;
  2. What is the printout of the code in (a) and (b): if number is 30?  If number is 35?
    1.     if (number % 2 == 0)            System.out.println(number + ” is even.”);            System.out.println(number + ” is odd.”);
    2.     if (number % 2 == 0)            System.out.println(number + ” is even.”);         else            System.out.println(number + ” is odd.”);
  3. How do you generate a random integer i such that
    1. 0 ≤ i < 20?
    2. 10 ≤ i < 20?
    3. 10 ≤ i ≤ 50?
  4. What is the value of the expression:  (ch >= 'A' && ch <= 'Z')
    1. if ch is 'A'?
    2. if ch is 'p'?
    3. if ch is 'E'?
    4. if ch is '5'?
  5. Write a Boolean expression that evaluates true if weight is greater than 50 pounds or height is greater than 60 inches.
  6. Write a switch statement that assigns to a String variable dayName with Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, if the int variable day is 0, 1, 2, 3, 4, 5, and 6, accordingly.
  7. Evaluate the following two expressions:      2 * 2 – 3 > 2 && 4 – 2 > 5        2 * 2 – 3 > 2 || 4 – 2 > 5
  8. Do the following two loops result in the same value in sum?
    1. 1:      int sum = 0; 2:      for ( int i = 0; i < 10; ++i ) { 3:          sum += i; 4:      }
    2. 1:      int sum = 0; 2:      for ( int i = 0; i < 10; i++ ) { 3:          sum += i; 4:      }
  9. If a variable is declared in the for loop control, can it be used after the loop exits?
  10. The for loop on the left is converted into the while loop on the right.  What is wrong?  Correct it.1: int sum = 0; 2: for (int i = 1; i <= 4; i++) { 3:    if (i % 3 == 0)  continue; 4:    sum += i; 5: }1: int i = 1, sum = 0; 2: while (i <= 4) { 3:    if (i % 3 == 0)  continue; 4:    sum += i; 5:    i++; 6: }
    1. After the break statement is executed in the following loop, which statement is executed?  Show the output.1: for (int i = 1; i < 4; i++) { 2:    for (int j = 1; j < 4; j++) { 3:       if (i * j > 2) 4:          break; 5:          System.out.println(i * j); 6:       } 7:       System.out.println(i); 8: }
    2. After the continue statement is executed in the following loop, which statement is executed?  Show the output.1: for (int i = 1; i < 4; i++) { 2:    for (int j = 1; j < 4; j++) { 3:       if (i * j > 2) 4:          continue; 5:          System.out.println(i * j); 6:       } 7:    System.out.println(i); 8: }
  11. Write a Java regular expression (“regex”), that matches en_US (standard Americian) formatted whole numbers.  Such numbers are composed of only digits and commas.  For example:InputResult From
    Correct Regex,0False,False1,20False1,234,False0True12True123True1,234True0,000True100,000True
Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Australia Assessments
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Healthcare & Medical
Excellent work! This submission had a mature tone and required minimal edits for clarity. We look forward to your future contributions.
Customer 452441, August 5th, 2022
Military
excellent work
Customer 456821, August 14th, 2022
Business Studies
Good
Customer 462893, April 26th, 2022
Computer science
Paper was extremely because support team did not read my request, causing it to be extremely late. I should receive at some type of refund because that one is not on me...
Customer 452515, April 19th, 2020
Military
Excellent work
Customer 456821, February 26th, 2022
English 101
TEST
Customer 463149, July 12th, 2022
English 101
i received the paper early
Customer 461063, November 1st, 2022
Other
Good work on the spreadsheet.
Customer 459155, May 31st, 2022
Math
ALL questions answered.
Customer 453625, April 7th, 2022
Business
Great job
Customer 452947, January 22nd, 2020
Military
Excellent job
Customer 456821, November 30th, 2022
Business and administrative studies
Turned in the new assignment,. Everything was great
Customer 463053, December 4th, 2022
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat