大学温度转换程序

时间:2019-02-20 21:31:22

标签: java function compilation

//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   TemperatureConverter不能应用于给定类型;

 convertTemp();
 ^
  

必填:String,String,double,double
  找到:没有参数
  原因:实际参数和正式参数列表的长度不同
  1个错误

     

---- jGRASP楔子2:进程的退出代码为1。
  ---- jGRASP:操作完成。

2 个答案:

答案 0 :(得分:2)

您的函数定义说它需要4个参数:

public static void convertTemp(
      String tempScale, 
      String Answer, 
      double temp,  
      double result)

但是当您调用它时,您传递了0个参数:

convertTemp();

答案 1 :(得分:0)

只需在public static void read() throws FileNotFoundException { // your method code } 内添加convertTemp()方法的参数即可。 :)