有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我应该使用哪个对象?

我不明白应该在Wind beaufort=new Wind(_______;)的标识符中放入哪个对象;。这里的第一行代码是构造函数,第二行代码是类

import java.util.Scanner;
public class WindSpeedCalc
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Wind speed in km/h: ");
        double kmH = scanner.nextDouble();
        
        
        Wind wind = new Wind(kmH);
        System.out.printf("The wind speed is equivalent to %.2f knots to two decimal places\n", wind.calculateKnots());
        Wind beaufort = new Wind(idkk);
        System.out.printf("The wind speed ranks around a %.1f on the Beaufort Scale\n", wind.calculateB());
        
        System.out.print(wind.analyzeWind());
    }
    
}

这是连接到上述构造函数的类。我不认为这个有什么问题

public class Wind
{
    double kmH;
    final double KM_IN_MI = 1.852;

    public Wind(double speedKmH)
    {
        kmH = speedKmH;
    }
    public double calculateKnots()
    {
        double knots = kmH / KM_IN_MI;
        return knots;
    }
    
    public int calculateB()
    {
         double mS = kmH / 3.6;
         double pow = 2.0 / 3.0;
         int b = (int)Math.round(Math.pow((mS / 0.836), pow));
         if(b > 12)
          b = 12;
         return b; 
    }
    
    public String analyzeWind()
    {
        String s = "";
        if(kmH < 2)
            s = "Wind is calm";
        else if (kmH > 120) 
            s = "European storm";
        else 
            s = "Moderate to strong wind";
        return s;
    }
}

共 (0) 个答案