Can you indentify Error in this code and repair it .The output of days is not coming correct. import java.util.Scanner; //Data.java public class Date { Scanner sc=new Scanner(System.in); //private instance variables private int year, month, day; // Constructs a Date instance with the given year, month and day public Date(int year, int month, int day) { this.year = year; this.month = month; this.day = day; } // Returns the year public int getYear() { System.out.println("Enter a year "); this.year=sc.nextInt(); return this.year; } // Returns the month public int getMonth() { System.out.println("Enter a Month "); this.month=sc.nextInt(); return this.month; } // Returns the day public int getDay() { System.out.println("Enter a Date "); this.day=sc.nextInt(); return this.day; } // Sets the year. input validation */ public void setYear(int year) { this.year=year; if(year % 4 != 0) { System.out.println("Enter a valid Year :"); this.year=sc.nextInt(); } } //Sets the month. input validation */ public void setMonth(int m) { this.month=m; if(m==0 || m>=12) { System.out.println("Enter valid Month"); this.month=sc.nextInt(); this.month=m; } } //Sets the day public double setDay(int d) { this.day=d; if(d==0 || d>31) { System.out.println("Enter valid day"); this.day=sc.nextInt(); this.day=d; } return this.day; } public void input() //input plus validator method { this.getYear(); this.setYear(year); this.getDay(); this.setDay(day); this.getMonth(); this.setMonth(month); } public void Display() { System.out.println(this.month+"/"+this.day+"/"+"/"+this.year); } // Returns a descriptive String in the form "MM/DD/YYYY" with leading zero public String toString() { return String.format("%02d/%02d/%4d", month, day, year); } // Sets year, month and day. input public void setDate(int year, int month, int day) { this.year = year; this.month = month; this.day = day; } } //main class //MainClass.java //class to test the Date class public class MainClass{ public static void main(String[] args) { Date D1 =new Date (0, 0, 0); D1.input(); D1.Display(); } }
Can you indentify Error in this code and repair it .The output of days is not coming correct.
import java.util.Scanner;
//Data.java
public class Date {
Scanner sc=new Scanner(System.in);
//private instance variables
private int year, month, day;
// Constructs a Date instance with the given year, month and day
public Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
// Returns the year
public int getYear() {
System.out.println("Enter a year ");
this.year=sc.nextInt();
return this.year;
}
// Returns the month
public int getMonth() {
System.out.println("Enter a Month ");
this.month=sc.nextInt();
return this.month;
}
// Returns the day
public int getDay() {
System.out.println("Enter a Date ");
this.day=sc.nextInt();
return this.day;
}
// Sets the year. input validation */
public void setYear(int year) {
this.year=year;
if(year % 4 != 0) {
System.out.println("Enter a valid Year :");
this.year=sc.nextInt();
}
}
//Sets the month. input validation */
public void setMonth(int m) {
this.month=m;
if(m==0 || m>=12)
{
System.out.println("Enter valid Month");
this.month=sc.nextInt();
this.month=m;
}
}
//Sets the day
public double setDay(int d) {
this.day=d;
if(d==0 || d>31)
{
System.out.println("Enter valid day");
this.day=sc.nextInt();
this.day=d;
}
return this.day;
}
public void input()
//input plus validator method
{
this.getYear();
this.setYear(year);
this.getDay();
this.setDay(day);
this.getMonth();
this.setMonth(month);
}
public void Display()
{
System.out.println(this.month+"/"+this.day+"/"+"/"+this.year);
}
// Returns a descriptive String in the form "MM/DD/YYYY" with leading zero
public String toString() {
return String.format("%02d/%02d/%4d", month, day, year);
}
// Sets year, month and day. input
public void setDate(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
}
//main class
//MainClass.java
//class to test the Date class
public class MainClass{
public static void main(String[] args) {
Date D1 =new Date (0, 0, 0);
D1.input();
D1.Display();
}
}
![Enter a year
342342
Enter a valid Year :
4324
Enter a Date
34
Enter valid day
3
Enter a Month
45
Enter valid Month
3
45/34//4324](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1ed6f9fa-1d04-4ab0-bc18-15e7e2acd2fc%2F4b0a4699-b9ca-481d-a8b1-e6f698a09409%2Fss5017p_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)