Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the time of day in terms of an hour, minute, second and day half (i.e., AM or PM), write a static Java method named

Given the time of day in terms of an hour, minute, second and day half (i.e., AM or PM), write a static Java method named fractionOfDay to calculate and return the fraction of the day (a value of type double) that has elapsed since midnight (12:00 AM). For example,

fractionOfDay ( 12, 0, 0, 'A'); 

would print 0.0

fractionOfDay ( 12, 0, 0, 'P');

would print 0.5

fractionOfDay ( 11, 59, 59, 'P');

would print 0.999988426

and so on...

why does this not work?:

public class practice {

public static void main(String[] args) { hour (3, 0, 0, 'A'); }

public static void fractionOfDay (int hour, int minute, int second, char half) { if (hour ==12 && minute ==0 && second==0 && half == 'A') { System.out.println (0.0); } else if (half == 'A') { System.out.println ((double) (hour/24 + minute/1440 + second/86400)); } else if (half == 'P') { System.out.println (0.5+ hour/24 + minute/1440 + second/86400); } else if (hour ==12 && minute ==0 && second==0 && half == 'P') { System.out.println (0.5); }

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions