Ok so im writing a small java application using Zellers Algorithm to work out the day of the week for a given date. I have never compiled a java program before because i'm still moderately new to the language and IDE's etc. I am using netbeans.
I have tried to compile the class but it comes up with an error Message saying "Could not find the main class: zellers.algorithm.Main. Program will exit."
My code is as follows:
package zellers.algorithm;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ZellersAlgorithm implements ActionListener{
private int d; //day of week (dd)
private int m; //month (mm)
private int y; //year born (yyyy)
private String[] DAY_OF_WEEK = {"Sunday","Monday", "Tuesday", "Wednesday",
"Thursday","Friday","Saturday"};
public String date; //Date entered into text field
//GUI objects
JTextField dateInput;
JButton submit;
JLabel result;
public ZellersAlgorithm(){
//constructor
d=1;
m=1;
y=1980;
date = "";
setupInterface();
}
public void setupInterface(){
//Create window objects
dateInput = new JTextField(10);
dateInput.addActionListener(this);
submit = new JButton("Find Day");
submit.addActionListener(this);
JLabel inst = new JLabel("Enter the date (dd/mm/yyyy): ");
result = new JLabel();
FlowLayout flo = new FlowLayout();
//create new window
JFrame window = new JFrame();
window.setSize(250,120);
window.setTitle("Zellers Algorithm");
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
window.setLayout(flo);
//Add objects to window
window.add(inst);
window.add(dateInput);
window.add(submit);
window.add(result);
}
public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if(source == submit){
date = dateInput.getText();
this.implmentZellers();
}
}
public void implmentZellers(){
//implements the zellers algorithm
/**
* Let day = d
* Month = m
* Year = y
*
*
* if m < 3
* m +=12
* y--;
*
* let A = first 2 digits of y
* let B = last 2 digits of y
*
* myResult = int(2.6M - 5.39) + int (B/4) + int (A/4) + d + b - 2A
*
* find remainder of (myResult / 7)
*
* dayNames[remainder]
*/
//Splits date string into Day month and year
String splitItems[] = date.split("/");
d = Integer.parseInt(splitItems[0]);
m = Integer.parseInt(splitItems[1]);
y = Integer.parseInt(splitItems[2]);
System.out.println(d);
System.out.println(m);
System.out.println(y);
if (m < 3){
m += 12;
y--;
System.out.println("--------");
System.out.println("m < 3");
System.out.println("Month: " + m);
System.out.println("Year: " + y);
System.out.println("--------");
}
int A;
int B;
double myResult;
A = y / 100;
System.out.println("A: " + A);
B = y % 100;
System.out.println("B: " + B);
//myResult = int(2.6m - 5.39) + int (B/4) + int (A/4) + d + B - 2A
myResult = ((int)((2.6 * m)-5.39)) + ((int)(B/4)) + ((int)(A/4)) + d + B - (2*A);
System.out.println(myResult);
//remainder of myResult is index for the day born in DAY_OF_WEEK
System.out.println("DOW: " + DAY_OF_WEEK[(int)myResult % 7]);
result.setText("The day was a " + DAY_OF_WEEK[(int)myResult % 7]);
}
public static void main(String[] args) {
new ZellersAlgorithm();
}
}
I assumed that this would compile as is has the main method but for some reason it won't.
Can anyone help with this either by ammending the code or by instructing me how to compile the file. I can use cmd as well as Netbeans and I also have Eclipse so any suggestions welcome.
Thank you in advance