//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();
Рад помочь. Не стесняйтесь отметить мой ответ как правильный. :)
Просто добавьте параметры для вашего метода convertTemp() внутри вашего main. :)
спасибо, очень помогло, исправил и теперь работает без сбоев.