location.java

来自「JAVAME Core technology and best practice」· Java 代码 · 共 30 行

JAVA
30
字号
package com.j2medev.chapter4.weather;

public class Location {
  
    private String[] location = new String[3];
    public static final int CITY = 0;
    public static final int REGION = 1;
    public static final int COUNTRY = 2;

    public Location() {
    }
    
    public String get(int field){
          if(field < 0 || field > 2)
            throw new IllegalArgumentException("The unit field is not defined");
          return location[field];
    }
    
    public void set(int index,String value){
        location[index] = value;
    }
    
    public String toString(){
        return "city : "+location[0]+"\n"
                +"region : "+location[1]+"\n"
                +"country : "+location[2]+"\n";
    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?