java - 大学温度转换程序

标签 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: error: method convertTemp in class TemperatureConverter cannot be applied to given types;

 convertTemp();
 ^

required: String,String,double,double
found: no arguments
reason: actual and formal argument lists differ in length
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

最佳答案

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

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

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

convertTemp();

关于java - 大学温度转换程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54795547/

相关文章:

javascript - JavaScript 新手 : Can I pass a List into this function and have it still work?

python - 延迟读取默认参数,直到调用函数为止

css - 为什么 scss 重复功能不起作用?

maven - Gradle自定义编译

c - 使用信号量编译但未运行的生产者-消费者代码

java - 在随机访问文件中寻求实现

java.lang.RuntimeException : Unable to start activity android. content.res.Resources$NotFoundException: 资源 ID #0x7f110002

java - GetChangeGui 手册 JFrame

java - 带有 war 文件的 Spring 应用程序属性配置文件

c - 使用全局结构变量时出现段错误