Results 1 to 2 of 2
  1. #1
    Arbalest is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default 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:
    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();
        }
                
            
        }
    attachment manager doesn't seem to work here's a link :
    ImageShack® - Online Photo and Video Hosting
    if there's something not clear in comments or code i'll explain it
    Last edited by Arbalest; 10-20-2012 at 09:10 PM.

  2. #2
    Arbalest is offline Member
    Join Date
    Sep 2012
    Posts
    11
    Rep Power
    0

    Default 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 thx
    Last edited by Arbalest; 10-20-2012 at 09:14 PM.

Similar Threads

  1. Storing previous errors and displaying
    By shivam0101 in forum Advanced Java
    Replies: 21
    Last Post: 03-13-2012, 05:58 PM
  2. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  3. Getting errors
    By Abbinormal in forum New To Java
    Replies: 5
    Last Post: 01-15-2010, 07:01 AM
  4. Errors?
    By Jamison5213 in forum New To Java
    Replies: 4
    Last Post: 12-30-2009, 01:14 AM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •