Java programming 1 p2, h2

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
Punctual Essays
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.