so i have this homework and this is the given problem:
Per-minute charging offers at 75 cents a minute from 5:01 am to 5:00 pm, and 90 cents a minute from 5:01 pm to 5:00 am.
this is my code:
double charge = 0;
Date date = new Date();
if(date.getHours() >= 5 && date.getHours() <= 17)
{
charge += 0.75 * date.getMinutes();
System.out.println(charge);
}
else
{
charge += 0.9 * date.getMinutes();
System.out.println(charge);
}
my problem is that the date.getMinutes() only gets the current minute of the current hours,
it supposed to be the number of minutes from 5:01am up to the current time and the else statement likewise. any idea guys? thx alot!
Well, for this you can do
Similarly, you could write it for the other part.
As it has been pointed out that the above methods have been deprecated, here is how you can do it with the
Calendar