标题:[求助]'class' or 'interface' expected
取消只看楼主
kingyor
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-6-4
 问题点数:0 回复次数:3 
[求助]'class' or 'interface' expected
D:\java\dates\jspcalendar.java:1: 'class' or 'interface' expected
packege dates;
^
D:\java\dates\jspcalendar.java:2: 'class' or 'interface' expected
import java.text.DateFormat;
^
D:\java\dates\jspcalendar.java:3: 'class' or 'interface' expected
import java.util.*;
^
3 errors



//下面的源程序
packege dates;
import java.text.DateFormat;
import java.util.*;
public class jspcalendar{
Calendar calendar = null;
public jspcalendar(){
calendar = Calendar.getInstance();
Date trialTime = new Date();
canlendar.setTime(trialTime);
}
//duqu year
public int getYear(){
return calendar.get(Calendar.YEAR);
}
//duqu month
public String getMonth(){
int m = getMonthInt();
String[] months = new String[]{"January","February","march",
"April","May","June","July","August","September",
"October","November","december"};
if (m>12)
return "Unknown to man";
return months[m-1];
}
//du weekday
public String getDay(){
int x = getDayOfWeek();
String[] days=new String[] {"Sunday","Monday","Tuesday","wednesday","Thursday",
"Friday","Saturday"};
if (x>7)
return "Unkown to man";
return days[x-1];
}
//duqu mnoth/day/year
public String getDate(){
return getMonthInt() + ":" + getDayOfWeek() + "/" +getYear();
}
//duqu huor/minute/second
public String getTime(){
return getHour() + ":" = getMinute() + ":" + getSecond();
}
public int getDayOfMonth(){
return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear(){
return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear(){
return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth(){
return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek(){
return calendar.get(Calendar.DAY_OF_WEEK);
}
public int getHour(){
return calendar.get(Calendar.HOUR_OF_DAY);
}
public int getMinute(){
return calendar.get(Calendar.MINUTE);
}
public int getSecond(){
return calendar.get(Calendar.SECOND);
}
public static void main(String args[]){
jspcalendar db = new jsapcalendar();
p("date:"+db.getDayOfMonth());
p("year:"+db.getYear());
p("month:"+db.getMonth());
p("time:"+db.getTime());
p("date:"+db.getDate());
p("Day:"+db.getDay());
p("Dayofyear:"+db.getDayOfYear());
p("Weekofyear:"+db.getWeekOfYear());
p("era:"+db.getEra());
p("ampm:"+db.getAMPM());
p("Dst:"+db.getDSTOffset());
p("Zone offset:"+db.getZoneOffset());
p("timezone:"+db.getUSTimeZone());
}
public static void p(String x){
System.out.println(x);
}
public int getEra(){
return calendar.get(Calendar.ERA);
}
public String getUSTimeZone(){
String zones = new String[]{"hawaii","Alaskan","pacific","Mountain","Central","Eastern"};
return zones[10+getZoneOffset()];
}
public int getZoneOffset(){
return calendar.get(Calendar.ZONE_OFFSET)/(60*60*10000);
}
public int getDSTOffset(){
return calendar.get(Calendar.DST_OFFSET)/(60*60*10000);
}
public int getAMPM(){
return calendar.get(Calendar.AM_PM);
}
}
搜索更多相关主题的帖子: interface expected class 
2006-12-11 15:38
kingyor
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-6-4
得分:0 

汗~~谢谢各位提醒,不过该了之后编译还是有好多错误,最后还剩下两个不知道怎么解决,请各位指点一下~~~汗~~~

主要的那个int m = getMonthInt();

//编译时报错信息
D:\java\dates\jspcalendar.java:17: cannot resolve symbol
symbol : method getMonthInt ()
location: class dates.jspcalendar
int m = getMonthInt();
^
D:\java\dates\jspcalendar.java:36: cannot resolve symbol
symbol : method getMonthInt ()
location: class dates.jspcalendar
return getMonthInt() + ":" + getDayOfWeek() + "/" +getYear();
^
2 errors

//改后程序
package dates;
import java.text.DateFormat;
import java.util.*;
public class jspcalendar{
Calendar calendar = null;
public jspcalendar(){
calendar = Calendar.getInstance();
Date trialTime = new Date();
calendar.setTime(trialTime);
}
//duqu year
public int getYear(){
return calendar.get(Calendar.YEAR);
}
//duqu month
public String getMonth(){
int m = getMonthInt();
String[] months = new String[]{"January","February","march",
"April","May","June","July","August","September",
"October","November","december"};
if (m>12)
return "Unknown to man";
return months[m-1];
}
//du weekday
public String getDay(){
int x = getDayOfWeek();
String[] days=new String[] {"Sunday","Monday","Tuesday","wednesday","Thursday",
"Friday","Saturday"};
if (x>7)
return "Unkown to man";
return days[x-1];
}
//duqu mnoth/day/year
public String getDate(){
return getMonthInt() + ":" + getDayOfWeek() + "/" +getYear();
}
//duqu huor/minute/second
public String getTime(){
return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth(){
return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear(){
return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear(){
return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth(){
return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek(){
return calendar.get(Calendar.DAY_OF_WEEK);
}
public int getHour(){
return calendar.get(Calendar.HOUR_OF_DAY);
}
public int getMinute(){
return calendar.get(Calendar.MINUTE);
}
public int getSecond(){
return calendar.get(Calendar.SECOND);
}
public static void main(String args[]){
jspcalendar db = new jspcalendar();
p("date:"+db.getDayOfMonth());
p("year:"+db.getYear());
p("month:"+db.getMonth());
p("time:"+db.getTime());
p("date:"+db.getDate());
p("Day:"+db.getDay());
p("Dayofyear:"+db.getDayOfYear());
p("Weekofyear:"+db.getWeekOfYear());
p("era:"+db.getEra());
p("ampm:"+db.getAMPM());
p("Dst:"+db.getDSTOffset());
p("Zone offset:"+db.getZoneOffset());
p("timezone:"+db.getUSTimeZone());
}
public static void p(String x){
System.out.println(x);
}
public int getEra(){
return calendar.get(Calendar.ERA);
}
public String getUSTimeZone(){
String[] zones = new String[] {"hawaii","Alaskan","pacific","Mountain","Central","Eastern"};
return zones[10+getZoneOffset()];
}
public int getZoneOffset(){
return calendar.get(Calendar.ZONE_OFFSET)/(60*60*10000);
}
public int getDSTOffset(){
return calendar.get(Calendar.DST_OFFSET)/(60*60*10000);
}
public int getAMPM(){
return calendar.get(Calendar.AM_PM);
}
}


宝哥啊宝哥~~命苦啊命苦啊~~~
2006-12-12 21:06
kingyor
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-6-4
得分:0 

呢我是想把那个整形给m,让getmonth()返回months[m-1]的值.


宝哥啊宝哥~~命苦啊命苦啊~~~
2006-12-15 09:05
kingyor
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-6-4
得分:0 
是啊!不过我一直在努力,因为没有人教我,找不到人问问题,所以在这里发帖了。路漫漫其修远兮,吾将上下而求所,呵呵~~~~怎么说我都不要紧,只要能解决问题,骂我蠢都没关系。
我试着定义了一下那个getMonthInt():
public int getMonthInt(){
return calendar.get(Calendar.MONTH);
}

呵呵~~居然OK了!happy!

宝哥啊宝哥~~命苦啊命苦啊~~~
2006-12-17 19:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-108806-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.161170 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved