Question

In: Computer Science

write this program in java... don't forget to put comments. You are writing code for a...

write this program in java... don't forget to put comments.

You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later.

For example, if the user enters 9:21 the method should output
9:46

and if the user enters 10:52 the method should output
11:17

and if the user enters 12:45 the method should output
1:10

Solutions

Expert Solution

import java.util.*;

public class Main
{
//method to calcuate the meeting end time
public static void meetingTime(String startTime)
{
//variable declaration and initialization
int hh=0, mm=0;
  
//check the hours is single digit or two digit
       if(startTime.charAt(1) == ':')
       {
       hh = Integer.parseInt(startTime.substring(0,1));
       mm = Integer.parseInt(startTime.substring(2,4));
       }
       else
       {
       hh = Integer.parseInt(startTime.substring(0,2));
       mm = Integer.parseInt(startTime.substring(3,5));
       }
      
       //calculate minutes
       mm = mm + 25;
       if(mm>59)
       {
       mm = mm % 60;
       hh++;
       }
      
       //check if hh is greater than 12
       if(hh>12)
       hh = hh % 12;
      
       //display the end time
       System.out.println("The end time of meeting is: "+hh+":"+mm);
}

   public static void main(String[] args)
   {
   //Scanner
   Scanner input = new Scanner(System.in);
  
   //get user input
       System.out.print("Enter the meeting start time: ");
       String startTime = input.nextLine();
  
//method calling
meetingTime(startTime);
   }
}

OUTPUT:

RUN 1:

Enter the meeting start time: 9:21
The end time of meeting is: 9:46

RUN 2:

Enter the meeting start time: 10:52
The end time of meeting is: 11:17


RUN 3:

Enter the meeting start time: 12:45
The end time of meeting is: 1:10




Related Solutions

Write this code in java and don't forget to comment every step. Write a method which...
Write this code in java and don't forget to comment every step. Write a method which asks a baker how hot their water is, and prints out whether it is OK to make bread with the water. If the water is at or above 110F, your method should print "Too Warm." If the water is below 90.5F, print "Too Cold." If it is in between, print "Just right to bake!" For example, if the user inputs the number 100.5, the...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.
This is a python program. Put comments explaining the code, please. Suppose you have been tasked...
This is a python program. Put comments explaining the code, please. Suppose you have been tasked with writing a Python program (using linked lists) to keep track of computer equipment. For each piece of equipment, we track its name, purchase date, purchase amount, and quantity on hand. Write a program that completes the following tasks: allow the user to add a piece of equipment to the front of the list; allow the user to update the quantity of a piece...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Create an array-based implementation of a binary tree. (WRITE IN JAVA) DON'T FORGET TO INCLUDE PSEUDOCODE...
Create an array-based implementation of a binary tree. (WRITE IN JAVA) DON'T FORGET TO INCLUDE PSEUDOCODE AND UML DIAGRAM
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT