Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HERE IS THE FILE THAT I HAVE TO TEST AND BELOW IT IS THE DATESTEST FILE... publi

ID: 3621383 • Letter: H

Question

HERE IS THE FILE THAT I HAVE TO TEST AND BELOW IT IS THE DATESTEST FILE...


public class Dates
{
//Add the needed instance variables to store the dates
private int month;
private int day;
private int year;



/**
* Constructor for the Dates class. This should take (in this order)
* an int representing the month, an int representing the day, and an int
* representing the year.
*
* NO VALIDATION SHOULD BE DONE ON THE INPUT!
*/
Dates(int m, int d, int y){
month=d;
day=d;
year=y;
}




/**
* Preforms a check to see if the month stored in the class
* is between 1 and 12, inclusive.
*
* This method should be public, should be called isMonthValid and takes no parameters.
* The return type is boolean.
*
* @return true if month is between 1 and 12 (inclusive), false otherwise.
*
*/
public boolean isMonthValid(){
if(month>0 && month<13){
return true;
}
else return false;

}


/**
* Performs a check to see if the year stored in the class
* is between 1000 and 1999, inclusive.
*
* This method should be public, should be called isYearValid and takes no parameters.
* The return type is boolean.
*
* @return true if year is between 1000 and 1999 (inclusive), false otherwise
*
*/
public boolean isYearValid(){
if(year>=1000 && year<2000){
return true;
}
else return false;
}



/**
* Performs a check to see if the year stored in the class
* is a leap year.
*
* A year is a leap year if it meets the following conditions:
* If the year is divisible by 4, it's a leap year UNLESS it's divisible by 100,
* in which case it's not a leap year UNLESS it's divisible by 400, in which case it is a leap year.
* If the year is not divisible by 4, it's not a leap year.
* Put another way, it's a leap year if
* a) it's divisible by 400, or
* b) it's divisible by 4 and it's not divisible by 100.
* So 1600 and 1512 are leap years, but 1700 and 1514 are not.
*
* If the year is not valid, it is not a leap year. (We have a method for checking that!)
*
* To check if something is divisible by a number, use the modulus (%) operator
*
* This method should be public, should be called isLeapYear and takes no parameters.
* The return type is boolean.
*
* @return true if year is a leap year, false otherwise
*
*/

public boolean isLeapYear(){
if(year%400==0 || (year%4==0 && year%100!=0))
return true;
else return false;

}


/**
* Performs a check to see if the day stored in the class
* is valid. This depends on the month and on the year.
*
* This method should be public, should be called isDayValid and takes no parameters.
* The return type is boolean.
*
* @return true if day is valid for the month and year, false otherwise
*
*/

public boolean isDayValid(){
switch(month){
case 1:{
if(day<32 && day>0){
return true;
}
}
case 2:{
if(day<30 && day>0){
return true;
}
}
case 3:{
if(day<32 && day>0){
return true;
}
}
case 4:{
if(day<31 && day>0){
return true;
}
}
case 5:{
if(day<32 && day>0){
return true;
}
}
case 6:{
if(day<31 && day>0){
return true;
}
}
case 7:{
if(day<32 && day>0){
return true;
}
}
case 8:{
if(day<32 && day>0){
return true;
}
}
case 9:{
if(day<31 && day>0){
return true;
}
}
case 10:{
if(day<32 && day>0){
return true;
}
}
case 11:{
if(day<31 && day>0){
return true;
}
}
case 12:{
if(day<32 && day>0){
return true;
}
}
default:
break;
}
return false;
}


/**
* Computes the number of days in the month. This depends on both
* the month and on the year.
*
* If either the month or the year is invalid, then the method should return 0.
* (We have methods for this!)
*
* Note that to figure out the number of days in February you'll
* need to check if it's a leap year. (We also have a method for this!)
*
* (HINT: use a switch statement.)
*
* This method should be PRIVATE, should be called getNumberDaysInMonth and takes no parameters.
* The return type is int.
*
* @return the number of day in the month and year, if month or year is invalid, returns 0.
*
*/
private int getNumberDaysInMonth(){
if(!isMonthValid() || !isYearValid())
return 0;
switch(month){
case (1): {
return 31;
}
case (2): {
if(isLeapYear())
return 28;
else
return 29;
}
case (3): {
return 31;
}
case (4): {
return 30;
}
case (5): {
return 31;
}
case (6): {
return 30;
}
case (7): {
return 31;
}
case (8): {
return 31;
}
case (9): {
return 30;
}
case (10): {
return 31;
}
case (11): {
return 30;
}
case (12): {
return 31;
}

default:
break;



}
return 0;
}





/**
* Performs a check to see if the entire date is valid.
* The month, day, and year must all be valid
*
* This method should be public, should be called isDateValid and takes no parameters.
* The return type is boolean.
*
* @return true if the entire date is valid month, day, and year), false otherwise
*
*/
public boolean isDateValid(){
if(isDayValid() && isMonthValid() && isYearValid() ){
return true;
}
else
return false;
}





/**
* Create a getter to return the year as an int.
*
* The method must be public and called getYear. It should accepts no parameters
* and have a return type of int.
*
* @param args
*/

public int getYear(){
return year;
}



/**
* Create a getter to return the month as an int.
*
* The method must be public and called getMonth. It should accepts no parameters
* and have a return type of int.
*
* @param args
*/

public int getMonth(){
return month;
}




/**
* Create a getter to return the day as an int.
*
* The method must be public and called getDay. It should accepts no parameters
* and have a return type of int.
*
* @param args
*/

public int getDay(){
return day;
}








public static void main(String[] args)
{
//FOR TESTING
int month, day, year; //date read in from user
int daysInMonth; //number of days in month read in
boolean monthValid, yearValid, dayValid; //true if input from user is valid
boolean leapYear; //true if user's year is a leap year

try{
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter month");
String number = bufferedreader.readLine();
month = Integer.parseInt(number);
System.out.println("Enter day");
number = bufferedreader.readLine();
day = Integer.parseInt(number);
System.out.println("Enter year");
number = bufferedreader.readLine();
year = Integer.parseInt(number);
Dates first=new Dates (month,day,year);
if(first.isMonthValid())
System.out.println("Month valid");
if(first.isYearValid())
System.out.println("year valid");
if(first.isLeapYear())
System.out.println("year is leap year");
System.out.println(first.getNumberDaysInMonth());
if(first.isDateValid())
System.out.println("Date valid");
}
catch(Exception e){
}
//Get integer month, day, and year from user
//Create a Dates object
//Check to see if month is valid
//Check to see if year is valid
//Determine whether it's a leap year
//Check the number of days in the month (it's okay even if it is private since this is part of the Dates class).

//Check to see if day is valid
//Determine whether date is valid and print appropriate message
}
}



AND HERE IS THE DATESTEST FILE THAT I HAVE TO TEST....

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


public class DatesTest {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}


public void testDates() {
fai@Testl("Not yet implemented");
}

@Test
public void testIsMonthValid() {
fail("Not yet implemented");
}

@Test
public void testIsYearValid() {
fail("Not yet implemented");
}

@Test
public void testIsLeapYear() {
fail("Not yet implemented");
}

@Test
public void testIsDayValid() {
fail("Not yet implemented");
}

@Test
public void testIsDateValid() {
fail("Not yet implemented");
}

@Test
public void testGetYear() {
fail("Not yet implemented");
}

@Test
public void testGetMonth() {
fail("Not yet implemented");
}

@Test
public void testGetDay() {
fail("Not yet implemented");
}

@Test
public void testMain() {
fail("Not yet implemented");
}

}

Explanation / Answer

What do you want to know about that set of instructions. You want to verify that is the piece of code is right or not................