forecast.java

来自「《J2ME实用教程》清华大学出版社出版」· Java 代码 · 共 37 行

JAVA
37
字号
package com.j2medev.chapter4;
//Forecast代表了天气预报信息
public class Forecast {
    
     public static final int DAY = 0;
     public static final int DATE = 1;
     public static final int LOW = 2;
     public static final int HIGH = 3;
     public static final int TEXT = 4;
     public static final int CODE = 5;
     private Unit unit = null;
     private String[] forcast = new String[6];

    public Forecast() {
    }
    public void setUnit(Unit u){
        this.unit = u;
    }
    public String get(int field){
        if(field < 0 || field > 6)
            throw new IllegalArgumentException("the att is not defined");
        return forcast[field];
    }
    
    public void set(int index,String value){
        forcast[index]=value;
    }
    
    public String toString(){
        return "day : "+forcast[0]+"\n"
                +"date : "+forcast[1]+"\n"
                +"low : "+forcast[2]+unit.get(Unit.TEMPERATRUE)+"\n"
                +"high : "+forcast[3]+unit.get(Unit.TEMPERATRUE)+"\n"
                +"text : "+forcast[4]+"\n";     
    }
}

⌨️ 快捷键说明

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