CSC 15 Lab 3, Chaper 3 Write a complete program that generates the exact followi
ID: 3586728 • Letter: C
Question
CSC 15 Lab 3, Chaper 3 Write a complete program that generates the exact following output. In this program you need to prompt the user the number of hours, minutes and seconds and then output the equivalent amount in minutes and seconds and hours. Please refer to the shell provided for you for more details. Requirements: I. Must Main method can only have two lines of code. Proper indentation Proper naming Comments Logic provide the exact same o utput word by word 2. 3. 4. 5, 6. At the top of your program include the following info as comments: First name, last name Description of the program Date you created the program This program converts hours, minutes, second to second and display in on the screen. How many times do you want to use the app? 2 What is your name? Alex Patten Hi Alex Patten Lets start!! Enter the number of the hours:3 Enter the number of the minutes: 5 Enter the number of the seconds: 360 3 Hours, 5 Minutes, and 360 Seconds is: 11460 seconds 191 Minutes 0 Scoonds 3 Hours and1 Minutes and 0 Seconds What is your name? Mary Lee Hi Mary Lee Lets start!! Enter the number of the hours:5 Enter the number of the minutes: 128 Enter the number of the seconds: 728 S Hours, 128 Minutes, and 728 Seconds is: 26408 scconds 440 Minutes 8 SeoondsExplanation / Answer
I am wrting logic inside described functions in the above code .I think it will be help ful to you.
Please find code below:
import java.util.Scanner;
public class TimeShell
{
//declare all your constants
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
start(kb);
}
/* call the method description
prompt the user for the name and the number of the times that they want to use this program
get the hours, minutes, seconds
call the method hoursToSec
call the method minToSec
calculate the total seconds
output the total seconds
call the method minSec to calulate the minutes and sec
call the method hourMinSec*/
public static void start(Scanner kb)
{
System.out.print("Enter a number:either totSec,min or hours ");
// nextInt() reads the next integer from the keyboard
int number = kb.nextInt(); //this number can be tot secs,mins,hours as required for input to underlined function.
}
/*This method get the totlal number of the seconds and finds the number of the minutes and sec and outputs the result*/
public static void minSec(int totalSeconds)
{
int totmins=(totalSeconds/60);
int totsecs=(totalSeconds%60);
System.out.print(totmins + " " + totsecs);
}
/*This method get the total number of the seconds and calculates the number of hours, minutes and second, then outputs the result*/
public static void hourMinSec(int totalSeconds)
{
int tothrs=(totalSeconds/3600);
int totmins=(totalSeconds%3600)/60;
int totsecs=(totalSeconds%60);
System.out.print(tothrs + " " + totmins + " " + totsecs);
}
/*calulates the number of the seconds in the given hours and returns the value*/
public static int hourToSec(int hours)
{
int seconds=(hours*3600);
return seconds;
}
/*This method calculates the number of the seconds in the given number of minutes*/
public static int minToSec(int min)
{
int seconds=(min*60);
return seconds;
}
/*outputs the description of the program*/
public static void description()
{
System.out.print("This program is used to cal total hrs,mins and seconds with given input as either totSec,min or hours ");
}
}
Thanks !!