Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: URGENT Need help with code for billing

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Default 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....
    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();
    		 // covert input to calendar object
    		 sc = new Scanner(service_date);
    		//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);	 
    		    System.out.println("Leaky Plumbing Repair Company");
    		    System.out.println("Invoice for Services");
    		    System.out.println("Date Printed: " + sdf.format (d));
    		    System.out.println("Plumber: " +name);	
    		    System.out.println("Service date: "+service_date);	
    		    System.out.println("Service hours: " +service_time);
    		    System.out.println("Charges:" +fee);		
    Last edited by copeg; February 13th, 2011 at 11:41 AM.

  2. #2
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Default 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

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default 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
    if ( normalBusinessHours ){
     //calculate normal business hours fee
    ///calculate fee based upon off hours

Similar Threads

  1. its urgent
    By talha07 in forum Java Networking
    Replies: 3
    Last Post: January 22nd, 2011, 01:44 PM
  2. cable company billing..need help with methods
    By printmatic in forum What's Wrong With My Code?
    Replies: 12
    Last Post: November 7th, 2010, 04:48 PM
    By macx234 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 30th, 2010, 08:41 PM
  4. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM
  5. Replies: 1
    Last Post: May 4th, 2009, 06:30 AM