Results 1 to 5 of 5

Thread: Inbetween Dates

  1. #1
    Rageagainst20 is offline Member
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default Inbetween Dates

    Hello I am new very to Java (I am having fun with it though!) I was wondering if this is hard to do.

    Sorry about the suedo code

    Java Code:
    If TodaysDate = (>StartDate AND <EndDate)
    I just what to make a condition that if todays date = greater than a start date and less than an end date then

    ***Something will happen (in this case my program adds 10% to the price). This is bascially for a billing program that adds on a quartely charge for each customer. The thing is, it as to detect with quarter has gone if you divide 365/4 thats 91.25 days a year. Now each of these 4 quarters could be called winter spring summer and autumn. From this my program needs to go on to detect the difference between the end of that quarter and todays date, from this i can work out a discount for paying arly or a cahrge for playing late.

    Thanks for reading please help me I am all out of ideas and have nowhere to begin

  2. #2
    gulapala is offline Member
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0

    Default

    Hi,

    In Jdk1.5, you have the two methods after(Date when) and before(Date when) in the Date class, which return the boolean value. You can add the code as below(pseudo code is given):

    Java Code:
       
    Date d = new Date() // d is the Date that needs to be checked
    boolean check = false;
    
      if (d.after(startdate) && d.before (enddate)) check = true;
      if (check == true) 
    
         //your code should be here.
    Last edited by JavaBean; 12-12-2007 at 11:13 AM. Reason: To highlight the code. - Use [ code ] not <code>
    Thanks & Regards, G.Rajasekhar

  3. #3
    Rageagainst20 is offline Member
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default

    Thank you very much for your help!

  4. #4
    Rageagainst20 is offline Member
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default

    Another question, I mentioned earlier that I will have to set up quartars (for a year)

    I plan to have each quarter as follows

    Quarter 1. January, Febuary, March
    Quarter 2. April, May, June
    Quarter 3. July, August, September
    Quarter 4. October, Novemeber, December

    Is there anyway to use a CASE like statement similiar to the one in offer in VB. Each month will have different dates, what could be the best way to compare todays date with each of the quarters, for example the end of the last quarter is Decemeber 31st, one of the conditions in this assignment is to calculate a bill based on the meter reading and apply discounts and chares as appropriate. I have little Java experience but I am an accomplished programmer in other fields, but I am finding it hard to think of how to create these Case statements (or whatever the Java alternate is)

    Below is the problem outlined


    Outline of the problem

    As an employee of a software company, you have been asked to develop an electronic billing system. The system will be part of a web site of a privet company that provides electricity to the customers. The idea is to reduce cost by providing online billing system which will replace existing pay by phone system. Online system will also reduce the time customer spends to make a payment. The payment process gets delayed due to calling centres being busy most of the time.

    Your job as a programmer is to write a program in Java that will allow a customer to make a payment online.

    This means that your program must calculate customerís electricity bill.

    A bill includes a quarterly £20 charge plus a consumption (use) charge of £0.07 per unit.

    Consumption is calculated from meter readings taken recently and at the end of the previous quarter (a customer is expected to enter this data).

    The payment should be made within fifteen days of the end of present quarter.

    Every payment must be checked for late payment and a £10 fee should be added for overdue payment.

    A discount of 10% will be applied to all customers who pay their bills within seven days of the end of the present quarter.

    You are also required to log the time a customer spends to make a payment. Customer should be able to request a report about the payment, which should be in a printable format.

    The company accountant should be able to view the same report.

  5. #5
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.text.*;
    import java.util.*;
    
    public class DateSwitch {
        public static void main(String[] args) {
            DateFormat df = new SimpleDateFormat("dd MMM yyyy");
            Calendar calendar = Calendar.getInstance();
            int[][] data = {
                { 2007, 2, 12 }, { 2006, 8, 6 }, { 2007,  2, 19 },
                { 2008, 9, 25 }, { 2010, 3, 4 }, { 2007, 11, 31 }
            };
            for(int j = 0; j < data.length; j++) {
                calendar.set(data[j][0], data[j][1], data[j][2]);
                Date date = calendar.getTime();
                System.out.printf("quarter for %s = %d%n",
                                   df.format(date), getQuarter(date));
            }
        }
    
        /**
         * Quarter 1. January, Febuary, March
         * Quarter 2. April, May, June
         * Quarter 3. July, August, September
         * Quarter 4. October, Novemeber, December
         */
        private static int getQuarter(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int year = calendar.get(Calendar.YEAR);
            int[] months = { 3, 6, 9, 12 };
            int count = 0;
            do {
                calendar.set(year, months[count++], 1);
                Date gate = calendar.getTime();
                if(date.compareTo(gate) < 1)
                    return count;
            } while(count < 4);
            return 0;
        }
    }

Similar Threads

  1. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 08:05 AM
  2. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:06 AM
  3. Comparing dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:02 AM
  4. help with dates and time
    By osval in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 01:41 PM
  5. differences between 2 dates
    By cecily in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 06:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •