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(); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education