Question
hi, i am trying to make a java program for my project. the name of the project is weather project. in which i want to
hi, i am trying to make a java program for my project. the name of the project is weather project. in which i want to calculate the windchill and cloudbase. i made the program but its giving me a garbage data when it comes on output so i need help in making the program. it is a java project and have to make the project in eclipse. thanks
here is the requirements: Design and create a GUI program for a meteorologist in Java that calculates the wind chill factor and cloud base altitude for inputs of temperature in Fahrenheit, wind speed in mph, and the dew point in Fahrenheit. The inputs can be entered from the keyboard or a file. The output is displayed in the man GUI (if keyboard entry is selected) and a display window created using a class for either data entry selection (separate classes are recommended for each output display). When the program begins, the main GUI will open. When data is entered, and the compute button is clicked, the values computed will be displayed in the main (GUI) data entry window and a column formatted data output window. The formatting of the data in the column formatted output window will include the units and comma separators for thousands. The entry widgets will accept input right-aligned, check for errors, and the window will have a title and a window icon. Each time a new set of data is entered on the keyboard, the main GUI will update and the data output display window will be updated to add the new input data and results. Note that column headers, output alignment, units, commas, and decimal places must be included in the column data displayed. If data entered from the keyboard is invalid, an error dialog message will be displayed, the label text will indicate an error, the output display window will not be updated, and the program will continue. When file entry is selected, a file selection (JFileChooser) window will be displayed. File opening errors will be handled with exceptions and a dialog box. If the file is valid and opened successfully, the program will read in the data, compute the results, and display the data and results in columns in a new display window created through a separate class and java file. The output data display windows will have a window title and icon, a title for the data, output alignment, units, commas, decimal places, and column headers. The display window for file data output will also have a way for the user to sort the data in the display in ascending order by column. The program will loop when certain windows are closed or a Cancel button is clicked so that it does not have to be restarted by the user. A Design Document (Word file) is required and will be submitted at all milestones and be presented as a part of project demonstrations. It will include implementation screen captures, descriptions, and explanations of functionality in the program, as well as the code (see the sample file). Three (3) presentations are required during the semester (Milestone 2, 4, and 6 - final demonstration). The Design document will be presented first during each presentation, and then the program operation will be demonstrated.
here is my code:
Gui.java
package windchill;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.plaf.FileChooserUI;
public class GUI extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel label1, label2, label3, label4;
JTextField t1, t2, t3;
JButton fileButton, computeButton;
public GUI() {
setLayout(null);
setSize(500, 500);
setTitle(" Weather Project");
label1 = new JLabel("Wind Chill Factor");
label1.setBounds(50, 30, 150, 30);
label2 = new JLabel("Enter The Temperature In Degrees (Fahreheit)");
label2.setBounds(30, 100, 270, 30);
label3 = new JLabel("Enter The Wind Speed In (mph)");
label3.setBounds(30, 200, 200, 30);
label4 = new JLabel("Enter The Dew Point In Degrees (Fahreheit)");
label4.setBounds(30, 300, 250, 30);
t1 = new JTextField();
t1.setBounds(300, 100, 120, 30);
t2 = new JTextField();
t2.setBounds(300, 200, 120, 30);
t3 = new JTextField();
t3.setBounds(300, 300, 120, 30);
fileButton = new JButton("File Entry");
fileButton.setBackground(Color.ORANGE);
fileButton.setBounds(30, 380, 120, 30);
computeButton = new JButton("Compute");
computeButton.setBackground(Color.ORANGE);
computeButton.setBounds(300, 380, 120, 30);
add(label1);
add(label2);
add(label3);
add(label4);
add(t1);
add(t2);
add(t3);
add(fileButton);
add(computeButton);
t1.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = ke.getKeyChar();
if (!(Character.isDigit(c))) {
ke.consume();
}
}
});
t2.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = ke.getKeyChar();
if (!(Character.isDigit(c))) {
ke.consume();
}
}
});
t3.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = ke.getKeyChar();
if (!(Character.isDigit(c))) {
ke.consume();
}
}
});
fileButton.addActionListener(this);
computeButton.addActionListener(this);
}
// Action listener on Choose File
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == fileButton) {
JFileChooser fc = new JFileChooser();
FileChooserUI data = fc.getUI();
ListShow listShow = new ListShow();
listShow.showFunc(data);
}
//Action listener on Compute Button
if (ae.getSource() == computeButton) {
try {
if ((t1.getText().equals("")) || (t2.getText().equals(""))
|| (t3.getText().equals(""))) {
JOptionPane.showMessageDialog(null,
"Fields Cannot Be Empty");
}
int temp = Integer.parseInt(t1.getText());
int speed = Integer.parseInt(t2.getText());
int dew = Integer.parseInt(t3.getText());
if (temp <= 50 && speed >= 3) {
WindChill wc = new WindChill(temp, speed, dew);
wc.setVisible(true);
} else {
JOptionPane.showMessageDialog(null,
"An Invalid Value Has Been Entered");
}
} catch (Exception e) {
System.out.println("Fields Cannot Be Empty");
}
}
}
public static void main(String[] args) {
GUI g1 = new GUI();
g1.setVisible(true);
g1.setIconImage(Toolkit.getDefaultToolkit().getImage("Users\\Desktop\\weather.png"));
}
}
WindChill.java
package windchill;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class WindChill extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel l1, l2, l3;
JButton windChillButton, cloudBaseButton, showDataInTable;
JTextField t1, t2, t3, t4, t5;
int temp, speed, dew;
public WindChill(double temp, double speed, double dew) {
setLayout(null);
setSize(550, 550);
l1 = new JLabel("Temperature in Farenhiet is: ");
l1.setBounds(30, 100, 270, 30);
t1 = new JTextField("" + temp);
t1.setBounds(300, 100, 120, 30);
l2 = new JLabel("Speed in mph is: ");
l2.setBounds(30, 200, 200, 30);
t2 = new JTextField("" + speed);
t2.setBounds(300, 200, 120, 30);
l3 = new JLabel("Dew is: ");
l3.setBounds(30, 300, 250, 30);
t3 = new JTextField("" + dew);
t3.setBounds(300, 300, 120, 30);
windChillButton = new JButton("Calculate Wind Chill Factor");
windChillButton.setBackground(Color.ORANGE);
windChillButton.setBounds(30,350,150,30);
cloudBaseButton = new JButton("Calculate Cloud Base Altitude");
cloudBaseButton.setBackground(Color.ORANGE);
cloudBaseButton.setBounds(30, 400,150,30);
showDataInTable = new JButton("Save Values to Table");
showDataInTable.setBounds(100, 450, 300, 30);
t4 = new JTextField(20);
t4.setBounds(300, 350, 120, 30);
t5 = new JTextField(20);
t5.setBounds(300, 400, 120, 30);
t1.setEditable(false);
t2.setEditable(false);
t3.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(windChillButton);
add(cloudBaseButton);
add(t4);
add(t5);
add(showDataInTable);
windChillButton.addActionListener(this);
cloudBaseButton.addActionListener(this);
showDataInTable.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
temp = Integer.parseInt(t1.getText());
speed = Integer.parseInt(t2.getText());
if (e.getSource() == windChillButton) {
double windChill = 35.74 + 0.6215 * temp + (0.4275 * temp - 35.75) * Math.pow(speed, 0.16); // Magnified formula to calculate windChill
String s = String.valueOf(windChill);
t4.setText(s);
}
if (e.getSource() == cloudBaseButton) {
double temp_spread = temp - dew;
double cloudbase = temp_spread / (4.4 * 1000);
String s1 = String.valueOf(cloudbase);
t5.setText(s1);
}
if (e.getSource() == showDataInTable)
{
t1.getText();
t2.getText();
t3.getText();
t4.getText();
t5.getText();
ListShow l1 = new ListShow();
l1.setVisible(true);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started