# Solved: Help with a beginner's Java program



## CaseyRenee87 (May 4, 2009)

Hey everyone!

I have a few questions about writing a program for one of my assignments, the concepts and everything are so intense and complicated due to I am a hatchling to computer programming, the only other practice I've had is with some JavaScript (another part of my course, and I learned to print the date using it) but this program is suoopsed to print a predefined date to the screen using three pieces of information as Instance variables: month, day and year all type Int.
it also is supposed to include a constructor that initializes these three variables and assumes the values provided are correct. Also I am supposed to provide a set and a get method for each instance variable. and lastly I have to provide a method called DisplayDate that displays the date in the variables seperated by /'s, in a test application seperate from the Date class. I understand how to do some of this but I keep missing out on one crucual point..thats keeping my programs from compiling..and it has to do with the test appliaction mainly..i dont know what instances and stuff to write in that class. anyways it's got me stumped due to i am a newbie to OOP  if anyone can help it would be greatly appreciated!
thanks!
casey


----------



## NeonFx (Oct 22, 2008)

Sure  I'd be glad to help. What do you have so far?

Because this is an assignment, I can't just give you the answer.


----------



## CaseyRenee87 (May 4, 2009)

hey thanks! ok here is my code so far, I got a LOT of it fixed today..there is just one problem left my complier gives this error:
cannot find symbol constructor Date[java.lang.String...etc etc. I cant seem to figure out what's causing it?

anyways here's my raw code as of now:

//dateTest.java Assignment: 6944
//name: Casey Clark student no: 2008030031
public class DateTest
{
public static void main(String args[])
{
//create Date objects
Date date1=new Date("06","24","2009");

//call and display initial value of month, day and year for each Date object
date1.displayDate();
}//end main method
}//end class DateTest

//Date.java assignment: 6944
//name: casey clark 
//Student no:MA2008030031
class Date
{
//Instance variables
private int monthValue; //declares month
private int dayValue; //declares day
private int yearValue; //declares year

//3 argument constructor
public Date(int month, int day, int year)
{
monthValue=month;
dayValue=day;
yearValue=year;
}
//set month
public void setMonth(int month)
{
monthValue=month;
}//end setMonth

//getMonth
public int getMonth()
{
return monthValue;
}//end getMonth

//set day
public void setDay(int day)
{
dayValue=day; 
}//end setDay

//getDay
public int getDay()
{
return dayValue;
}//end getDay

//set year
public void setYear(int year)
{
yearValue=year;
}//end setYear

//get year
public int getYear()
{
return yearValue;
}
//display the date
public void displayDate()
{ 
//statement calls getMonth, getDay and getYear
System.out.printf("the date is:\n%d/%d/%d%d%d%d", getMonth(),getDay(),getYear()); 
}//end method displayDate

}//end class Date

Both are actually in two seperate classes in the same folder, i pasted them together so you can see all of the source code.


----------



## NeonFx (Oct 22, 2008)

> Date date1=new Date("06","24","2009");


That is your first problem right there. Take the quotes out of the arguments. When you use quotes there your computer will save them as string variables in memory, not integers.

The code will look for Date(String x, String y, String z), and not for Date(int x, int y, int z)


----------



## NeonFx (Oct 22, 2008)

Also:


> System.out.printf("the date is:\n%d/%d/%d%d%d%d", getMonth(),getDay(),getYear());


Should be:

System.out.printf("the date is:\n%d/%d/%d", getMonth(),getDay(),getYear());

Each %d is a pointer for each of the variables following the string text.


----------



## CaseyRenee87 (May 4, 2009)

hey neonfx! thank you so much for the help!!!! hehe I knew i was doing something wrong..I just couldn't determine what it was that was causing that bug..or bug/s  I appreciate the assistance majorly I'll re edit the files and let you know if they compile right this time.


----------



## NeonFx (Oct 22, 2008)

Sure thing :up:

I'm not the only one that provides help with Java problems here. Do come back and make a new topic if you need help again.


----------



## CaseyRenee87 (May 4, 2009)

Will do!

I have about 8 Java lessons left and they will only get more complex and advanced, so I am quite sure I will be coming back for help quite often when i cant figure it out on my own of course.  thanks again for the help! that was the last bug and I sent in my assignment! hopefully I will do well.


----------

