Results 1 to 5 of 5
Thread: Inbetween Dates
- 12-11-2007, 08:50 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 8
- Rep Power
- 0
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
I just what to make a condition that if todays date = greater than a start date and less than an end date thenJava Code:If TodaysDate = (>StartDate AND <EndDate)
***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
- 12-12-2007, 09:40 AM #2
Member
- Join Date
- Dec 2007
- Posts
- 11
- Rep Power
- 0
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 10:13 AM. Reason: To highlight the code. - Use [ code ] not <code>
Thanks & Regards, G.Rajasekhar
- 12-12-2007, 12:01 PM #3
Member
- Join Date
- Dec 2007
- Posts
- 8
- Rep Power
- 0
Thank you very much for your help!
- 12-18-2007, 04:04 PM #4
Member
- Join Date
- Dec 2007
- Posts
- 8
- Rep Power
- 0
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.
- 12-19-2007, 05:24 AM #5
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
-
How to Compare two Dates
By Java Tip in forum java.utilReplies: 1Last Post: 06-24-2008, 07:05 AM -
No fo days between two dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:06 AM -
Comparing dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:02 AM -
help with dates and time
By osval in forum New To JavaReplies: 3Last Post: 12-12-2007, 12:41 PM -
differences between 2 dates
By cecily in forum New To JavaReplies: 1Last Post: 08-02-2007, 05:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks