• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Help Needed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I'm having problems trying to display the numbers which should form part of a Calender layout, i.e, like the windows Calender. Now I have the surrounding code set up, but I am having trouble trying to get the code that will actually display the numbers when the program is run. I'm pretty poor at Java so its is most likely a simple problem. Thanks In advance
My program so far(Date Class):
import textio.ConsoleIO;
public class Date
{
public static voidmain(String[] args)

{
int day = -1;
int month = -1;
int year = -1;

{
ConsoleIO.out.print("Enter day number: ");
day = ConsoleIO.in.readInt();

if (day < 0)
ConsoleIO.out.println("Invalid day");
else if (day == 0)
printDay(0);
else if (day == 1)
printDay(1);
else if (day == 2)
printDay(2);
else if (day == 3)
printDay(3);
else if (day == 4)
printDay(4);
else if (day == 5)
printDay(5);
else if (day == 6)
printDay(6);
else if (day > 6)
ConsoleIO.out.println("Invalid day");
}

{
ConsoleIO.out.print("Enter month number: ");
month = ConsoleIO.in.readInt();

if (month < 1)
ConsoleIO.out.println("Invalid month");
else if (month == 1)
printMonth(1);
else if (month == 2)
printMonth(2);
else if (month == 3)
printMonth(3);
else if (month == 4)
printMonth(4);
else if (month == 5)
printMonth(5);
else if (month == 6)
printMonth(6);
else if (month == 7)
printMonth(7);
else if (month == 8)
printMonth(8);
else if (month == 9)
printMonth(9);
else if (month == 10)
printMonth(10);
else if (month == 11)
printMonth(11);
else if (month == 12)
printMonth(12);
else if (month >12)
ConsoleIO.out.println("Invalid month");
}

ConsoleIO.out.print("Enter year number: ");
year = ConsoleIO.in.readInt();
ConsoleIO.out.println(year);

}

public static voidprintDay(int day)
{
if (day == 0)
ConsoleIO.out.print("Sunday");
if (day == 1)
ConsoleIO.out.print("Monday");
if (day == 2)
ConsoleIO.out.print("Tuesday");
if (day == 3)
ConsoleIO.out.print("Wednesday");
if (day == 4)
ConsoleIO.out.print("Thursday");
if (day == 5)
ConsoleIO.out.print("Friday");
if (day == 6)
ConsoleIO.out.print("Saturday");
}

public static void printMonth(int month)
{
if (month == 1)
ConsoleIO.out.print("January");
if (month == 2)
ConsoleIO.out.print("February");
if (month == 3)
ConsoleIO.out.print("March");
if (month == 4)
ConsoleIO.out.print("April");
if (month == 5)
ConsoleIO.out.print("May");
if (month == 6)
ConsoleIO.out.print("June");
if (month == 7)
ConsoleIO.out.print("July");
if (month == 8)
ConsoleIO.out.print("August");
if (month == 9)
ConsoleIO.out.print("September");
if (month == 10)
ConsoleIO.out.print("October");
if (month == 11)
ConsoleIO.out.print("November");
if (month == 12)
ConsoleIO.out.print("December");
}

public static voidprintDate(int day,int month,int year)

{

int zeller=Calendar.dateToZeller(day,month,year);

printDay(zeller);
ConsoleIO.out.print(","+day+",");
printMonth(month);
ConsoleIO.out.print(","+year);
}

public static int dates(int day1,int month1,int year1,int day2,int month2,int year2)

{
int date1=Calendar.dateToJulian(day1,month1,year1);
int date2=Calendar.dateToJulian(day2,month2,year2);

return date2-date1;
}

public void setDate(int day,int month,int year)
{
days.setValue(day);
months.setValue(month);
years.setValue(year);
}
}

Calender Class

public class Calendar {
public static int dateToZeller(int day, int month, int year){
int dd = day;
int mm = month;
int yy = year;
if(month < 3) {
mm = month + 10;
yy = year - 1;
}else
mm = month - 2;
int yr = yy % 100;
int cent = yy / 100;
return ((700 + (26 * mm - 2) / 10 + dd + yr + (yr / 4) + (cent / 4) - 2 * cent) % 7);
}
public static int dateToJulian(int day, int month, int year) {
int mm = month;
int yy = year;
if(month > 2)
mm = mm - 3;
else {
mm = mm + 9;
yy--;
}
int cent = yy / 100;
int yr = yy % 100;
return ((146097 * cent) >> 2) + ((1461 * yr) >> 2) + (153 * mm + 2) / 5 + day + 1721119;
}
}
Class Main4
import textio.ConsoleIO;
public class Main4
{
public static void main(String[]args)
{
int day=1;
ConsoleIO.out.print("Please Enter a Month: ");
int month=ConsoleIO.in.readInt();
ConsoleIO.out.print("Please Enter a Year: ");
int year=ConsoleIO.in.readInt();
Date.printCalendar(day,month,year);
Date.daysInMonth(day,month,year);
}
}
Quick Expalnation of what each class is doing:
Date Class --> Contains all the code to run the calender. This is where the code to display the number will go
Calender Class --> The calendar class contains two static methods:
(a)dateToZeller which converts a Georgian date into an encoding for the day of the
week, where 0 represents Sunday, 1 is Monday,..., and 6 is Saturday;
and the method
(b) dateToJulian which converts a date into a julian number representing the number
of days that have elapsed since some distant epoch.
[ May 06, 2004: Message edited by: Michael Monan ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Michael Monan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I'm having problems with Main4, which isn't working because of the changes

import textio.ConsoleIO;
public class Main4
{
public static voidmain(String[]args)

{

int day=1;
ConsoleIO.out.print("Please Enter a Month: ");
int month=ConsoleIO.in.readInt();

ConsoleIO.out.print("Please Enter a Year: ");
int year=ConsoleIO.in.readInt();

Date.printCalendar(day,month,year);
Date.daysInMonth(day,month,year);

}
}
I think it is something to do with the way the (int,int,int) is set out?
 
Michael Monan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks mate, I've done it differently and it is now working fine
 
I found a beautiful pie. And a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic