Jump to content

Need Help For Java Program


Recommended Posts

Posted

[color=#282828][font=helvetica, arial, sans-serif][size=4]
hi can anybody please help me in doing java program i need to submit my assignment on monday


Here's the question:-[color=#000000][font=verdana, sans-serif][size=3][b][i](Temperature Conversion)[/i][/b][/size][/font][/color][color=#000000][font=verdana, sans-serif][size=3]Write a temperature-conversion application that converts from Fahrenheit to Celsius. The Fahrenheit temperature should be entered from the keyboard (via a [/size][/font][/color]JTextField[color=#000000][font=verdana, sans-serif][size=3]). A [/size][/font][/color]J Label[font=verdana, sans-serif][color=#000000][size=3] should be used to display the converted temperature. Use the following formula for the conversion: [/size][/color][/font]
[font=verdana, sans-serif][color=#000000][size=3]Celsius= 5/9*([/size][size=3]Fahrenheit[/size][size=3] -32)[/size][/color][/font][/size][/font][/color]

Posted

http://www.roseindia.net/java/example/java/swing/convert-temperature.shtml

Posted

[CODE]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CTemp extends JFrame
implements ActionListener {
private JButton button;
public static void main(String[] args) {
CTemp frame = new CTemp();
frame.setSize(400, 300);
frame.createGUI();
frame.setVisible(true);
}
private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout() );
button = new JButton("Fahrenheit converted to Celsius");
window.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
int fahrenheit, celsius;
String fahrenheitString;

fahrenheitString = JOptionPane.showInputDialog("Tempature in Fahrenheit: ");
fahrenheit = Integer.parseInt(fahrenheitString);
celsius = (5 / 9) * (fahrenheit - 32);
JOptionPane.showMessageDialog(null, fahrenheit + " Degrees Fahrenheit\n" + "converted to\n" + celsius + " Degrees Celsius");
}
}
[/CODE]

Posted

nenu ichina code lo konni errors undochu.. oka sari check chesko :)

and also assignment submit cheseppudu class names n method names instance variable anni change cheyi alli plagiarism antaaremo

Posted

@hava5 -[color=#000000][font=helvetica, arial, sans-serif][font=verdana, sans-serif][size=3] [/size][/font][/font][/color][color=#282828][font=helvetica, arial, sans-serif]J Label[/font][/color][color=#282828][font=verdana, sans-serif][color=#000000][size=3] should be used to display the converted temperature. Using the formula [/size][/color][/font][/color]

Posted

[CODE]

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
// This example demonstrates the use of JButton, JTextField and JLabel.
public class TempConversion implements ActionListener {
JFrame converterFrame;
JPanel converterPanel;
JTextField tempCelsius;
JLabel celsiusLabel, fahrenheitLabel;
JButton convertTemp;
// Constructor
public TempConversion() {
// Create the frame and container.
converterFrame = new JFrame("Convert Celsius to Fahrenheit");
converterPanel = new JPanel();
converterPanel.setLayout(new GridLayout(2, 2));
// Add the widgets.
addWidgets();
// Add the panel to the frame.
converterFrame.getContentPane()
.add(converterPanel, BorderLayout.CENTER);
// Exit when the window is closed.
converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Show the converter.
converterFrame.pack();
converterFrame.setVisible(true);
}
// Create and add the widgets for converter.
private void addWidgets() {
// Create widgets.
tempCelsius = new JTextField(2);
celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
convertTemp = new JButton("Convert...");
fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);
// Listen to events from Convert button.
convertTemp.addActionListener(this);
// Add widgets to container.
converterPanel.add(tempCelsius);
converterPanel.add(celsiusLabel);
converterPanel.add(convertTemp);
converterPanel.add(fahrenheitLabel);
celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event) {
// Parse degrees Celsius as a double and convert to Fahrenheit.
int tempFahr = (int) ((Double.parseDouble(tempCelsius.getText())) * 1.8 + 32);
fahrenheitLabel.setText(tempFahr + " Fahrenheit");
}
// main method
public static void main(String[] args) {
// Set the look and feel.
try {
UIManager.setLookAndFeel(UIManager
.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
}
TempConversion converter = new TempConversion();
}
}
[/CODE]


idhi try chey vayya... kakapothe logic cahnge chesko ne req patti or formula ni batti ..

×
×
  • Create New...