Hey,
I'm writing a program as follows:
Suppose you are writing a program that tells what day of the week someone’s birthday falls on this year. Write a method named getDayOfWeek that takes an int parameter, representing what day of the year it is, and returns the numeric value for “Monday”. For example, for 1999, the first day of the year was on Friday. The thirty-second day of the year (February 1, 1999) was a Monday, so getDayOfWeek(1) should return the numeric value for “Friday” and getDayOfWeek(32) should return the numeric value for “Monday”. (Hint: if you divide the day of the year by 7, the remainder will always be a numeric value between 0 and 6, which can be made to correspond to the days of the week).
As part of this program, you’ll also want a method that takes the month and day as parameters and re-turns what day of the year it is. For example, getDay(1,1) should return 1; getDay (2,1) should return 32; and getDay (12,31) should return 366. (Hint: If the month is 3, and the day is 5, you have to add the number of days in January plus the number of days in February to 5 to get the result: 31 + 28 + 5 = 64.)
Design and develop a Java Applet, named BirthdayApplet, that lets the user input their birth date (month, day and 4-digit year) and displays which day of the week it falls on for the year 2007 along with an indication of whether the year they were born was a leap year or not. Use the getDayOfWeek, getDay, and isLeapYear methods described above.
The applet should contain three separate TextField components for inputting the month, day and year along with Labels indicating their purpose and expected format (i.e. year = xxxx). Once the user has entered values into the text fields, they may select the “Display Birthday” Button to display their birthday for THIS year (2008). Your program should also let the user know if the year they were born was a leap year or not. The format for displaying the birthday follows (i.e. User entered November 24, 2000):
November 2008
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
The month name and current year should be displayed in the first row, the weekdays should be labeled in the second row, and the respective calendar for that month displayed beneath. The actual birthday must be “highlighted” in some fashion (i.e. bold, colored, circled, etc.). You may use any text-related GUI component(s) to display the birthday and associated month calendar. You may select the style and size of the text you would like to use for displaying the month calendar, just ensure that the requested birthday is “highlighted“ (identifiable from the other printed values) when complete.
I'm getting a little lost and confused...here's what I have so far, and I hope someone can give me a few pointers to get this rolling and get on the right path. Thanks.
import java.applet.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
public class BirthdayApplet extends Applet implements ActionListener
{
public static int WIDTH=500, HEIGHT=500;
private Button displayButton;
private TextField monthField, dayField, yearField;
private AudioClip myAudioClip;
private int inputMonth, inputDay, inputYear;
private int firstDayofYear = 2, firstDayofMonth = -1;
// Creates arrays to store the days in the month and their names.
int[] daysINmonth = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
String[] monthNames = {" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int[] daysINweek = {0, 1, 2, 3, 4, 5, 6};
String[] dayNames = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Satruday"};
public void init()
{
setSize (WIDTH, HEIGHT);
// Plays 'Happy Birthday' Song
myAudioClip = getAudioClip(getCodeBase(), "../../audio.mid");
myAudioClip.loop();
// Creates the textfields, labels, and buttons.
displayButton = new Button ("Display Birthday");
displayButton.addActionListener(this);
monthField = new TextField (2);
dayField = new TextField (2);
yearField = new TextField (4);
Label monthLabel = new Label ("Month");
Label dayLabel = new Label (" Day");
Label yearLabel = new Label (" Year");
// Adds the buttons, labels, and textfields to applet.
add(monthLabel);
add(monthField);
add(dayLabel);
add(dayField);
add(yearLabel);
add(yearField);
add(displayButton);
}
public void paint (Graphics g)
{
g.drawString(monthNames[inputMonth] + " 2008", 200, 100);
g.drawString("S" + " " + "M" + " " + "T" + " " + "W" + " " + "R" + " " + "F" + " " + "S", 165, 125);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == displayButton)
{
// Converts inputs from strings to integer values.
inputMonth = Integer.parseInt(monthField.getText());
inputDay = Integer.parseInt(dayField.getText());
inputYear = Integer.parseInt(yearField.getText());
repaint();
}
}
}