1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gekata [30.6K]
3 years ago
14

LAB: Praising dates

Computers and Technology
1 answer:
blsea [12.9K]3 years ago
4 0

Answer:

Explanation:

The following is the entire modified code, it takes in the date as an input and continues changing the dates to the desired format. If the input format is wrong it says "Wrong Format" and requests another input. If -1 is passed as an input the program terminates.

        import java.util.Scanner;

        class DateParser {

public static int getMonthAsInt(String monthString) {

        int monthInt;

        switch (monthString) {

            case "January" :

                monthInt = 1;

                break;

            case "February":

                monthInt = 2;

                break;

            case "March":

                monthInt = 3;

                break;

            case "April":

                monthInt = 4;

                break;

            case "May":

                monthInt = 5;

                break;

            case "June":

                monthInt = 6;

                break;

            case "July":

                monthInt = 7;

                break;

            case "August":

                monthInt = 8;

                break;

            case "September":

                monthInt = 9;

                break;

            case "October":

                monthInt = 10;

                break;

            case "November":

                monthInt = 11;

                break;

            case "December":

                monthInt = 12;

                break;

            default:

                monthInt = 0;

                }

        return monthInt;

       }

        public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

               // TODO: Read dates from input, parse the dates to find the one

        // in the correct format, and output in m/d/yyyy format  

 

                String date = "";

                while (!date.equals("-1")) {

                    String month = "";

                    String day = "";

                    String year = "";

                    System.out.println("Enter date:");

                    date = scnr.nextLine();

                    try {

                        year = date.substring((date.length()-4), date.length());

                        if (Character.isDigit(date.charAt(date.length()-8))) {

                            day = date.substring((date.length()-8), date.length()-6);

                            month = date.substring(0, date.length()-9);

                        } else {

                            day = date.substring((date.length()-7), date.length()-6);

                            month = date.substring(0, date.length()-8);

                        }

                        if ((year.length() == 4) && (day.length() > 0) && (day.length() <= 2) && (month.length() >= 3)) {

                            System.out.println(getMonthAsInt(month) + "/" + day + "/" + year);

                        } else {

                            System.out.println("Wrong Format");

                        }

                    } catch (Exception e) {

                        System.out.println("Wrong Format");

                    }

                }    

        }

}

You might be interested in
In two to three sentences, describe how the first Mac OS was different from the operating systems used by most early PCs.
Paha777 [63]

Answer:

DOS: Disk Operating System. DOS was the computer operating system used in the early days of computing and was extended to PC-DOS by Bill Gates when Microsoft was asked by IBM to develop an operating system for the IBM personal computers.

Microsoft Windows. Microsoft Windows is likely the most well-known and common computer operating system in the world today.

8 0
3 years ago
Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed __________.
Vaselesa [24]

Answer:

By reference ; by value

Explanation:

An array is defined as the arrangement of a certain item in a well orderly manner/ fashion.

Unless otherwise specified, entire arrays are usually passed by reference and individual array elements are passed by value which is the standard norm in the mode of operations.

7 0
3 years ago
Files containing ____ are available from a variety of sources.
leonid [27]
Hello <span>Charlesreid9517 
</span><span>

Answer: Files containing graphics are available from a variety of sources


Hope This Helps
-Chris</span>
4 0
4 years ago
Read 2 more answers
__________ helps organisms transport nutrients
alina1380 [7]
<span>Soil helps organisms to transport nutrients because the soil has various rich particles so that it helps plants to grow well.If any tree or plant wants to grow well means the soil should have rich content of particles.Soil will absorb rain water and helps to transport the nutrients to organisms.Only rich and healthy soil will reduce the natural disaster.</span>
4 0
3 years ago
24. Describe the role of keyboard and mouse in computer? What are the fundamental similarity and differences between them? ​
jasenka [17]

Answer: They give input

Explanation: The keyboard and the mouse controll the computer, by giving inputs. Similarity - They both give inputs

Difference - They give inputs in different ways

6 0
3 years ago
Other questions:
  • Which of the following is a true statement about psychological tests administered by computers? computers make standardization e
    9·1 answer
  • Which of these might be an example of an advertiser's target group?
    6·2 answers
  • Although you can use a dialog box to indent paragraphs, word provides a quicker way through the ____.
    7·1 answer
  • Consider the following C++ program in which the statements are in the incorrect order. Rearrange the statements so that itprompt
    6·1 answer
  • Jason is working on a project that requires him to manage a huge amount of data. The spreadsheet he is working on has data relat
    10·1 answer
  • Energía de movimiento de los átomos o moléculas
    11·1 answer
  • ¿como la imagen organiza la realidad?
    13·1 answer
  • Computer science - algorithms - flowcharts
    11·1 answer
  • Which of the following is not a method for opening Word software?
    14·2 answers
  • You are the Emergency Management Director of a small island nation. Your nation has come under Cyber-attack and the attackers ha
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!