I am in a beginner java class and am having trouble getting a program to work. We are asked to create a calendar type application to display a calendar. It uses a application and a worker class I am stuck and have been working on it all day. Here is the code i have, Please help if you can i have been working on this for way too long.
Below is the worker.
Code:
public class Calendar {
String tempStr;
public int day;
public int year;
public Calendar(int nday, int nyear, int fmonth){
day = nday;
year = nyear;
}
public String displayJanuary(){
String display = "";
display = "January of year " + year +"\n" +
"S M T W T F S"+"\n" +
space();
for(int i=1;i<32;i++){
display += day(i);
}
return display;
}
private String space(){
String space = "";
for(int i=0; i<day-1;i++){
space += " ";
}
return space;
}
private String day(int currentday){
String printday = ""+currentday;
if(currentday<10){
printday+=" ";
}
else{
printday+=" ";
}
boolean isWeekend = weekend(currentday);
if(isWeekend==true){
printday+="\n";
}
return printday;
}
private boolean weekend(int currentday){
int result = (day+currentday-1)%7;
if(result==0){
return true;
}
else{
return false;
}
}
public String showFebruary(){
String show = "";
show = "February of year " + year +"\n" +
"S M T W T F S"+"\n" +
space();
for(int j=1;j<day;j++){
show += day(j);
}
return show;
}
private boolean isleap(int leapyear){
int isleap = (year%4);
if (isleap==0){
return true;
}
else{
return false;
}
}
private int dayinfeb(int days){
if (true) {
return 29;
}
else{
return 28;
}
}
private String area(){
String area="";
for(int j=0; j<day-1;j++){
area +=" ";
}
return area;
}
private String today(int currentday){
String printtoday = ""+currentday;
if(currentday<10){
printtoday+=" ";
}
else{
printtoday+=" ";
}
boolean isWeekend = weekend(currentday);
if(isWeekend==true){
printtoday+="\n";
}
return printtoday;
}
private boolean endweek(int currentday){
int result = (day+currentday-1)%7;
if(result==0){
return true;
}
else{
return false;
}
}
}
Code:
import javax.swing.JOptionPane;
public class TestCalendar {
public static void main(String[] args) {
String tempStr = " ";
int yearNum;
int dayNum;
tempStr = JOptionPane.showInputDialog("Enter the year");
yearNum = Integer.parseInt(tempStr);
tempStr = JOptionPane.showInputDialog("Enter the day of the week for January 1");
dayNum = Integer.parseInt(tempStr);
tempStr = JOptionPane.showInputDialog("Enter the year");
yearNum = Integer.parseInt(tempStr);
tempStr = JOptionPane.showInputDialog("Enter the day of the week for February 1");
dayNum = Integer.parseInt(tempStr);
}
}
Comment