Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Provide answer to this practice excercise using Eclipse or Java; Below are the directions Following is the entire code: import java.util.Scanner; public class DateThirdTry {
Provide answer to this practice excercise using Eclipse or Java;
Below are the directions
Following is the entire code:
import java.util.Scanner; public class DateThirdTry { private String month; private int day; private int year; //a four digit number. public void writeOutput( ) { System.out.println(month + " " + day + ", " + year); } public void readInput( ) { boolean tryAgain = true; Scanner keyboard = new Scanner(System.in); while (tryAgain) { System.out.println("Enter month, day, and year"); System.out.println("as three integers:"); System.out.println("do not use commas or other punctuations."); int monthInput = keyboard.nextInt( ); int dayInput = keyboard.nextInt( ); int yearInput = keyboard.nextInt( ); if (dateOK(monthInput, dayInput, yearInput) ) { setDate(monthInput, dayInput, yearInput); tryAgain = false; } else System.out.println("Illegal date. Reenter input."); } } public void setDate(int month, int day, int year) { if (dateOK(month, day, year)) { this.month = monthString(month); this.day = day; this.year = year; } else { System.out.println("Fatal Error"); System.exit(0); } } public void setMonth(int monthNumber) { if ((monthNumber 12)) { System.out.println("Fatal Error"); System.exit(0); } else month = monthString(monthNumber); } public void setDay(int day) { if ((day 31)) { System.out.println("Fatal Error"); System.exit(0); } else this.day = day; } public void setYear(int year) { if ( (year 9999) ) { System.out.println("Fatal Error"); System.exit(0); } else this.year = year; } public boolean equals(DateFifthTry otherDate) { return ( (month.equalsIgnoreCase(otherDate.month)) && (day == otherDate.day) && (year == otherDate.year) ); } public boolean precedes(DateFifthTry otherDate) { return ( (year = 1) && (monthInt = 1) && (dayInt = 1000) && (yearInt
CODE:
public static void main(String[] args) {
// TODO Auto-generated method stub
DateThirdTry date = new DateThirdTry();
date.readInput();
date.writeOutput();
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started