变量可能是Netbeans的最终意义

  • 本文关键字:Netbeans 变量 java netbeans
  • 更新时间 :
  • 英文 :


我一直在尝试创建一个代码,该代码将在用户输入特定数据时计算Windchill。我是Java的新手,并且在这个项目上遇到了很多困难。但是,我终于让它成功地运行。即使现在正在运行,我仍会收到消息,说我的变量可以最终确定。我不确定这是什么意思,不能让它消失。我在评论中标记了在他们身上有消息的人。有人可以解释一下这意味着什么以及为什么会发生?

这是我的代码:

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        String line;
        String date;
        int windSpeed, temperature;
        Scanner kb = new Scanner(System.in);
        System.out.println("Enter the observation date: ");
        date = kb.nextLine();
        System.out.println ("Enter the wind speed in MPH: ");        
        line = kb.nextLine();
        windSpeed = Integer.parseInt(line);
        System.out.println ("Enter the temperature in degrees F: ");
        line = kb.nextLine();
        temperature = Integer.parseInt(line);
        Observation observation1 = new Observation(date,windSpeed,temperature);
        System.out.println("Observation Date: " + observation1.getDate());
        System.out.println("WindChill: " + observation1.getwindChill());
    }    
}

我在同一软件包中的其他课程:

public class Observation {
    private String date; //can be final
    private int windSpeed;//can be final
    private int temperature;//can be final
    private double windChill;//can be final      
    public Observation (String d, int s, int t){
        date = d;
        windSpeed = s;
        temperature = t;
        windChill = 35.74 + 0.6215*t + (0.4275*t - 35.75) * Math.pow(s,0.16);
    }
    public String getDate (){
        return date;
    }
    public double getwindChill(){
        return windChill;
    }
}

Java中的最终变量是cost剂,这意味着一旦设置了它们的值,它就永远不会改变。NetBeans建议您在变量声明中将final修饰符放在以下情况下:

  • 您在创建后立即分配一个值
  • 您在构造函数中初始化它们

,您永远不会更改其价值。

最新更新