Results 1 to 14 of 14

Thread: Calander

  1. #1
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Calander

    hello everyone i am looking for help to create a calender from this class i have created i want the user to enter the year and then they get full year calender only using this Date class i tried couple of if's and looping but i am not getting any useful results
    package date;

    import java.util.Scanner;

    public class Date {
    Scanner input=new Scanner(System.in);
    private int day, year;
    private Month month;

    public Date() {
    setDate(21, Month.October, 2013);
    }


    public Date(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }

    public void setDate(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }

    public void displayDate() {
    System.out.printf("%s %02d %s %4d \n",dow(), day, month, year);
    }


    public DayOfWeek dow (){
    int month = this.month.ordinal()+1;
    int result;
    if (month<=2)
    result= (year+31*(month-1)+day+(year-1)/4-3*((year+99)/100)/4)%7;
    else
    result= (year+31*(month-1)+day-(4*month+23)/10+year/4-(3*(year/100+1))/4)%7;
    return DayOfWeek.values()[result];
    }
    public static DayOfWeek dow(int day , Month month , int year)
    {
    Date temp = new Date ( day , month , year);
    return temp.dow();

    }
    public static boolean isLeap (int year)
    {
    return !dow(29,Month.Febraury, year) .equals( dow( 1 , Month.March,year));


    }

    public static int daysInMonth(Month month, int year)
    {
    switch (month)
    {
    case April: case June : case September : case Novomber : return 30;
    case Febraury : return isLeap(year)?29:28;
    default : return 31;
    }
    }

    public void inDate() {
    @SuppressWarnings("resource")
    Scanner input=new Scanner(System.in);
    System.out.println("Please enter a date in the format: dd mm yyyy");
    day=input.nextInt();
    month=Month.values()[input.nextInt()-1];
    year=input.nextInt();

    }


    public Scanner getInput() {
    return input;
    }


    public void setInput(Scanner input) {
    this.input = input;
    }


    public int getDay() {
    return day;
    }


    public void setDay(int day) {
    this.day = day;
    }


    public int getYear() {
    return year;
    }


    public void setYear(int year) {
    this.year = year;
    }


    public Month getMonth() {
    return month;
    }


    public void setMonth(Month month) {
    this.month = month;
    }



    }

  2. #2
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Unhappy Calender

    Help please i have created this class i want use it to create a calender only using this class anyone can help please:o:
    package date;

    import java.util.Scanner;

    public class Date {
    Scanner input=new Scanner(System.in);
    private int day, year;
    private Month month;

    public Date() {
    setDate(21, Month.October, 2013);
    }


    public Date(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }

    public void setDate(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }

    public void displayDate() {
    System.out.printf("%s %02d %s %4d \n",dow(), day, month, year);
    }


    public DayOfWeek dow (){
    int month = this.month.ordinal()+1;
    int result;
    if (month<=2)
    result= (year+31*(month-1)+day+(year-1)/4-3*((year+99)/100)/4)%7;
    else
    result= (year+31*(month-1)+day-(4*month+23)/10+year/4-(3*(year/100+1))/4)%7;
    return DayOfWeek.values()[result];
    }
    public static DayOfWeek dow(int day , Month month , int year)
    {
    Date temp = new Date ( day , month , year);
    return temp.dow();

    }
    public static boolean isLeap (int year)
    {
    return !dow(29,Month.Febraury, year) .equals( dow( 1 , Month.March,year));


    }

    public static int daysInMonth(Month month, int year)
    {
    switch (month)
    {
    case April: case June : case September : case Novomber : return 30;
    case Febraury : return isLeap(year)?29:28;
    default : return 31;
    }
    }

    public void inDate() {
    @SuppressWarnings("resource")
    Scanner input=new Scanner(System.in);
    System.out.println("Please enter a date in the format: dd mm yyyy");
    day=input.nextInt();
    month=Month.values()[input.nextInt()-1];
    year=input.nextInt();

    }


    public Scanner getInput() {
    return input;
    }


    public void setInput(Scanner input) {
    this.input = input;
    }


    public int getDay() {
    return day;
    }


    public void setDay(int day) {
    this.day = day;
    }


    public int getYear() {
    return year;
    }


    public void setYear(int year) {
    this.year = year;
    }


    public Month getMonth() {
    return month;
    }


    public void setMonth(Month month) {
    this.month = month;
    }



    }

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Calander

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Calander

    import java.util.Scanner;

    public class Date {
    Scanner input=new Scanner(System.in);
    private int day, year;
    private Month month;

    public Date() {
    setDate(21, Month.October, 2013);
    }


    public Date(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }

    public void setDate(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }

    public void displayDate() {
    System.out.printf("%s %02d %s %4d \n",dow(), day, month, year);
    }


    public DayOfWeek dow (){
    int month = this.month.ordinal()+1;
    int result;
    if (month<=2)
    result= (year+31*(month-1)+day+(year-1)/4-3*((year+99)/100)/4)%7;
    else
    result= (year+31*(month-1)+day-(4*month+23)/10+year/4-(3*(year/100+1))/4)%7;
    return DayOfWeek.values()[result];
    }
    public static DayOfWeek dow(int day , Month month , int year)
    {
    Date temp = new Date ( day , month , year);
    return temp.dow();

    }
    public static boolean isLeap (int year)
    {
    return !dow(29,Month.Febraury, year) .equals( dow( 1 , Month.March,year));


    }

    public static int daysInMonth(Month month, int year)
    {
    switch (month)
    {
    case April: case June : case September : case Novomber : return 30;
    case Febraury : return isLeap(year)?29:28;
    default : return 31;
    }
    }

    public void inDate() {
    @SuppressWarnings("resource")
    Scanner input=new Scanner(System.in);
    System.out.println("Please enter a date in the format: dd mm yyyy");
    day=input.nextInt();
    month=Month.values()[input.nextInt()-1];
    year=input.nextInt();

    }


    public Scanner getInput() {
    return input;
    }


    public void setInput(Scanner input) {
    this.input = input;
    }


    public int getDay() {
    return day;
    }


    public void setDay(int day) {
    this.day = day;
    }


    public int getYear() {
    return year;
    }


    public void setYear(int year) {
    this.year = year;
    }


    public Month getMonth() {
    return month;
    }


    public void setMonth(Month month) {
    this.month = month;
    }



    }[/QUOTE]

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Calander

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Angry Calender

    hello everyone i am looking for help to create a calender from this class i have created i want the user to enter the year and then they get full year calender only using this Date class i tried couple of if's and looping but i am not getting any useful results
    Java Code:
    import java.util.Scanner;
    
    public class Date {
    Scanner input=new Scanner(System.in);
    private int day, year;
    private Month month;
    
    public Date() {
    setDate(21, Month.October, 2013);
    }
    
    
    public Date(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }
    
    public void setDate(int day, Month month, int year) {
    this.day = day;
    this.month = month;
    this.year = year;
    }
    
    public void displayDate() {
    System.out.printf("%s %02d %s %4d \n",dow(), day, month, year);
    }
    
    
    public DayOfWeek dow (){
    int month = this.month.ordinal()+1;
    int result;
    if (month<=2)
    result= (year+31*(month-1)+day+(year-1)/4-3*((year+99)/100)/4)%7;
    else
    result= (year+31*(month-1)+day-(4*month+23)/10+year/4-(3*(year/100+1))/4)%7;
    return DayOfWeek.values()[result];
    }
    public static DayOfWeek dow(int day , Month month , int year)
    {
    Date temp = new Date ( day , month , year);
    return temp.dow();
    
    }
    public static boolean isLeap (int year)
    {
    return !dow(29,Month.Febraury, year) .equals( dow( 1 , Month.March,year));
    
    
    }
    
    public static int daysInMonth(Month month, int year)
    {
    switch (month)
    {
    case April: case June : case September : case Novomber : return 30;
    case Febraury : return isLeap(year)?29:28;
    default : return 31;
    }
    }
    
    public void inDate() {
    @SuppressWarnings("resource")
    Scanner input=new Scanner(System.in);
    System.out.println("Please enter a date in the format: dd mm yyyy");
    day=input.nextInt();
    month=Month.values()[input.nextInt()-1];
    year=input.nextInt();
    
    }
    
    
    public Scanner getInput() {
    return input;
    }
    
    
    public void setInput(Scanner input) {
    this.input = input;
    }
    
    
    public int getDay() {
    return day;
    }
    
    
    public void setDay(int day) {
    this.day = day;
    }
    
    
    public int getYear() {
    return year;
    }
    
    
    public void setYear(int year) {
    this.year = year;
    }
    
    
    public Month getMonth() {
    return month;
    }
    
    
    public void setMonth(Month month) {
    this.month = month;
    }
    
    
    
    }
    Attached Thumbnails Attached Thumbnails Calander-presentation1.jpg  

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Calander

    i am not getting any useful results
    Please explain. Copy and paste here the program's output and add some comments saying what is wrong with it and show what you want it to be.



    BTW The posted code has lost all its formatting. Nested statements should be indented.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Calander

    i am new to this forum sorry the output should be smth like the attached image i want know how to create this calendar from the code Date class

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Calander

    What happens when you compile the code? If there are compiler errors, copy the full text and paste it here.
    If there are no compiler errors and the program can be executed, copy the full contents of the command prompt window from when you execute the program and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Calander

    i don't know how to do the code -_-
    i tried smth like that
    Java Code:
    package date;
    
    import java.util.Scanner;
    public class CalendarProgram {
    
    	
    	public static void main (String args[]){
    	
    		int year = 0;
    		Date date = new Date();
    		Scanner scanner = new Scanner ( System.in);
    		System.out.println("Welcome to the Calander Application");
    		System.out.println("Please enter the year for which you want the Calander");
    		year = scanner.nextInt();
    		
    	
    	
    	        for (int weeks = 1; weeks < 7; weeks++)
    	        {
    	     	        for (int day = 0; day < 7; day++)
    	            {
    	         
    	                int firstDayofMonth = 1;
    					if (weeks == 1 && day < firstDayofMonth - 1)
    	                {
    	                   date.dow();
    	                }
    	                else
    	                {
    	                 
    	                  int calPrinter = 0;
    						if (calPrinter <= date.daysInMonth(null,0))
    	                    {
    	             
    	                   calPrinter++;
    	                    }
    	                }
    	       
    	         
    	            }
    	         
    	        }
    	}
    }

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Calander

    What happens with that code?
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    gucci88 is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Calander

    no output + errors due to the function daysInMonth it doesn't worrk

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Calander

    Copy the full text of the error messages and paste them here.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

Similar Threads

  1. Create Calander
    By cheecoo in forum Java Applets
    Replies: 5
    Last Post: 06-12-2008, 03:50 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
  •