[Solved] Lab 3: Date Format

$25

File Name: Lab_3:_Date_Format.zip
File Size: 169.56 KB

SKU: [Solved] Lab 3: Date Format Category: Tag:
5/5 - (1 vote)

Lab 3: Date FormatWrite a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and message that indicates whether it is valid. If it is not valid, also display a message explaining why it is notvalid.The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). the day value dd must be from 1 to a value that is appropriate for the given moth. September, April, June,and November each have 30 days. February has 28 days except for the leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it isalso divisible by 400.2 HintsTo complete this assignment, you will need to utilize some methods not used in class. Start by reading in the users input using Scanners nextLine()method.2.1 SubstringNext we have to get the individual numbers out of the string. First to geta small portion of the string, use the substring(start, end) method.Here is an example:String s = My name;String s2 = s.substring(0,2); // holds the value myString s3 = s.substring(3,6); // holds the value namString s4 = s.substring(3); // holds the value nameString space = s.substring(2,3); // holds the value

substring() returns a new string having the same characters as the portion of the original that starts a index start and up to, but not including end. Indices in Java start at 0, so the rst character is at index 0, the secondat index 1, and so on. If no end is speci ed, the substring goes until the end of the String2.2 Converting Strings to IntegersInteger.parseInt(someString) converts a string into an int.String s = 123;int i = Integer.parseInt(s); //stores 123Use the above information to get integer values for the month, date, andyear. The rest of the program is logic!

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Lab 3: Date Format
$25