Hi. I am tr ying to write a function for JAVA that will caluclate a rate for my local ISP for the day's sign up. the final rate after taxes is 21.05. If the days left is less than 15, we add the rest of the amount plus 21.05 to it. if its more than 15 days left, then its only that pro-rated amount. But anyways, I can get the system date and I use a substring to get "Mar" for the current month. then i have an If statment that is supposed to set the numOfDays to 31 if "Mar". well, its not working. the month is set to "Mar" but the if statement isn't working.
here's the code
import java.util.*;
public class counter {
public static double convertStringtoDouble(String s) {
Double doubleObject = Double.valueOf(s);
return doubleObject.doubleValue();
}
public static void main(String argv[]) {
//Define all variables
String dateString="",month="",dayString="",yearString="";
int year;
double dialup=19.95,dialUpPrice,numOfDays=0;
//System Date
Date today = new Date();
dateString=today.toString();
//Figures out month<string>, day<double> for calculations.
month = dateString.substring(4,7);
month = month.toString();
dayString = dateString.substring(8,10);
double day = convertStringtoDouble(dayString);
yearString = dateString.substring(24,28);
double yeardouble= convertStringtoDouble(yearString);
year = (int)yeardouble;
//if month is J,M,M,J,A,O,D numOfDays is 31
if (month=="Jan" || month=="Mar" || month == "May" || month=="Jul" || month == "Aug" || month == "Oct" || month == "Dec"
{
numOfDays=31;
}
//else check for leap years in 2004 and 2008 (after this, java will be obsolete)
else if (month=="Feb" && (year == 2004 || year == 2008))
{
numOfDays=29;
}
else if (month=="Feb"{
numOfDays=28;}
else{
numOfDays=30;
}
//not sure about this part. hopeuflly this computes teh amount.
double tempPrice=dialup / numOfDays * (numOfDays-day);
if (day < 15) {
dialUpPrice=tempPrice+(tempPrice*0.055);
}
else {
dialUpPrice = dialup+tempPrice+((dialup+tempPrice)*0.055);
}
//prints out the dialup price and just for testing the num of days
System.out.println (dialUpPrice);
System.out.println (numOfDays);
}
}
tahnx alot for your help.
aarons
here's the code
import java.util.*;
public class counter {
public static double convertStringtoDouble(String s) {
Double doubleObject = Double.valueOf(s);
return doubleObject.doubleValue();
}
public static void main(String argv[]) {
//Define all variables
String dateString="",month="",dayString="",yearString="";
int year;
double dialup=19.95,dialUpPrice,numOfDays=0;
//System Date
Date today = new Date();
dateString=today.toString();
//Figures out month<string>, day<double> for calculations.
month = dateString.substring(4,7);
month = month.toString();
dayString = dateString.substring(8,10);
double day = convertStringtoDouble(dayString);
yearString = dateString.substring(24,28);
double yeardouble= convertStringtoDouble(yearString);
year = (int)yeardouble;
//if month is J,M,M,J,A,O,D numOfDays is 31
if (month=="Jan" || month=="Mar" || month == "May" || month=="Jul" || month == "Aug" || month == "Oct" || month == "Dec"
{
numOfDays=31;
}
//else check for leap years in 2004 and 2008 (after this, java will be obsolete)
else if (month=="Feb" && (year == 2004 || year == 2008))
{
numOfDays=29;
}
else if (month=="Feb"{
numOfDays=28;}
else{
numOfDays=30;
}
//not sure about this part. hopeuflly this computes teh amount.
double tempPrice=dialup / numOfDays * (numOfDays-day);
if (day < 15) {
dialUpPrice=tempPrice+(tempPrice*0.055);
}
else {
dialUpPrice = dialup+tempPrice+((dialup+tempPrice)*0.055);
}
//prints out the dialup price and just for testing the num of days
System.out.println (dialUpPrice);
System.out.println (numOfDays);
}
}
tahnx alot for your help.
aarons