Please send me answer within 10 min!! I will rate you good for sure!! Please send me explaination of your code and provide screenshot of your code and output!! Please Help. What is wrong with my code? It works fine but the test cases validDate2 and validDate3 fail when running the program. Can you please tell me what's wrong? ORIGINAL CODE:

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

Please send me answer within 10 min!! I will rate you good for sure!! Please send me explaination of your code and provide screenshot of your code and output!!

Please Help. What is wrong with my code? It works fine but the test cases validDate2 and validDate3 fail when running the program. Can you please tell me what's wrong?

ORIGINAL CODE:

package Lab2;

public class Lab2 {

/**

* Takes a date as three integers:day, month, and year.

* The method returns a true if the date is valid and false otherwise.

* The method checks if the month is valid, and the year is after the year 1000.

* It checks if the day is valid according to the month. If the month is February,

* it checks if the year is a leap year

*/

public static boolean validDate(int day, int month, int year) {

// declaring boolean variables as originally false

boolean yearValid = false;

boolean monthValid = false;

boolean dayValid = false;

boolean isLeapYear = false;

 

// truth value = T if the month is greater than 1 and less than 12 inclusive

if (month >= 1 && month <= 12) {

monthValid = true;

}

 

// if the year is greater than 1000 inclusive, the truth value is T

else if (year >= 1000) {

yearValid = true;

}

 

// It is a leap year if the year is divisible by 400 or divisible by 4 and not divisible by 100

else if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {

isLeapYear = true;

}

 

// If statement for if the month is February and it is a leap year

else if (month == 2 && isLeapYear == true) {

 

// truth value = T if the day is greater than 1 and less than 29 inclusive

if (day >= 1 && day <= 29) {

dayValid = true;

}

}

 

// if the day is greater than 31 or less than 1, it is invalid

else if (day > 31 || day < 1) {

dayValid = false;

}

 

// April, June, September and November have 30 days

else if (month == 4 || month == 6 || month == 9 || month == 11) {

 

// truth value = T if the day is greater than 1 and less than 30 inclusive

if (day >= 1 || day <= 30) {

dayValid = true;

}

}

 

// January, March, May, July, August, October, and December have 31 days

else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {

 

// truth value = T if the day is greater than 1 and less than 30 inclusive

if (day >= 1 || day <= 31) {

dayValid = true;

}

}

 

// If statement for if it is February and it is not a leap year

else if (month == 2) {

 

// truth value = T if the day is greater than 1 and less than 28 inclusive

if (day >= 1 || day <= 28) {

dayValid = true;

}

 

else if (day > 28) {

dayValid = false;

}

}

 

// If the above statements don't apply, the date is invalid and the method returns false

else {

return false;

}

 

// the method returns the truth value of the date

return (yearValid && monthValid && dayValid);

}

}

boolean valid = Lab2.validDate (31, 2, 2022);
assertEquals("Failed validDate 1", false, valid);
}
@Test
void validDate2() {
boolean valid = Lab2.validDate (31, 3, 1765);
assertEquals("Failed validDate 2", true, valid);
}
@Test
void validDate3() {
boolean valid = Lab2.validDate (29, 2, 1600);
assertEquals("Failed validDate 3", true, valid);
}
@Test
void validDate4 () {
boolean valid = Lab2.validDate (29, 2, 2022);
assertEquals("Failed validDate 4", false, valid);
}
@Test
void validDate5() {
boolean valid = Lab2.validDate(0, 2, 2022);
assertEquals("Failed validDate 5", false, valid);
}
@Test
void validDate6() {
boolean valid = Lab2.validDate (29, 0, 2022);
assertEquals("Failed validDate6", false, valid);
}
}
@Test
void validDate7() {
boolean valid = Lab2.validDate(12, 10, 876);
assertEquals("Failed valid Date6", false, valid);
Transcribed Image Text:boolean valid = Lab2.validDate (31, 2, 2022); assertEquals("Failed validDate 1", false, valid); } @Test void validDate2() { boolean valid = Lab2.validDate (31, 3, 1765); assertEquals("Failed validDate 2", true, valid); } @Test void validDate3() { boolean valid = Lab2.validDate (29, 2, 1600); assertEquals("Failed validDate 3", true, valid); } @Test void validDate4 () { boolean valid = Lab2.validDate (29, 2, 2022); assertEquals("Failed validDate 4", false, valid); } @Test void validDate5() { boolean valid = Lab2.validDate(0, 2, 2022); assertEquals("Failed validDate 5", false, valid); } @Test void validDate6() { boolean valid = Lab2.validDate (29, 0, 2022); assertEquals("Failed validDate6", false, valid); } } @Test void validDate7() { boolean valid = Lab2.validDate(12, 10, 876); assertEquals("Failed valid Date6", false, valid);
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of Flowchart
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
  • SEE MORE 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