Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 2 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 22 Sep 2017 My Price 9.00

string from the keyboard

Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. 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 month. September, April, June, and November each have 30 days. February has 28 days except for 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 is also divisible by 400. Input Notes: The input is a string of the form mm/dd/yyyy on a line by itself. Output Notes (Prompts and Labels): The input is prompted for by "Please enter a date to be checked". After that, the program prints a line consisting of "Your date was mm/dd/yyyy" (displaying the input that was entered). Following that, the program either prints: It is a valid date. or It is not a valid date. If it prints the latter, it prints an additional line: The reason it is invalid: REASON where REASON can be any one of the following: "The day value is less than one. "The day value is greater than 29 in February in a leap year. "The day value is greater than 28 in February in a non leap year. "The day value is greater than 30 in a month with just 30 days. "The day value is greater than 31 in a month with just 31 days. "The month value is not from 1 to 12. Note: if there are multiple errors in the date, priority is given to the "invalid day value" reason. SPECIFICATION OF NAMES: Your application class should be called CheckDate PROVIDED STARTER CODE import java.util.Scanner; public class CheckDate { /** * param args the command line arguments */ public static void main(String[] args) { System.out.println("Please enter a date to be checked"); Scanner reader = new Scanner(System.in); String date = reader.next(); int breakIndex = date.indexOf("/"); String monthString = date.substring(0, breakIndex); int month = Integer.parseInt(monthString); String rest = date.substring(breakIndex+1); breakIndex = rest.indexOf("/"); String dayString = rest.substring(0, breakIndex); String yearString = rest.substring(breakIndex+1); int day = Integer.parseInt(dayString); int year = Integer.parseInt(yearString); boolean validDate = true; String message = ""; if(day<1) { validDate = false; message = "The day value is less than one."; } switch(month){ /* * Here is where you need to put your cases in order to check * the days of the month that was entered. */ } break; default: validDate = false; message = message + "The month value is not from 1 to 12."; } /* * Here is where you will need to put an if statement to output * the resulting output of your program. */ } } import java.util.Scanner; public class CheckDate { public static void main(String[] args) { System.out.println("Please enter a date to be checked"); Scanner reader = new Scanner(System.in); String date = reader.next(); int breakIndex = date.indexOf("/"); String monthString = date.substring(0, breakIndex);

Answers

(5)
Status NEW Posted 22 Sep 2017 08:09 PM My Price 9.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)