The Java code:

// Molad.java program

// This program calculate the Molad and determines when Rosh Hashana

// will be selabrated acording to Halacha Rules.

// first year's molad is given: 20:28:00 at Teusday.

// the program adds for every year 354 days+ 8:48:40. If this year is a

// leap year the program will add another lunar month: 29 days+ 12:44:3.33

// writen by Naftali Feldman for Programming Languages class. Fall 97.

import java.awt.*;

import java.applet.Applet;

public class Molad extends Applet

{

int day; // the day of the week when the Molad accures */

int h,m,s; // the exact time of the molad (hour,min,sec)

int year_num;

int rh_day; // the determined day when Rosh Hashana

int flag; // will be selabrated

int l_count; // a counter for leap years

int loc; // the line location of g.drawString

int y,add_to_s;

public void init()

{

flag=0;

l_count=0;

day=3;

h=20;

m=28;

s=0;

loc=1;

}

public void paint ( Graphics g )

{

for (year_num=1;year_num<44;++year_num)

{

loc=loc+15;

g.drawString("year: "+year_num+", the molad is on "+day+" day of the week, at time "+h+":"+m+":"+s,20,loc);

rh_day=day;

if (flag==1){

rh_day=3;

flag=0;

} else {

if (h>11) {

rh_day++; // add day

if (rh_day==8) rh_day=1;

}

if (rh_day==1 || rh_day==4 || rh_day==6) {

rh_day++;

if (rh_day==8) rh_day=1; // add day

}

// regular check init:

y=year_num;

while (y>19) y=y-19;

if ((day==3) && (h>2) && (m>21) && (y==1 || y==2 || y==4 || y==5 || y==7 || y==9 || y==10 || y==12 || y==13 || y==15 || y==16 || y==18)) rh_day=5;

// leap check init:

y=year_num;

while (y>19) y=y-19;

if ((day==5) && (h>11) && (y==3 || y==6 || y==8 || y==11 || y==14 || y==17 || y==19)) flag=1;

} // termination of else

loc=loc+15;

g.drawString(" Rosh Hashana will be at "+rh_day+" day of the week",20,loc);

day=day+354;

s=s+40;

m=m+48;

h=h+8;

while (s>60) {

s=s-60;

m=m+1; }

while (m>60) {

m=m-60;

h=h+1; }

while (h>24) {

h=h-24;

day=day+1; }

while (day>7) day=day-7;

y=year_num;

while (y>19) y=y-19; // check for leap procedure

if (y==3 || y==6 || y==8 || y==11 || y==14 || y==17 || y==19) {

loc=loc+15;

g.drawString("leap ",20,loc);

l_count=l_count+1;

if (l_count==3) // every 3 leap years we must add another

{ l_count=0; // second. 1/3 sec for every leap year

add_to_s=4;

} else add_to_s=3;

day=day+29;

s=s+add_to_s;

m=m+44;

h=h+12;

while (s>60)

{ s=s-60;

m=m+1; }

while (m>60)

{ m=m-60;

h=h+1; }

while (h>24)

{ h=h-24;

day=day+1; }

while (day>7) day=day-7;

}

}

}

}