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
ANSWER QUICK
luda_lava [24]

Answer:

u will need good car parts and a very well made engine

Explanation:

u need a good engine because if u only work on the outer layer of the car the inner parts will be slow and old and the car will have problems

5 0
3 years ago
Who would need to be consulted when specifying the requirements of a project?
elena55 [62]

Answer:A technology expert

Explanation:

3 0
3 years ago
HELP PLEASE<br> this is for drivers ed btw
4vir4ik [10]

Answer:

b is the correct option

Explanation:

may it help u

4 0
3 years ago
Wqqwfqwfqwfqfqfqffqwffqwqfqqfqfqffqqfqfwccc
almond37 [142]

Answer:

?

Explanation:

4 0
4 years ago
Read 2 more answers
Ma poate ajuta cineva?
kari74 [83]
Da, sigur. cu ce ai nevoie de ajutor?
5 0
3 years ago
Other questions:
  • For laminar flow over a flat plate, the local heat transfer coefficient hx is known to vary as x−1/2, where x is the distance fr
    12·1 answer
  • Consider the combustion of ethanol C2H5OH with air. Assume the air is dry and comprised of 21% oxygen and 79% nitrogen on a mola
    15·1 answer
  • * Write a recursive function that finds the index of s2 in s1. Do not use any * string functions except for .length(), .equals()
    12·1 answer
  • 25 gallons of an incompressible liquid exert a force of 70 lbf at the earth’s surface. What force in lbf would 6 gallons of this
    12·1 answer
  • A hair dryer is basically a duct of constant diameter in which a few layers of electric resistors are placed. A small fan pulls
    7·1 answer
  • import java.util.Scanner; public class FindSpecialValue { public static void main (String [] args) { Scanner scnr = new Scanner(
    11·1 answer
  • Name three things you can find with a level in construction and explain why they are Important ​
    12·1 answer
  • Which option distinguishes the step in the engineering design phase described in the following scenario?
    8·1 answer
  • What are the laws that apply to one vehicle towing another?
    11·1 answer
  • If f(
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!