Question

public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner...

public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Enter a date in the format month/day/year");
       String date = keyboard.nextLine();
       //Make a copy
       String dateCopy = date;
      
       //Extract the values
       //start with month
       //indexOf() is used to find the index of a specified character in a givenString
       int workingIndex = date.indexOf("/");
      
       //substring(int beginIndex, int endIndex)
       //return strings substring
       String sM = date.substring(0,workingIndex);
       //convert string to integer
       int m = Integer.parseInt(sM);
      
       //move to day
       date = date.substring(workingIndex+1);
       workingIndex = date.indexOf("/");
       String sD = date.substring(0,workingIndex);
       int d = Integer.parseInt(sD);
      
       //move to year
       date = date.substring(workingIndex+1);
       int year = Integer.parseInt(date);
      
       //check the valid date
       //a valid month must be from 1 to 12
       if(m<1 || m>12)
       {
           System.out.println(dateCopy + "is invalid! The month must be between 1 and 12.");
       }
       //Leap year
       //February has 28 days except on leap years (29).
       else if (m==2)
       {
           if(d == 29)
       {
               //Leap years are years that are divisible by 4.
               //but not divisible by 100 unless also divisible by 400.
              
               if(!(year%4==0 && (year%100!=0 || year%400 == 0)))
               {
                   System.out.println(dateCopy + " is invalid! The date given is not a leap year.");
               }
               else
               {
                   System.out.println(dateCopy + " is a valid date!");
               }
           }//Normal year
           else if (d<1 || d>28)
           {
               System.out.println(dateCopy + " is invalid! The day is wrong for this month. Must be between 1 and 28.");
           }
           else
           {
               System.out.println(dateCopy + " is a valid date!");
           }
       }
       //April, June, September, and November have 30 days
       else if(m==4 && (d<1 || d>30) || m==6 && (d<1 || d>30) || m==9 && (d<1 || d>30) || m==11 && (d<1 || d>30))
       {
           System.out.println(dateCopy + " is invalid! The day is wrong for this month. Must be between 1 and 30.");
       }
       else if((m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) && (d<1 || d>31))
       {
           System.out.println(dateCopy + " is invalid! The day is wrong for this month. Must be between 1 and 31.");
       }
       else
       {
           System.out.println(" is a valid date!");
       }
       }
   }

Looking for the flowchart for this code. It determines the validity of a user inputted birth date entered in the format in the code.

Homework Answers

Answer #1

The Flowchart is very big.

Please find all the conditions slowly.

I have made it easy for you to understand.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
/* Program Name: BadDate.java Function: This program determines if a date entered by the user is...
/* Program Name: BadDate.java Function: This program determines if a date entered by the user is valid. Input: Interactive Output: Valid date is printed or user is alerted that an invalid date was entered. */ import java.util.Scanner; public class BadDate { public static void main(String args[]) { // Declare variables Scanner userInput = new Scanner (System.in); String yearString; String monthString; String dayString; int year; int month; int day; boolean validDate = true; final int MIN_YEAR = 0, MIN_MONTH = 1,...
import java.util.Scanner; public class AroundTheClock {    public static void main(String[] args)    {       ...
import java.util.Scanner; public class AroundTheClock {    public static void main(String[] args)    {        Scanner input = new Scanner(System.in);        int departureTime = input.nextInt();        int travelTime = input.nextInt();        int arrivalTime;            departureTime =12;            departureTime = 0;            arrivalTime = (int) (departureTime + travelTime);            (arrivalTime = (arrivalTime >=12));            if (arrivalTime = arrivalTime %12)            {            System.out.println(arrivalTime);...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
import java.util.Scanner; import java.util.Random; public class DiceRoll {    public static final int SIDES = 6;...
import java.util.Scanner; import java.util.Random; public class DiceRoll {    public static final int SIDES = 6;    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Enter the number of times a 6 sided die should be rolled ");        Scanner keyboard = new Scanner(System.in);        Random r = new Random();               int times = keyboard.nextInt();        boolean valid = false;        while(!valid) {           ...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { //...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { // Scanner class object declare Scanner readStudentFile = null; // try block begin /*System.out.println("Working Directory = " + System.getProperty("user.dir")); // for debugging purposes only*/ try { // open file readStudentFile = new Scanner(new File("student.txt")); // loop until end of file while (readStudentFile.hasNextLine()) { String stu = readStudentFile.nextLine(); String[] eachStu; eachStu = stu.split(" "); String firstName = null, middleName = null, lastName = null; long id...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4,...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4, 5, 1}, {3,6,1,2}, {1,3,6,5}; Answer : 1- All values ​​of array2D are automatically 0 ? Yes or No 2- What is the value of array2D [3] .length ?________ 3-  The value that array2D.length shows is 12: Yes or No ? 4- Assign the value of 12 to the element in the third row, fourth column : 5- the value obtained when calculating array2D [1] [1]...
using System; public static class Lab5 { public static void Main() { // declare variables int...
using System; public static class Lab5 { public static void Main() { // declare variables int inpMark; string lastName; char grade = ' '; // enter the student's last name Console.Write("Enter the last name of the student => "); lastName = Console.ReadLine(); // enter (and validate) the mark do { Console.Write("Enter a mark between 0 and 100 => "); inpMark = Convert.ToInt32(Console.ReadLine()); } while (inpMark < 0 || inpMark > 100); // Use the method to convert the mark into...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT