URGENT Need help with code for billing
Hello Im working on a school project and seem to be stuck. Any help is appreciated!
Basically my program has to compute charges for a company based on the hour of the day and the day of the week. Im stuck on the part where it is supposed to compute the fee based on the time of day :(
PLEASE HELP ...here is what I have so far....
Code java:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class Project2
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
System.out.print("Plumber: ");
String name = sc.next();
System.out.print("Service date (mm/dd/yyyy): ");
String service_date = sc.next();
sc.useDelimiter("/");
sdf.setLenient(false);
// covert input to calendar object
sc = new Scanner(service_date);
sc.useDelimiter("/");
//Parse input for individual values (mm/dd/yyyy)
//January=0, so subtract 1 from month
int month = sc.nextInt()-1;
int day = sc.nextInt();
int year = sc.nextInt();
Calendar cal = Calendar.getInstance();
cal.set(year, month, day);
//Get day of week, Sun=1,.. Sat=7
int n = cal.get(Calendar.DAY_OF_WEEK);
Scanner sd = new Scanner(System.in);
System.out.print("Starting time of service call (Military time): ");
int start = 0;
start = sd.nextInt();
System.out.print("Ending time of service call (Military time): ");
int end = 0;
end = sd.nextInt();
//Start time
double startTime = (start / 100) + (start % 100.0 / 60);
//End time
double endTime = (end / 100) + (end % 100.0 / 60);
double service_time = endTime - startTime;
int base = 52;
int over = 78;
int saturday = 76;
int overSaturday = 114;
int sunday = 124;
int overSunday = 186;
double fee =0;
// Weekday charges if basic or overtime
if (n>=2 && n<=6)
fee = (service_time * base);
// Saturday
if (n==7)
fee = (service_time * saturday);
// Sunday
if (n==1)
fee = (service_time * sunday);
//output
System.out.println("");
System.out.println("Leaky Plumbing Repair Company");
System.out.println("Invoice for Services");
System.out.println("");
System.out.println("Date Printed: " + sdf.format (d));
System.out.println("Plumber: " +name);
System.out.println("");
System.out.println("Service date: "+service_date);
System.out.println("Service hours: " +service_time);
System.out.println("");
System.out.println("Charges:" +fee);
}
}
Re: URGENT Need help with code for billing
* So the part im having trouble with is writing the if statement for
if (weekday) && (reg business hours)
fee= (service_time * base);
So ive gotten the weekday part down but im lost on how to write the reg business hours part.
Im trying to say that if service is performed between 8am and 5pm the fee is the amt of hrs time reg fee
However if service is performed after 5pm and before 8am the the fee is 1.5 times the reg fee
Re: URGENT Need help with code for billing
For future reference, please flank your code with the code/highlight tags (see Announcements for instructions)
Your conditions sounds like an if/else...in pseudo-code
Code :
if ( normalBusinessHours ){
//calculate normal business hours fee
}else{
///calculate fee based upon off hours
}