微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

运算符 < 未定义参数类型 String, int ?在 Java 中

如何解决运算符 < 未定义参数类型 String, int ?在 Java 中

我试图在服装方法中设置一个条件,如果温度

定义参数类型 String,int 的运算符

那么如何在下面的服装方法中使用大于 > 且小于 < 的这个?

import java.util.Random;

import net.aksingh.owmjapis.api.APIException;
import net.aksingh.owmjapis.core.OWM;
import net.aksingh.owmjapis.model.CurrentWeather;

public class Weather {
    
    Weather Tweather = new Weather();
    // method to test the API key
    public static String owmKey() {
        return "api-key"; // api key
    }

    static CurrentWeather cwd;

    String[] highTemp = { "Shirt","T-shirt","Jacket","Raincoat" };
    String[] midTemp = { "sweater","thermal-shirt" };
    String[] lowTemp = { "Trousers","Jeans","Shorts" };

    public static Boolean getCity(String city) {
        /*
         * Description: This method returns the name of the city.
         * 
         * @param city: value of to be validated.
         *
         * @return : return the back the name of the city if valid.
         */

        // declaring object of "OWM" class
        OWM owm = new OWM(owmKey());

        // getting current weather data for the selected city

        try {
            cwd = owm.currentWeatherByCityName(city);
            if (cwd.hasCityId()) {
                // we then return the city name
                return true;

            }

        } catch (APIException e) {
            // returns if city doesn't exist on the OWM API
            return false;
        }
        return null; // else return null
    }

    public String temp() {
        return "The temperature of are: Max-" + (cwd.getMainData().getTempMax() - 273.15) + " / Min - "
                + (cwd.getMainData().getTempMin() - 273.15) + "\'Celsius";
    }

    public String clothing() {
        Random clothings = new Random();
        int high = clothings.nextInt(highTemp.length - 1);
        int mid = clothings.nextInt(midTemp.length - 1);
        int low = clothings.nextInt(lowTemp.length - 1);
        
        if( Tweather.temp() < 10 ) {
            return "Adviesd Clothings By CTZ: " + highTemp[high]; 
        }

        return "Adviesd Clothings By CTZ: " + highTemp[high] + " and " + midTemp[mid] + " and " + lowTemp[low];
        // return "Adviesd Clothings By CTZ: "+ highTemp[high] +" and " + midTemp[mid] +
        // " and " + lowTemp[low];
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。