Could someone please help me with the below lab. I also included my code from la
ID: 3647791 • Letter: C
Question
Could someone please help me with the below lab. I also included my code from last week. I am not sure how to go about updating my code to meet the criteria they are asking for. ThanksThis week's lab will require you to log in to the Citrix iLab system, where you will be using the Eclipse IDE to program this lab's Java applications. The lab requires you to modify last week's temperature conversion program. Remember that this week's assignment requires you to write your program in Java.
Deliverables
The student will submit the following to the Dropbox.
Source code for program 1
Screenshot of output for program 1
i L A B S T E P S
Program 1: Temperature Conversion Program Version 2
You will rewrite the temperature conversion program from the previous week. Your GUI application must inherit from the JFrame class. The GUI and event handling setup should be done in the constructor. Do not use any of the GUI editing capabilities of Eclipse for this assignment. The temperature conversion application should have a label and JTextField in which the user inputs a value which must appear in the upper part of the frame. There should be a set of three radio buttons which indicate the input scale of the value to be converted.
There should also be a set of three radio buttons which indicate the output scale to be converted to. The three input scale buttons must appear vertically aligned (i.e., use a JPanel) on the left side of the display, and the three output scale buttons must appear vertically aligned (i.e., use another JPanel) and appear on the right side of the display. Event handling should be set up so that selection of any input or output radio button causes an event which triggers the event handling code to determine which of nine possible conversions is needed. You can display the result in an output text field or in a Jlabel which appears in the bottom part of the display.
Your program should accurately convert from Fahrenheit, Celsius, Kelvin to Fahrenheit, Celsius, Kelvin. NOTE: Only the selected conversion is displayed in the output area!!! When the conversion selection changes, the output area should change to show only the new result. The output should display three digits after the decimal point. HINT: Use the ItemListener interface and use the isSelected method on the radio buttons to learn which buttons are turned on!
NOTE: you can find conversion formulas at the following website: http://library.thinkquest.org/20991/gather/formula/data/129.html.
Below is my code that needs to be updated!!!!!
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class temperature extends JFrame
{
private JLabel results;
private JButton FarenheittoCelsius;
private JButton CelsiustoFarenheit;
private JButton KelvintoCelsius;
private JButton CelsiustoKelvin;
private JButton KelvintoFarenheit;
private JButton FarenheittoKelvin;
private JTextField temp;
public temperature()
{
setTitle("Temperature Convertor GUI");
JLabel input = new JLabel("Enter a Temperature:");
temp = new JTextField();
JLabel output = new JLabel("The converted temperature is:");
results = new JLabel();
JPanel userInfoPanel = new JPanel( new GridLayout( 2, 2) );
userInfoPanel.add(input);
userInfoPanel.add(temp);
userInfoPanel.add(output);
userInfoPanel.add(results);
ActionListener buttons = new Button();
FarenheittoCelsius = new JButton("Farenheit to Celsius");
FarenheittoCelsius.addActionListener( buttons );
CelsiustoFarenheit = new JButton("Celsius to Farenheit");
CelsiustoFarenheit.addActionListener( buttons );
KelvintoCelsius = new JButton("Kelvin to Celsius");
KelvintoCelsius.addActionListener( buttons );
CelsiustoKelvin = new JButton("Celsius to Kelvin");
CelsiustoKelvin.addActionListener( buttons );
KelvintoFarenheit = new JButton("Kelvin to Farenheit");
KelvintoFarenheit.addActionListener( buttons );
FarenheittoKelvin = new JButton("Farenheit to Kelvin");
FarenheittoKelvin.addActionListener( buttons );
JPanel buttonsPanel = new JPanel( new GridLayout(3,2) );
buttonsPanel.add(FarenheittoCelsius);
buttonsPanel.add(CelsiustoFarenheit);
buttonsPanel.add(KelvintoCelsius);
buttonsPanel.add(CelsiustoKelvin );
buttonsPanel.add(KelvintoFarenheit);
buttonsPanel.add(FarenheittoKelvin);
setLayout(new BorderLayout());
add(userInfoPanel, BorderLayout.CENTER);
add(buttonsPanel, BorderLayout.SOUTH);
setSize(800, 225);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void displayResult(double result)
{
DecimalFormat type = new DecimalFormat();
results.setText(type.format(result));
}
private void displayErrorMessage(String message)
{
results.setText(message);
}
private class Button implements ActionListener
{
public void actionPerformed(ActionEvent text)
{
Object source = text.getSource();
double res = 0;
double userinput;
String in = null;
try
{
in = temp.getText( );
userinput = Double.parseDouble( in );
}
catch(Exception question)
{
displayErrorMessage("This is not a valid number");
return;
}
if(source == FarenheittoCelsius)
{
res = 5.0/9.0 * (userinput - 32);
}
else if(source == CelsiustoFarenheit)
{
res = (1.8 * userinput) + 32;
}
else if(source == KelvintoCelsius)
{
res = userinput - 273;
}
else if (source == CelsiustoKelvin)
{
res = userinput + 273;
}
else if(source == KelvintoFarenheit)
{
res = ((userinput - 273) * 1.8) + 32;
}
else if(source == FarenheittoKelvin)
{
res = 5.0/9.0 * (userinput - 32) + 273;
}
displayResult(res);
}
}
public static void main(String[] args)
{
new temperature().setVisible(true);
}
}
Explanation / Answer
Class temperature is public, should be declared in a file named temperature.java public class temperature extends JFrame
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.