Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Draw a Flowchart and Write a Pseudocode for this Java Program: /* Program Name: BadDate.java Function: This program determines if a date entered by the

Draw a Flowchart and Write a Pseudocode for this Java Program:

/* Program Name: BadDate.java

Function: This program determines if a date entered by the user is valid.

Input: Interactive

Output: Valid date is printed or user is alerted that an invalid date was entered.

*/

import javax.swing.JOptionPane;

public class BadDate

{

public static void main(String args[])

{

// Declare variables

String yearString;

String monthString;

String dayString;

int year;

int month;

int day;

boolean validDate = true;

final int MIN_YEAR = 0, MIN_MONTH = 1, MAX_MONTH = 12, MIN_DAY = 1, MAX_DAY = 31;

// This is the work of the housekeeping() method

// Get the year, then the month, then the day

yearString = JOptionPane.showInputDialog("Enter Year ");

monthString = JOptionPane.showInputDialog("Enter Month ");

dayString = JOptionPane.showInputDialog("Enter Day ");

// Convert Strings to integers

year = Integer.parseInt(yearString);

month = Integer.parseInt(monthString);

day = Integer.parseInt(dayString);

// This is the work of the detailLoop() method

// Check to be sure date is valid

if( year <= MIN_YEAR ) // invalid year

validDate = false;

else if ( month < MIN_MONTH || month > MAX_MONTH ) // invalid month

validDate = false;

else if ( day < MIN_DAY || day > MAX_DAY ) // invalid day

validDate = false;

// This is the work of the endOfJob() method

// Test to see if date is valid and output date and whether it is valid or not

if( validDate == true )

{

System.out.println(month+"/"+day+"/"+year+" is valid");

// Output statement

JOptionPane.showMessageDialog(null,month+"/"+day+"/"+year+" is valid");

}

else

{

System.out.println(month+"/"+day+"/"+year+" is invalid");

// Output statement

JOptionPane.showMessageDialog(null,month+"/"+day+"/"+year+" is invalid");

}

} // end of main() method

} // end of BadDate class

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

3. Evaluate your listeners and tailor your speech to them

Answered: 1 week ago