Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help solving this java program Cannot use arrays for this only conditional statements such as if and else. Program uses two classes. A control

Need help solving this java program

Cannot use arrays for this only conditional statements such as if and else.

Program uses two classes. A control class, DatesDriver.java and an object class, Dates.java. Dates.java contains a number of methods that together will let a client program know if a given date is valid or not. DatesDriver.java uses this class to test the validity of a date entered by the user. Method signatures are provided for both classes as well as comments that let you know what needs to be done. Complete both classes to allow dates to be tested

DatesDriver.java

import java.util.Scanner; /** * DatesDriver.java - Determine whether a 2nd- or 3rd-millenium date entered by * the user is valid. * * @author * @version */ public class DatesDriver { /** * Main method. * * @param args the command line arguments */ public static void main( String[] args ) { int month; // month read in from user int day; // day read in from user int year; // year read in from user boolean monthValid; // true if month entered by user is valid boolean dayValid; // true if day entered by user is valid boolean yearValid; // true if year entered by user is valid Dates date; Scanner scan; scan = new Scanner( System.in ); // Prompt the user for the month, day, and year. Then get integer // month, day, and year from user // create a Dates object using the month, day, and year // entered by the user // Check to see if month is valid -- assign to the boolean monthValid // Check to see if day is valid -- assign to the boolean dayValid // Check to see if the year is valid -- assign to the boolean yearValid // Determine whether date as a whole is valid and print appropriate // message } // method main } // class TestDates

Dates.java

/** * Dates.java - An class that represents a date. * * @author * @version */ public class Dates { private int day; private int month; private int year; /** * constructor. * * @param m the month * @param d the day of the month * @param y the year */ public Dates( int m, int d, int y ) { month = m; day = d; year = y; } // constructor // -------------------------- public methods --------------------------- /** * isValidDay - returns true if the day of the month is valid. A date is * valid if it has the correct number of days for the month (31 for Jan, * Mar, May, Jul, Aug, Oct, Dec; 30 for Apr, Jun, Sep, Nov; 28 for Feb - * except leap year, when it is 29) * * @return boolean */ public boolean isValidDay() { return false; // stub, you'll need to replace this } // isValidDay /** * isValidMonth - returns true if the month of the year is valid. A month is * valid if it is an int between 1 and 12 (inclusive) * * @return boolean */ public boolean isValidMonth() { return false; // stub, you'll need to replace this } // isValidMonth /** * isValidYear - returns true if the year is valid. A year is valid if it is * an int between 1000 and 2999 (inclusive) * * @return boolean */ public boolean isValidYear() { boolean isValid = false; if ( year >= 1000 && year <= 2999 ) { isValid = true; } return isValid; } // isValidYear // ------------------------- private methods --------------------------- /** * isLeapYear - returns true if the the year entered is a leap year. This is * a helper method used by the isValidMonth method. * * A given year is 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. * * @return boolean */ private boolean isLeapYear() { return false; // stub, you'll need to replace this } // isLeapYear } // class Dates

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions