Answered step by step
Verified Expert Solution
Question
1 Approved Answer
DO IN JAVA DO IN JAVA DO in JAVA, -----------------------------------------------------------------------------------------------Previous code:------------------------------------------------------------------------------------------------------- DATE FILE public class Date { private int day; private int month; private int
DO IN JAVA DO IN JAVA
DO in JAVA,
-----------------------------------------------------------------------------------------------Previous code:-------------------------------------------------------------------------------------------------------
DATE FILE
public class Date { private int day; private int month; private int year; public Date() { this.day = 10; this.month = 05; this.year = 2010; } public Date(int day, int month, int year) { this.day = day; this.month = month; this.year = year; } public Date(String month, int day, int year) { this.day = day; if (month.equalsIgnoreCase("January")) this.month = 1; else if (month.equalsIgnoreCase("February")) this.month = 2; else if (month.equalsIgnoreCase("March")) this.month = 3; else if (month.equalsIgnoreCase("April")) this.month = 4; else if (month.equalsIgnoreCase("May")) this.month = 5; else if (month.equalsIgnoreCase("June")) this.month = 6; else if (month.equalsIgnoreCase("July")) this.month = 7; else if (month.equalsIgnoreCase("August")) this.month = 8; else if (month.equalsIgnoreCase("September")) this.month = 9; else if (month.equalsIgnoreCase("October")) this.month = 10; else if (month.equalsIgnoreCase("November")) this.month = 11; else if (month.equalsIgnoreCase("December")) this.month = 12; this.year = year; } public Date(int day, int year) { super(); this.year = year; if (day 31 && day 59 && day 90 && day 120 && day 151 && day 181 && day 212 && day 243 && day 273 && day 273 && day 334 && day 10 && day 10) { return "( 0" + month + "/" + day + "/" + year + " )"; } else { return "( " + month + "/" + day + "/" + year + " )"; } } public String convertInSecondFormat() { if (month 10 && day 10) { return "( " + getMonthName() + "/" + day + "/" + year + " )"; } else { return "( " + getMonthName() + "/" + day + "/" + year + " )"; } } public String convertInThirdFormat() { return "(" + getTotalDay() + " " + year + ")"; } @Override public String toString() { return convertInFirstFormat() + " " + convertInSecondFormat() + " " + convertInThirdFormat(); } } ------------------------------TEST FILE_---------------------------------------------------------------
import java.util.Date; import java.util.Scanner; public class Test { public Test(int day, int month) {} public Test(String monthName, int days, int year) {} public Test(int day, int month, int year) { } public static void main(String[] args){ Scanner scan=new Scanner(System.in); Date date = null; int option; System.out.println("this program converts dates entered to multiple formats"); System.out.println("Enter your date in the format you choose and all three formats will be provided as an output"); do { System.out.println("Enter date " + "1. (MM/DD/YYYY) " + "2. (Month Name, DD, YYYY) " + "3. (DDD YYYY) " + "4. Exit"); System.out.print("Please choose any option: "); option = scan.nextInt(); scan.nextLine(); switch (option) { case 1: System.out.print("Enter day: "); int day = scan.nextInt(); System.out.print("Enter month: "); int month = scan.nextInt(); System.out.print("Enter year: "); int year = scan.nextInt(); date = new Date(day, month, year); System.out.println("Your date is: "); System.out.println(date.toString()); break; case 2: System.out.print("Enter Month name: "); System.out.print("Enter day: "); day = scan.nextInt(); System.out.print("Enter year: "); year = scan.nextInt(); System.out.println("Your date is: "); assert date != null; System.out.println(date.toString()); break; case 3: System.out.print("Enter days: "); int days = scan.nextInt(); System.out.print("Enter year: "); year = scan.nextInt(); date = new Date (days); System.out.println("Your date is: "); System.out.println(date.toString()); break; case 4: System.out.println("Thank you"); break; default: System.out.println("Invalid try again!"); break; } } while (option != 4); scan.close(); } }
For this programming assignment you will be re-using portions of your code from the last assignment as a starting point. You are to create a new DateFileTest class that uses the existing Date Class for the following: Instead of bringing in dates from a user, you will be bringing in dates from a text file. You should use the existing Date class to create date objects from file inputs The data in the file is provided in alternating formats in order from MM/DD/YYYY to Month name, DD, YYYY (just those two formats to simplify the input handling and verification). Spaces are used in the file as delimiters between integers and strings in the date format. You will use the file provided here DAtes in multiple formats. 8 17 1943 April 1 1985 4 27 2010 September 27 2005 12 13 2001 June 5 1075 11 25 1974 December 11 2004 21 14 1980 1. Your code is to handle exceptions for the following situations; the file is not found or can't be opened, in which case the program informs the user and ends. the month is not a valid month (between 1-12), using a try/catch block the year is not a valid year (assume between 1800-2020 is valid, using a try/catch block) the entry is not a valid month name (must start with a capital and be spelled correctly as a string) If any of these exceptions occur, your program must disregard that specific date, output an error message to the display, NOT write that specific date to the file, and continue to move on to process the rest of the data in the file Your program will create a new text file and write dates out to that file. You will write out all 3 formats (with appropriate / and, delimiters) to the file for each date read in from the file. Your program files must include a program header that includes your name, course discussion section, and program description. Well structured and commented code are expected. Your submission must include all program files, output text file, and execution screenshots showing your messages from error handling. Submissions without all the files will not receive a grade and no late submissions will be accepted
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