首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >高校温度转换程序

高校温度转换程序
EN

Stack Overflow用户
提问于 2019-02-20 21:31:22
回答 2查看 111关注 0票数 0
代码语言:javascript
复制
//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不能应用于给定的类型;

代码语言:javascript
复制
 convertTemp();
 ^

所需:字符串、字符串、双、双 裁定:无争议 原因:实际的和正式的论点列表的长度不同。 1错误--jGRASP wedge2:进程的退出代码为1。 -jGRASP:行动完成。

EN

回答 2

Stack Overflow用户

发布于 2019-02-20 21:40:52

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

代码语言:javascript
复制
public static void convertTemp(
      String tempScale, 
      String Answer, 
      double temp,  
      double result)

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

代码语言:javascript
复制
convertTemp();
票数 2
EN

Stack Overflow用户

发布于 2019-02-20 23:37:52

只需将convertTemp()方法的参数添加到main中即可。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54795547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档