calling a method to display the results

On 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 Rate Topic: -----

#1 tricket_7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 09-May 09

calling a method to display the results

Post icon  Posted 01 December 2009 - 12:13 PM

What am I doing wrong here on the getStation() I have tried stationCode.getStation, s.getStation() Help
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";
		
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: calling a method to display the results

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

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.
public static String getStation(String s) {
//code


but when you call it, you sont supply it any parameter:
stationName = getStation();


Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9044
  • View blog
  • Posts: 33,551
  • Joined: 27-December 08

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);
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1