//Name: Eric Stum
//Date: 2/20/2019
//desciption: Homework 4
import java.util.Scanner;
import java.lang.reflect.Method;
public class TemperatureConverter{
public static void convertTemp(String tempScale, String Answer, double temp, double result){
if(tempScale.equals("f") && Answer.equals("yes"))
{
double scale1 = (0.5555555555555556);//had troubles with the faction for some reason :/
result = scale1 * (temp - 32);
System.out.println(temp + " is equal to " + result + " degrees celsius. ");
}
else if(tempScale.equals("c") && Answer.equals("yes")){
result = (temp * 1.8) + 32.0;
System.out.println(temp + " is equal to " + result + " degrees farenheight. ");
}
else{
System.out.println("invalid entry");
}
}
//main method
public static void main(String args[]){
double result;
double temp;
String tempScale;
System.out.println("Hello. This Program will convert Farenheight to Celcius or vise-versa.");
Scanner keyboard1 = new Scanner(System.in);
Scanner keyboard2 = new Scanner(System.in);
System.out.println("To get started please enter a temperature");
temp = keyboard2.nextDouble();
System.out.println("Did you submit Farenheight or Celsius?");
System.out.println("Type f for farenheight or c for celsius: ");
tempScale = keyboard1.nextLine();
if (tempScale.equals("f") || tempScale.equals("F")){
System.out.println("you entered in " + temp + " degrees farenheight.");
}
else if (tempScale.equals("c") || tempScale.equals("C")){
System.out.println("you entered in " + temp + " degrees celsius.");
}
else{
System.out.println("invalid entry");
}
System.out.println("would you like to convert it?");
Scanner keyboard3 = new Scanner(System.in);
String Answer = keyboard3.nextLine();
convertTemp();
}
}所以我是一所大学的学生,我正在努力找出这个家庭作业,但还没有找到答案。我一直收到有关方法调用的错误,不管我尝试了什么,谁能帮我弄清楚如何成功地将该方法调用到主方法中。真的需要帮忙吗?
但是我不断地发现这个错误:
TemperatureConverter.java:62:错误: convertTemp类中的方法convertTemp不能应用于给定的类型;
convertTemp();
^所需:字符串、字符串、双、双 裁定:无争议 原因:实际的和正式的论点列表的长度不同。 1错误--jGRASP wedge2:进程的退出代码为1。 -jGRASP:行动完成。
发布于 2019-02-20 21:40:52
您的函数定义表示它需要4个参数:
public static void convertTemp(
String tempScale,
String Answer,
double temp,
double result)但是,当您调用它时,需要传递0个参数:
convertTemp();发布于 2019-02-20 23:37:52
只需将convertTemp()方法的参数添加到main中即可。:)
https://stackoverflow.com/questions/54795547
复制相似问题