For Java programming. I am programming a service charge. I have two price: Day p
ID: 3788520 • Letter: F
Question
For Java programming.
I am programming a service charge.
I have two price: Day price < 17:00 hours and Evening price > 17:00 hours
Day price = $52.00 Evening price = $78.00
I have to input a time, and get output cost.
How do I calculate the output cost by entering the input time?
Example: Start time = 16:00 and End time =18:00 equals $130.00
double priceD = 52.00
double priceE = 78.00
int quantity;
if (time < 17:00 = 52.00)
else 78.00
total = (priceD * quantity)
total = (priceE * quantity)
total = (priceD + priceE)
???
Thank you.
Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class ServiceCharge
{ static double total;
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Start Time");
double startTime=sc.nextDouble();
System.out.println("Enter End Time");
double endTime=sc.nextDouble();
double priceD = 52.0;
double priceE = 78.0;
double quantity;
if((0.0 <= startTime)&& (startTime< 17.0) && (startTime <= endTime)&& (endTime< 17.0) ){
quantity = endTime - startTime;
total = priceD*quantity;
}else if( (0.0 <= startTime)&&(startTime< 17.0) && (17.0 <= endTime)&&( endTime< 24.0) ){
quantity = 17.0 - startTime;
total = priceD*quantity;
quantity = endTime -17.0;
total = total+ priceE*quantity;
}
else if( (17.0 <= startTime)&&(startTime < 24.0) && (startTime <= endTime)&&(endTime < 24.0) ){
quantity = endTime - startTime;
total = priceE*quantity;
}
System.out.println("Service Charge "+ total);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.