import javax.swing.JOptionPane;
import java.util.*;
public class Ch10Ex04
{
public static void main (String [] args)
{
String weatherData;
String stationCode, strTemp, strWindSpeed, stationName;
double temp;
int windSpeed;
weatherData = JOptionPane.showInputDialog(null, "Please enter the weather station data:");
stationCode = weatherData.substring(0, 3);
strTemp = weatherData.substring(4, 9);
strWindSpeed = weatherData.substring(9, 12);
temp = Double.parseDouble(strTemp);
windSpeed = Integer.parseInt(strWindSpeed);
stationName = getStation(); // call getStation method, provided below
JOptionPane.showMessageDialog(null, "Readings for " + stationName + "\n" +
"Current Temperature: " + temp + " degrees F.\n" +
"Wind Speed: " + windSpeed + " mph.\n");
}
public static String getStation(String s) // Does not need to be changed
{
if (s.equals("ASH"))
return "Asheville";
else if (s.equals("HEN"))
return "Hendersonville";
else if (s.equals("BOO"))
return "Boone";
else
return "Unknown Station";
}
}
calling a method to display the resultsOn this exercise the only thing not working is get() method, I have tr
Page 1 of 1
2 Replies - 706 Views - Last Post: 01 December 2009 - 12:22 PM
#1
calling a method to display the results
Posted 01 December 2009 - 12:13 PM
What am I doing wrong here on the getStation() I have tried stationCode.getStation, s.getStation() Help
Replies To: calling a method to display the results
#2
Re: calling a method to display the results
Posted 01 December 2009 - 12:21 PM
The getStation(String s) method you declared expects a String object as a parameter.
but when you call it, you sont supply it any parameter:
public static String getStation(String s) {
//code
but when you call it, you sont supply it any parameter:
stationName = getStation();
#3
Re: calling a method to display the results
Posted 01 December 2009 - 12:22 PM
The method getStation() is expecting a String parameter. You are calling the method getStation() that takes no parameters, which isn't defined in your class. Try calling it by using the stationCode as the parameter like so: getStation(stationCode);
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|