Using java Create a class called Date that includes 3 instance variables—a month
ID: 3697087 • Letter: U
Question
Using java Create a class called Date that includes 3 instance variables—a month (type int), a day (type int), and a year (type int). Provide a constructor that initializes the 3 instance variables and assumes the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day, and year separated by forward slashes(/). Write a test application named DateTest that demonstrates class Date’s capabilities.
This is the code that i recieved from the last person who answered this question:
When I try to run it in netbeans I get on getting the error message :Error: Could not find or load main class javaapplication52.JavaApplication52
class Date
{
int month, day, year;
Date()
{
month=05;
day=01;
year=2016;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public void displayDate()
{
Date d=new Date();
d.setDay(01);
d.setMonth(05);
d.setYear(2016);
System.out.println("Current date is :" +d.getDay() + "/" + d.getMonth() + "/" + d.getYear());
}
}
class DateTest
{
public static void main(String args[])
{
Date d=new Date();
d.displayDate();
}
}
Explanation / Answer
Following are the steps you have to follow to get rid of the error
1. Start NetBeans
2. File -> New Project
3. select Java -> Java Application -> Next
4. Give Project Name as DateTest -> Finish
now copy proper code in the project and run it, you will get the output.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.