Create a class named date that stores date values

Assignment Help JAVA Programming
Reference no: EM13820444

Create a class named Date that stores date values and prints out the date in either a pure numeric format or a name and number format (see sample session for format details).

Date class notes:

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

In your 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

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.

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: EM13820444

Questions Cloud

Grade book program : Grade Book Program
Project manager managing projects : Identify two key challenges project managers must address in public sector infrastructure projects and discuss how these challenges are similar to and different from those experienced by a project manager managing projects within a corporate envir..
Unix programming : UNIX Programming
Supply of cashews and the price of cashews : In the long run, what will happen to the supply of cashews and the price of cashews?
Create a class named date that stores date values : Create a class named Date that stores date values
Calculate the mass fraction of sulfuric acid : Two aqueous sulfuric acid solutions containing 20.0 wt% H2SO4 (SG = 1.139) and 60.0 wt% H2SO4 (SG = 1.498) are mixed to form a 4.00 molar solution (SG = 1.213). Calculate the mass fraction of sulfuric acid in the product solution.
Find the probability of the number of women : A random sample of 13 adult women is selected. Use the binomial probabilities table or technology to find the probability of the number of women in this sample of 13 who had tried 5 or more diets in their lifetime is
Frequent shopper program : Frequent Shopper Program
Triple constraint-cost/revenue-schedule and scope-quality : Form a two-person groups and select a topic on which you are “experts” (such as choosing a class) and you are challenged to develop a consensus knowledge base and inference rules. What model did you use to arrive at your decision?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Writing a java program that provides simple statistics

You will be writing a Java program that provides simple statistics about the input data. The method stubs are given below. This assignment will give you experience with methods

  Translates a number into the closest letter grade

Write a program that translates a number into the closest letter grade. For case, the number 2.8 which might have been the average of several grades would be converted to B-

  Explain the graphical coordinate system in java where is

question 1 describe the graphical coordinate system in java. where is the origin? what units apply to the xy

  Java enumeration lettergrade represent letter grades

Write a java enumeration LetterGrade that represents letter grades A through F, including plus and minus grades. Define a private instance variable holding a boolean value.

  Write java program to store employee id number

Use employee data file called employees.txt should comprise at least 5 employee records. Each record stores employee ID number (six digits) last name, first name, middle inital,gender(m or f).

  Demonstrates conditions under which the compareto() method

Write an application that demonstrates conditions under which the compareTo() method retrun a positive number, a negative number, and a zero when used to compare two Strings, Save the file as CompareStringValues.java. Lab Assignment

  How events and graphical user interfaces are related

Describe what an event is and how events and Graphical User Interfaces (GUI) are related

  Implemented a distributed rental car management system

You implemented a distributed rental car management system using Java TCP Sockets and object streams. The goal of this project is to use code from your TCP project and create a new implementation of the rental car management system using Java RMI

  Calculate monthly commissions for n salespersons

Understanding of arrays - arrayLists, objects, classes, sorting and searching. Develop a java application program for such a scenario that a local department store manager wants to use it for calculating monthly commissions for N salespersons.

  Program that allows users to enter a dollar amount

Write a program that allows users to enter a dollar amount for their bank account balance at the beginning of the month. Then ask the user to enter a dollar amount for any number of checks written in a month, up to 50.

  Write a test application name employeetest

Create two Employee objects and display each objects yearly salary. Then give each employee a 10% raise and display each employee's yearly salary again.

  Create a new project in your ide named animalinfo

Create a new project in your IDE named "AnimalInfo." Create a class called "AnimalInfo" as the main class for the program.

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