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
goblinko [34]
3 years ago
9

Complete the following method that takes a String parameter that is a time in American 12 hour format, such as "06:12 PM." The m

ethod returns a String with the same time in standard international 24 hour form. For example, given the parameter in the example above, the method would return "18:12." Values with AM correspond to times from 00:00 to 11:59 and PM for times from 12:00 to 23:59. Recall the method Integer.parseInt() takes a String parameter and returns the integer equivalent. And then simply I am supposed to create a method like so... public static String convertTime(String amerFormat) { }
Engineering
1 answer:
goldfiish [28.3K]3 years ago
8 0

Answer:

public class AmericanTimeFormatting {

  public static String convertTime(String amerFormat)

  {

   

      if(amerFormat.length()<8) {

          System.out.println("Length of the input string should be 8");

          return null;

      }

   

      else if(!Character.isDigit(amerFormat.charAt(0)) && !Character.isDigit(amerFormat.charAt(1)) && !Character.isDigit(amerFormat.charAt(3)) && Character.isDigit(amerFormat.charAt(4))) {

          System.out.println("Digit is requird");

          return null;

      }

 

      else if(amerFormat.charAt(2)!=':'|| amerFormat.charAt(7)!='.') {

          System.out.println("Punctuation required");

          return null;

      }

      //Am or Pm specification check

      else if(!amerFormat.substring(5,7).equals("PM") && !amerFormat.substring(5,7).equals("AM")){

          System.out.println("Required PM or AM");

          return null;

      }

      else {

          //For PM

          if(amerFormat.substring(5,7).equals("PM")) {

              String time="";

              int hour=Integer.parseInt(amerFormat.substring(0,2));

              hour=24-(12-hour);

              time+=String.valueOf(hour)+":";

              int minute=Integer.parseInt(amerFormat.substring(3,5));

              time+=minute;

              return time;

          }

          //For AM

          else {

              return amerFormat.substring(0,5);

          }

         

      }

  }

  public static void main(String[] args) {

 

      String time=convertTime("06:12PM.");

   

      if(!time.equals(null)) {

          System.out.println("Time is "+time);

      }

  }

}

You might be interested in
Select the correct statement(s) regarding IEEE 802.16 WiMAX BWA. a. WiMAX BWA describes both 4G Mobile WiMAX and fixed WiMax b.
Gala2k [10]

Answer:

d. all of the statements are correct.

Explanation:

WiMAX Broadband Wireless Access has the capacity to provide service up to 50 km for fixed stations. It has capacity of up to 15 km for mobile stations. WiMAX BWA describes both of 4G mobile WiMAX and fixed stations WiMAX. OFMD is used to increase spectral efficiency of WiMAX and to improve noise performance.

5 0
3 years ago
Starting with the column in Problem 1, perform enough additional calculations to determine the effects of increasing fc from 500
Hoochie [10]

Answer:

Explanation:

Find attached the solution to the question

5 0
3 years ago
WHICH ONE DO YOU LIKE *CREDIT 2 sbrianna3606*
RSB [31]

Answer:

first one, rest are okay ig.....

Explanation:

6 0
3 years ago
Why would a robot process something faster than a human
pantera1 [17]
A robot is a machine. It is often, or almost always, automatic, which means that it is able to perform activities on its own without the aid of external variables, like humans. It moves in the way that it was originally programmed, or designed to act. These actions are described as 'intents' of its own.
8 0
3 years ago
Read 2 more answers
If OSHA determines that an employer's response to a non-formal complaint is adequate, what options does the employee filing the
Anuta_ua [19.1K]
Fill it out without telling ur employer as that may cause backlash and have an osha certified employee come check out ur work or job site
4 0
3 years ago
Other questions:
  • A sheet of steel 4.4 mm thick has nitrogen atmospheres on both sides at 1200°C and is permitted to achieve a steady-state diffus
    10·1 answer
  • Water at 20 °C is flowing with velocity of 0.5 m/s between two parallel flat plates placed 1 cm apart. Determine the distances f
    5·1 answer
  • 8.19 - Airline Reservations System (Project Name: Airline) - A small airline has just purchased a computer for its new automated
    7·1 answer
  • Part of the basic procedures is the vehicle check. What does that mean?
    7·1 answer
  • What is a build enviroment in construction
    8·1 answer
  • What is the advantage of Sensabot over human inspectors?
    12·1 answer
  • Select the correct answer.
    15·2 answers
  • You can safely place a jack on a floor pan to keep a vehicle steady.
    5·2 answers
  • What does the supply chain management process involve
    6·1 answer
  • A linear frequency-modulated signal makes a good test for aliasing, because the frequency moves over a range. This signal is
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!