Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Content For this programming assignment you will be re-using portions of your code from the last assignment as a starting point. You are to

Assignment Content

  1. 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.txt

    • 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.

My Previous Code

import java.util.*; import java.text.DateFormatSymbols;

class Date{ String Date; String Month; String Year; public Date(){} public Date(int M,int D,int Y){ String dt = "" + D; if(dt.length()==1){ this.Date = "0" + dt; } else{ this.Date = "" + dt; } String mt = "" + M; if(mt.length()==1){ this.Month = "0" + mt; } else{ this.Month = "" + mt; } this.Year = "" +Y; } public Date(String M,int D,int Y){ String dt = "" + D; if(dt.length()==1){ this.Date = "0" + dt; } else{ this.Date = "" + dt; } this.Month = M; this.Year = "" + Y; } public Date(int D,int Y){ this.Date = "" + D; this.Year = "" + Y; } public void display(int ch){ if(ch==1){ System.out.println(this.Month+"/"+this.Date+"/"+this.Year); String M = new DateFormatSymbols().getMonths()[Integer.parseInt(this.Month)-1]; System.out.println(M+" "+this.Date+", "+this.Year); if(this.Date.length()==1) System.out.println("00"+this.Date+", "+this.Year); else System.out.println("0"+this.Date+", "+this.Year); } if(ch==2){ String calender[] = {"January","February","March","April","May","June","July","August","September","October","November","December"}; String calender2[] = {"01","02","03","04","05","06","07","08","09","10","11","12"}; String M = ""; for(int i=0;i<12;i++){ if(calender[i].equals(this.Month)){ M = calender2[i]; break; } } System.out.println(M+"/"+this.Date+"/"+this.Year); System.out.println(this.Month+" "+this.Date+", "+this.Year); if(this.Date.length()==1) System.out.println("00"+this.Date+", "+this.Year); else System.out.println("0"+this.Date+", "+this.Year); } if(ch==3){ System.out.println("/"+this.Date+"/"+this.Year); System.out.println(""+this.Date+", "+this.Year); if(this.Date.length()==1) System.out.println("00"+this.Date+", "+this.Year); else System.out.println("0"+this.Date+", "+this.Year); } } } public class DateTest {

public static void main(String[] args) { Scanner s = new Scanner(System.in); while(true){ System.out.println("Select an option: 1. MM/DD/YYYY(02/06/2021) 2. Month name, DD, YYYY(February 06,2021) 3. DDD YYYY(006 2021) 4. Exit"); int ch = s.nextInt(); s.nextLine(); if(ch==1){ System.out.println("Enter Month: "); int M = s.nextInt(); System.out.println("Enter Date: "); int D = s.nextInt(); System.out.println("Enter Year: "); int Y = s.nextInt(); s.nextLine(); Date date = new Date(M,D,Y); date.display(1); } if(ch==2){ System.out.println("Enter Month: "); String M = s.nextLine(); System.out.println("Enter Date: "); int D = s.nextInt(); System.out.println("Enter Year: "); int Y = s.nextInt(); s.nextLine(); Date date = new Date(M,D,Y); date.display(2); } if(ch==3){ System.out.println("Enter Date: "); int D = s.nextInt(); System.out.println("Enter Year: "); int Y = s.nextInt(); s.nextLine(); Date Date = new Date(D,Y); Date.display(3); } if(ch==4) break; } }

}

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

4. Write the structure function corresponding to the following: (a)

Answered: 1 week ago