Implement 1-parameter date constructor that receives string

Assignment Help JAVA Programming
Reference no: EM13940849

Need assistance with driver class and Date class. This is what I have so far for the driver class.
In the driver class, include a loop that repeatedly:
-Asks the user to enter a date or "q" to quit.
-If the entry is not "q", instantiate a Date object.
-If the error variable is null:
-Print the date using numeric format.
-Print the date using alphabetic format.
-Otherwise, print the value of the error variable.

Date objects should store the date in two int instance variables: day and month, and it should include the String instance variable, error, initialized with null.
Implement a 1-parameter Date constructor that receives a dateStr string parameter and performs complete error checking on the given dateStr value. The Date constructor is the entity that's responsible for date error checking. That way, if a Date object is instantiated and if there are no errors, then you're guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value, using an appropriate concatenation of a string constant, input substring, and/or API exception message.
Constructors use the same exception handling rules as methods: In a try block, include the parsing of the month and day substrings and other error-checking logic that will not work if parsing fails.
Take into account the actual number of days in each month, but assume that there are always 28 days in February.
To extract day and month numbers from the given date string, use String's indexOf method to find the location of the slash character, and String's substring method to extract month and day substrings from the input string.
Include a method for printing the date with a numeric format. Use the zero-pad flag in a printf method call to get exactly two digits for each month and day.
Include a method for printing the date with an alphabetic format.
Include a getError method which returns the value of the error instance variable.

Sample session:

Enter a date in the form mm/dd ("q" to quit): 5/2
05/02
May 2
Enter a date in the form mm/dd ("q" to quit): 05/02
05/02
May 2
Enter a date in the form mm/dd ("q" to quit): 52
Invalid date format - 52
Enter a date in the form mm/dd ("q" to quit): 5.0/2
Invalid format - For input string: "5.0"
Enter a date in the form mm/dd ("q" to quit): 13/2
Invalid month - 13
Enter a date in the form mm/dd ("q" to quit): 2/x
Invalid format - For input string: "x"
Enter a date in the form mm/dd ("q" to quit): 2/30
Invalid day - 30
Enter a date in the form mm/dd ("q" to quit): 2/28
02/28
February 28
Enter a date in the form mm/dd ("q" to quit): q

Reference no: EM13940849

Questions Cloud

Develop a management consultancy practice : Now, assume that the firm wants to develop a management consultancy practice. (Alternatively, you may choose to add a legal services line instead.). Create a separate new matrix that summarizes the additional risk factors for this firm launching a..
How humane is capital punishment : Would a death sentence in John's case result in specific or general deterrence? To other officers? To the community in general? To other criminals? How does the data measure up to the myths and misconceptions generally held about capital punishmen..
Devise a marketing strategy to launch : Develop a new product and devise a marketing strategy to launch the product into the market place. Has to be in Power Point presentation. This is the name of our product COMPAL FRESH JUICE.
What are the probable consequences of the given behavior : What are the probable consequences of this behavior for investors analyzing the current year financial statements?
Implement 1-parameter date constructor that receives string : Date objects should store the date in two int instance variables: day and month, and it should include the String instance variable, error, initialized with null.
Information on the competitive environment : What demographic and geographic information should Eddie Bauer collect to select store locations? What information on the competitive environment should Eddie Bauer collect?
Gathering or using marketing intelligence : Your task is to explain how the situation in the article relates to a topic in this course. For example, an article might discuss how a company is gathering or using marketing intelligence.
How would the contract be reflected in the balance sheets : If Ms. McGonigle's proposal is adopted, how would the contract be reflected in the balance sheets at the end of 2008 and at the end of 2009?
Determine the diameter of a solid steel shaft : The design specification for a transmission shaft states that the angle of twist must be no more than 1° over a length 20 times the diameter. Using this specification determine the diameter of a solid steel shaft to transmit 150 kW at a speed of 3..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Implement a class called reversewords

Implement a class called ReverseWords that uses a stack to output a set of elements input by the user in reverse order.

  Create the investment calculator

Create the following GUI that allows a user to calculate the value of an investment after a certain number of years with monthly compound interest.

  Includes methods which format invoice details for printing

Constructor for the Invoice class requires subtotal and customer type only

  Understand actual communication with an smtp server

Understand actual communication with an SMTP server can be achieved using TCP Sockets and understand the development of a graphical user interface (GUI) and use of event handling.

  Write a program that prompts the user to enter an integer

Using && and || write a program that prompts the user to enter an integer and determine whether it is: Evenly divisible by 5 AND 6.

  Assessment taskyour task is to develop a java application

assessment taskyour task is to develop a java application that allows the user to read travel booking data from a text

  Prepare an overloaded constructor

Prepare an overloaded constructor that provides values for each field. Also provide get methods for each field. Save the file as Patient.java.

  Use of java api to perform interactive i/o in java

To gain experience designing and writing your own Java Program, To use of Java APIs to perform interactive I/O in Java programming, To declare variables and constants appropriately

  Explain the importance of access modifiers

Which access modifier (public, private, protected, default) would you use on a data field in the following cases?

  Create an application that keeps tracks of the information

Create an application that keeps tracks of the information in such a simple social network. More specifically, your application will allow for user profiles to be added to, deleted from, or looked-up in the social network.

  Implement/update specific methods for the dfs of a graph

implement/update specific methods for the DFS of a graph; for at least 2 graphs (1 being the provided one), show the DFS order of vertices in the graph, and for each node,

  Describe the equivalence classes

Prove that these relations on the set of all functions from Z to Z are equivalence relations. Describe the equivalence classes.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd