Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 10:50 PM
Member
 
Join Date: Dec 2007
Posts: 8
Rageagainst20 is on a distinguished road
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

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-12-2007, 11:40 AM
Member
 
Join Date: Dec 2007
Posts: 11
gulapala is on a distinguished road
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):

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.
__________________
Thanks & Regards, G.Rajasekhar

Last edited by JavaBean : 12-12-2007 at 12:13 PM. Reason: To highlight the code. - Use [ code ] not <code>
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-12-2007, 02:01 PM
Member
 
Join Date: Dec 2007
Posts: 8
Rageagainst20 is on a distinguished road
Thank you very much for your help!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-18-2007, 06:04 PM
Member
 
Join Date: Dec 2007
Posts: 8
Rageagainst20 is on a distinguished road
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


Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-19-2007, 07:24 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Compare two Dates Java Tip java.util 1 06-24-2008 09:05 AM
No fo days between two dates Java Tip Java Tips 0 01-28-2008 11:06 AM
Comparing dates Java Tip Java Tips 0 01-28-2008 11:02 AM
help with dates and time osval New To Java 3 12-12-2007 02:41 PM
differences between 2 dates cecily New To Java 1 08-02-2007 07:37 PM


All times are GMT +3. The time now is 04:34 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org