Results 1 to 4 of 4
- 01-13-2011, 03:23 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 93
- Rep Power
- 0
why does this program not execute
The program below does not run. I don't underdstand why.:(
Date.java
TimeTeller.javaJava Code:import java.util.Calendar; public class Date { Calendar time = Calendar.getInstance(); private int i_day; private String day; private int date; private int i_month; private String month; private int year; public Date() { i_day = time.get(Calendar.DAY_OF_WEEK); day = getDay(i_day); i_month = time.get(Calendar.MONTH); month = getMonth(i_month); date = time.get(Calendar.DATE); year = time.get(Calendar.YEAR); } private String getDay(int day) { switch(day) { case 1: {return "Monday";} case 2: {return "Tuesday";} case 3: {return "Wednesday"; } case 4: {return "Thursday"; } case 5: {return "Friday"; } case 6: {return "Saturday"; } case 7: {return "Sunday"; } default: {return "NoDay";} } } public String getMonth(int month) { switch(month) { case 1: return "January"; case 2: return "February"; case 3: return "March"; case 4: return "April"; case 5: return "May"; case 6: return "June"; case 7: return "July"; case 8: return "August"; case 9: return "September"; case 10: return "October"; case 11: return "November"; case 12: return "December"; default: return "NoMonth"; } } public String printDate() { return (day+" "+date+" "+"month"+" "+ year); } }
Java Code:public class TimeTeller { public static void main(String[] args) { Date today = new Date(); today.printDate(); } }
- 01-13-2011, 03:27 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Define "does not run". Does it compile? Are there exceptions? Do you expect it to print something out? Add some println statements to make sure it enters and runs the appropriate methods.
- 01-13-2011, 03:29 PM #3
Senior Member
- Join Date
- Dec 2010
- Posts
- 100
- Rep Power
- 0
Hi - in your main method, you are creating a new Data object. And then, you invoke the printDate() method on it. The printDate() method only returns a string, it does not print it. So in your main method, try:
Best,Java Code:System.out.println(today.printDate());
--user0--
- 01-13-2011, 03:32 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 93
- Rep Power
- 0
Similar Threads
-
is there a way to tell how to execute a java program in the jar
By aaroncarpet in forum Advanced JavaReplies: 9Last Post: 11-19-2009, 04:31 PM -
Execute the commands in Jsp Program
By swetha_2008 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-17-2008, 06:04 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM -
Execute a new program in java
By mathias in forum Advanced JavaReplies: 1Last Post: 07-31-2007, 05:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks