Question
Asked Feb 10, 2020
10 views

Not allowed to use decisions or loops, if then statements, I haven't learned that. I have to use division and modulus.

PART D. Write a program HourConverter which asks the user to enter a number of hours and outputs the
equivalent duration in weeks+days+hours. (Hint: Use the division and mod operator.) Here are some examples:
Enter a number of hours:
7 hours is 0 weeks, 0 days, and 7 hours
help_outline

Image Transcriptionclose

PART D. Write a program HourConverter which asks the user to enter a number of hours and outputs the equivalent duration in weeks+days+hours. (Hint: Use the division and mod operator.) Here are some examples: Enter a number of hours: 7 hours is 0 weeks, 0 days, and 7 hours

fullscreen
check_circle

Expert Answer

Step 1

Since here no programming language is specified. So, we are providing the solution in Java.

The below given java program will obey the following rubrics:

  • Importing essential header files.
  • Defining main method in main class.
  • Creating instance of scanner class.
  • Displaying message to user to enter the number of hours.
  • Reading number of hours as input from user.
  • For obtaining the number of hours, by using modulus operator. Modulus operator stores the completely divisible number only and ignores the remainder part.
  • After that calculating the number of weeks by dividing the entered number of hours by 7 and storing the result in week variable.
  • Finally, calculating the number of days by using the modulus operator in between the entered number of hours and the weeks.
  • Displaying results to user.

 

Step 2

Program code:

 

//importing essential header files

import java.util.Scanner;

//main class

public class Main

{

//main method

public static void main(String[] args)

{

    //instantiating scanner class

Scanner in = new Scanner(System.in);

//dispalying message to user to enter the number of hours

System.out.print("Enter a number of hours: \n");

//reading inputs from user  

int hours = in.nextInt();

//storing number of hours

int h1 = hours % 24;

//storing number of ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What are patches and service packs?

A:  Patches: A patch is a small piece of software that is used to correct a problem in another software...

question_answer

Q: Design a class named Employee. The class should keep the following information infields:• Employee n...

A: Program:Filename: “Test.java”public class Test{   public static void main(String args[])   {    Prod...

question_answer

Q: Create a complex query based on two or more tables (SCHOOL, DEPARTMENT, PROFESSOR, TECHNOLOGY, COURS...

A: Query:SELECT A.SCHOOL_CODE FROM SCHOOL A, DEPARTMENT B WHERE A.DEPARTMENT_ID = (SELECT DEPARTMENT_ID...

question_answer

Q: Compiler Design: Lexical analysis   Given the regular expression ((a|b)(a|bb))∗ Construct an equival...

A: Lexical Analysis: Lexical analysis is used to convert a sequence of characters into the sequence of ...

question_answer

Q: Consider a schema  R={A,B,C,D,E} and the following set of functional dependencies: {AB-> C, C-&gt...

A: To find whether the relation is in BCNF or not, it must fulfill all the conditions given below-1)Rel...

question_answer

Q: Write one Python statement to store the names of five friends (you pick the names) in a list named p...

A: List in python: A list in python is a datatype that is heterogeneous in nature. That is the values o...

question_answer

Q: Python Coding-(On Pycharm Community Edition)   Create a mini-lottery with TEXT ticket.  The user i...

A: Program Instruction:First import the module of the random numbers.Then read the file ‘ticket.txt’ wi...

question_answer

Q: Please solve the below question asap using c++ basic logic and running it for a larger number of tes...

A: //include the required header files #include<iostream> #include<string> #include <cst...

question_answer

Q: Write one Python statement to print variable price in currency format (with commas for thousands).

A: Program:price = 78200000print("\nOriginal Number: ", price)print("Printing in currency format: "+"{:...