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
This question allows you to practice proving a language is non-regular via the Pumping Lemma. Using the Pumping Lemma (Theorem 1
Ulleksa [173]

Answer:

<em>L is not a regular language with formal proofs  </em>

Explanation:

<em>(a) To prove that L is not a regular language, we will use a proof by contradiction. the assumption entails  that L is a regular language. Then by the Pumping Lemma for Regular Languages, </em>

<em>there exists a pumping length p for L such that for any string s ∈ L where |s| ≥ p, </em>

<em>s = xyz subject to the following conditions: </em>

<em>(a) |y| > 0 </em>

<em>(b) |xy| ≤ p, and </em>

<em>(c) ∀i > 0, xyi </em>

<em>z ∈ L</em>

<em />

<em>(b) To determine that L is not a regular language, we mke use of proof by contradiction.  lets assume, that L is regular. Then by the Pumping Lemma for Regular Languages, it states also,</em>

<em>The pumping length, p for L such that for any string s ∈ L where |s| ≥ p, s = xyz subject  to the condtions as follows : </em>

<em>(a) |y| > 0 </em>

<em>(b) |xy| ≤ p, and </em>

<em>(c) ∀i > 0, xyi </em>

<em>z ∈ L. </em>

<em>Choose s = 0p10p </em>

<em>. Clearly, |s| ≥ p and s ∈ L. By condition (b) above, it follows is shown. by the first condition x and y are zeros.</em>

<em>for some  k > 0. Per (c), we can take i = 0 and the resulting string will still be in L. Thus,  xy0 </em>

<em>z should be in L. xy0 </em>

<em>z = xz = 0(p−k)10p </em>

<em>It is shown that is is  not in L. This is a  contraption with the pumping lemma.  our assumption that L is regular is  incorrect, and L is not a regular language</em>

6 0
3 years ago
The privilege of driving comes with
julsineya [31]
The privilege of driving comes with responsibility
5 0
2 years ago
A slender rod AB, of weight W, is attached to blocks A and B, which move freely in the guides shown. The blocks are connected by
gregori [183]

Answer:

(a) T = W/2(1-tanθ)  (b) 39.81°

Explanation:

(a) The equation for tension (T) can be derived by considering the summation of moment in the clockwise direction. Thus:

Summation of moment in clockwise direction is equivalent to zero. Therefore,

T*l*(sinθ) + W*(l/2)*cosθ - T*l*cosθ = 0

T*l*(cosθ - sinθ) = W*(l/2)*cosθ

T = W*cosθ/2(cosθ - sinθ)

Dividing both the numerator and denominator by cosθ, we have:

T = [W*cosθ/cosθ]/2[(cosθ - sinθ)/cosθ] = W/2(1-tanθ)

(b) If T = 3W, then:

3W = W/2(1-tanθ),

Further simplification and rearrangement lead to:

1 - tanθ = 1/6

tanθ = 1 - (1/6) = 5/6

θ = tan^(-1) 5/6 = 39.81°

8 0
3 years ago
Which type of inappropriate practice most likely occurred if a researcher takes credit for someone else’s idea and does not ackn
Rashid [163]

Answer: the answer is plagiarism.

Explanation: Plagiarism is the act of taking credit from someone else's works or ideas, without acknowledging the author. <u>Conflict of interest</u> occurs when an employee has <u>interests that are at odds to each other</u>, which isn't shown at the excerpt given in the exercise. <u>Fabrication</u> is the <u>creation of intellectual property</u>, also not shown in the exercise, and <u>falsification</u> is the <u>creation of a scientific hypothesis</u> that <u>cannot be verified</u> by lack of practical evidence, which is not the case described as well.

7 0
3 years ago
What types of issues MAY occur to slow or prevent the best outcome?
german

Answer:

im sorry but i cant find any studies about this and im 3 days late

4 0
3 years ago
Other questions:
  • Which type of door consists of thin pieces of wood, glass, or louvers placed within a framed rectangular area?
    7·2 answers
  • Which sentence about the technology design process is true
    12·1 answer
  • How do I calculate the gear ratio​
    6·1 answer
  • You're running an engine and seeing that it is exhausting blue smoke. Which is likely to
    9·1 answer
  • Complete the following sentence. The skills and content of several subject areas were combined to form a new field known as a me
    12·2 answers
  • WHAT IS THE MOST POWERFUL PART IN A CAR
    13·2 answers
  • Certain pieces made by an acoustic lathe are subject to three kinds of defects X,Y,Z. A sample of 100 pieces was inspected with
    6·1 answer
  • 4 points
    13·1 answer
  • What building codes did Mega Corporation fail to follow?
    9·1 answer
  • A continuous function y = ƒ(x) is known to be negative at x = 0 and positive at x = 1. Why does the equation ƒ(x) = 0 have at le
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!