Ask Java Expert


Home >> Java

Computer Science - Java Programming - Writing a number converter

Surgeons have a very tough schedule throughout the day to deal with patients, perform surgeries, visit wards, and attend meetings among others. Assume a surgeon wants to take a nap during the day time, but, due to his schedule, he may not get many chances. He wants to take one nap with the longest break time. Write a program to help this surgeon find a suitable time for a nap. He also wants to know total free time that he has on that specific day.

To complete this Assignment:

Input

You need to take input of 3 parameters: time1, time2 and appointment description for all the appointments of day. The time1 represents the starting time of an appointment and the ending time is represented by time2. All times are specified in the form of hh:mm. The ending time of an appointment will always be after the starting time. The value of each attribute is separated by a single space. The appointment description is specified in the single quotes.The value in both of the times must be greater than or equal to 9:00 and less than or equal to 17:00. Therefore, you need to take the value into consideration i.e., nap cannot start before 9:00 and cannot last after 17:00.

Output

For each appointment, you need to do following. Assume start time of nap and maximum nap time are 00:00.1. Check if the difference between ending and starting time is greater than maximum nap time, then update the values of start time of nap with the value of starting time of current appointment and maximum nap time with the difference of time calculate for current appointment.2. Add this difference of time to the total free time of the day.

Once all the appointments are processed, you need to print the following:1. Schedule of the day: You can take a longest nap at hh:mm which will last for [H hours and] M minutes.2. The total free time available in the day is hh:mm where hh:mm is the time when the nap can start.

To display the length of the nap, follow these rules:If the total time X is less than 60 minutes, just print &"X minutes." If the total duration X is at least 60 minutes, print "Hhours and M minutes," where H = X ÷ 60 (integer division, of course) and M = X mod 60.

You don't have to worry about correct pluralization; i.e., you must print "1 minutes" or "1 hours" if that is the case.The duration of the nap is calculated by the difference between the ending time and the beginning time. That is, if anappointment ends at 14:00 and the next one starts at 14:47, then you have 14:47 - 14:00 = 47 minutes of possiblenapping.

If there is more than one longest nap with the same duration, print the earliest one. You can assume the physician won'tbe busy all day, so there is always time for at least one possible nap.

You can make the input simpler by asking user to specify one long string which contains the details of all theappointments of a single day using three parameters repeated in the format as “time1 time2 ‘appointmentdescription' time1 time2 ‘appointment description' ..." and then applying string processing to separate details. You canalso use an alternate approach by taking input of three parameters separately. The examples of both methods are shownbelow:

Sample Inputs and Outputs: Example #1: input is in the form of one long string:Enter details of all the appointments: 9:00 9:45 ‘Ward inspection' 10:00 11:30 ‘Patients' 12:00 13:00 ‘Lunch' 13:00 15:00‘Meeting' 16:30 17:00 ‘Reading'

Output: You can take longest nap at 15:00 and it will last for 1 hours and 30 minutes.Total free time during whole day is 2 hours and 15 minutes. Example #2: input is in the form of one long string:Enter details of all the appointments: 12:00 13:00 ‘Lunch invitation'Output:You can take longest nap at 13:00 and it will last for 4 hours and 0 minutes.Total free time during whole day is 7 hours and 0 minutes.

Example #3: Each parameter is taken as a separate input. You need to take confirmation from user if they want toadd an appointment for the day. If they confirms then ask details of an appointment, else, you will break thesequence of taking input and process all the appointments specified by the user.

Do you want to add an appointment? Yes Enter starting time: 9:00Enter ending time: 12:00Enter appointment description: ‘Patients'Do you want to add an appointment? YesEnter starting time: 12:00Enter ending time: 13:00Enter appointment description: ‘Lunch.'Do you want to add an appointment? YesEnter starting time: 13:00Enter ending time: 16:00Enter appointment description: ‘Operation theatre'Do you want to add an appointment? YesEnter starting time: 16:30Enter ending time: 17:00Enter appointment description: ‘Discussion'Do you want to add an appointment? No

Output: You can take longest nap at 16:00 and it will last for 30 minutes.Total free time during whole day is 30 minutes.

Note: You may need to look at substring() and indexOf() of String class to perform string processing in this programmingquestion. If you are facing difficulty to take input and process in the form of "hh:mm" then you take separate inputs forboth hours and minutes.

Java, Programming

  • Category:- Java
  • Reference No.:- M91914388
  • Price:- $60

Guranteed 36 Hours Delivery, In Price:- $60

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As