我不断收到消息
线程“main”中的异常 java.lang.NoSuchMethodError: WeatherInput: method ()V not found
在我正在从事的这个项目的客户课程中,我不知道为什么,我想知道这里是否有人能看到我缺少的东西?
这是我的服务类:
class WeatherInput
{
private static final String NEWLINE = "\n";
private double temp;
private double tempAverage;
private double tempHigh;
private double tempLow;
private double tempHundred;
public String newCity = new String();
public String city = new String();
public WeatherInput( String city) {
temp = 0;
tempAverage = 0;
tempHigh = 0;
tempLow = 0;
tempHundred = 0;
newCity = city;
}
public void setTemp( double temprature)
{
temp = temp;
}
public void tempCalc(String city)
{
while(!city.equals("*"))
{
city = newCity;
}
while(temp != 0)
{
tempAverage = (temp + temp)/2;
if(tempHigh > temp)
tempHigh = temp;
if(tempLow < temp)
tempLow = temp;
if(temp > 100)
tempHundred = temp;
temp++;
}
System.out.print(tempAverage);
}
public String printString(){
return NEWLINE + "Statistics for: " + newCity + "Average: " + tempAverage + "High: " + tempHigh + "Low: " + "Over 100: "
+ tempHundred + NEWLINE;
}
}
这是我的客户:
import java.util.*; //For Scanner and class
//----------------------------------------------------------------------------------
//Class Name: KosmowsiProg2
//Description: This class has one method, the main method
//----------------------------------------------------------------------------------
public class KosmowskiProg2
{
//-------------------------------------------------------------------------------
//Method Name: main
//-------------------------------------------------------------------------------
public static void main(String[] args)
{
//-----------------------Local Constants--------------------------------------
//-----------------------Local Variables--------------------------------------
double newTemp;
//-----------------------Objects----------------------------------------------
Scanner scanner = new Scanner(System.in);
String city = new String();
String inputCity = new String();
WeatherInput input = new WeatherInput();
WeatherInput input2 = new WeatherInput();
//---------------------Method Body--------------------------------------------
System.out.print("Please enter the names of the cities, ending in a *");
inputCity = scanner.next();
System.out.print("Please enter the tempratures, ending in a 0");
newTemp = scanner.nextDouble();
input.setTemp(newTemp);
input.tempCalc(inputCity);
}//End main method
private static void printResults(WeatherInput in){
System.out.print(in.printString());
}
}//End class KosmowskiProg2
我正在创建一个服务类,然后我可以将其传递给客户端类,该类将读取以“*”结尾的城市列表,然后为每个城市读取以“0”结尾的温度列表。然后它必须计算平均温度,最高和最低,然后将它们与任何超过 100 的温度一起输出。我和我的教授谈过,她告诉我解决方案是一个嵌套的 while 循环,并且提示最终程序应该在一个单独的客户端类中。我还需要输出每个类别的总数。问题是,我在试图弄清楚如何使用我在客户端中创建的这个服务类来获取我需要的数据时遇到了很多麻烦。我的教授似乎无法以我能理解的方式解释它,所以我希望能得到一些帮助。