Results 1 to 2 of 2
Thread: Displaying errors
- 10-20-2012, 02:42 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Displaying errors
hello i'm trying to make a calender as a practice so far it's working fine but the output is not what i wanted it to be here's the java code and the output in the screen:
attachment manager doesn't seem to work here's a link :Java Code://this is a calender displayer import java.util.Scanner; public class calendertest1 { public static void main(String[] args){ Scanner input = new Scanner(System.in); int year=0, month; //input of the year while(year<=1800){ System.out.print("type year : "); year = input.nextInt(); } //input of the month System.out.print("type month number in here(1, 12)"); month=input.nextInt(); //displaying the month's array bodyArray(month, year); } //getting the month's name according to it's number public static String getMonthName(int month){ String monthName=""; switch (month){ case 1: monthName="January"; break; case 2: monthName="February"; break; case 3: monthName="March"; break; case 4: monthName="April"; break; case 5: monthName="May"; break; case 6: monthName="June"; break; case 7: monthName="July"; break; case 8: monthName="August"; break; case 9: monthName="September"; break; case 10: monthName="October"; break; case 11: monthName="November"; break; case 12: monthName="December"; } return monthName; } //number of days per months public static int getNumbersOfdays(int year, int month){ // getting 31 days in here if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) return 31; //getting 30 days in here if(month==4 || month==6 || month==9 || month==11) return 30; //in here for february if it's a leap it get 29 otherwise 28 if(month==2 ) return isLeap(year)?29 : 28; return 0; } //boolean method for leap year check public static boolean isLeap(int year){ return (year%4==0 && year%100 !=0)|| year%400==0; } //getting total of days since 1st january 1800 public static int totalNumbersOfDays(int year, int month){ int total=0; for(int i=1800; i<year; i++){ if(isLeap(i)){ total+=366; } else{ total+=365; } } return total; } //getting the fst day's number of the month public static int fstDay(int year, int month){ final int dayOne=3; int totalDays=totalNumbersOfDays(year, month); return (totalDays+dayOne%7); } //displaying the table in here public static void bodyArray(int month, int year){ int numberOfDays=getNumbersOfdays(year, month); int day1=fstDay(year, month); System.out.printf("\t\t\t\t\t\t%s %4d\n", getMonthName(month), year); System.out.println("---------------------------------------------------------------------------------------------------------------"); System.out.printf(" %10s%10s%10s%10s%10s%10s%10s","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); int k; for(k=0;k<day1;k++) System.out.print(" "); //in here i tried System.out.printf("%10s", " "); but i get displaying errors for(k=1; k<=numberOfDays; k++){ System.out.printf("%10d", k); if((k+day1)%7==0) System.out.println(); } System.out.println(); } }
ImageShack® - Online Photo and Video Hosting
if there's something not clear in comments or code i'll explain itLast edited by Arbalest; 10-20-2012 at 08:10 PM.
- 10-20-2012, 07:58 PM #2
Member
- Join Date
- Sep 2012
- Posts
- 11
- Rep Power
- 0
Re: Displaying errors
p.s:i've canceled the java tag so the code becomes visible .
main problem is that it should select a day of the week for example a Thursday which mean days before should be a blank and it goes on, but the output just ignore them all like this if it's a a Thursday it will start from Monday and the date would be starting from 4th and and so on, if someone could help me with this and thxLast edited by Arbalest; 10-20-2012 at 08:14 PM.
Similar Threads
-
Storing previous errors and displaying
By shivam0101 in forum Advanced JavaReplies: 21Last Post: 03-13-2012, 04:58 PM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
Getting errors
By Abbinormal in forum New To JavaReplies: 5Last Post: 01-15-2010, 06:01 AM -
Errors?
By Jamison5213 in forum New To JavaReplies: 4Last Post: 12-30-2009, 12:14 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks