mercredi 7 octobre 2015

How to use if-else with String dates

I am trying to use if-else statements to get the date entered by the user and display a constant for that particular season.

So for example if I were to enter a date of 04/25/2015 I would want it to show the price for Spring. When I print the price it displays zero instead.

Any help will be great. Method will be shown below

public double determinePrice(){

    double price = 0;
    if(rentalDate.substring(1, 3).equals(3) || rentalDate.substring(1, 3).equals(4)|| rentalDate.substring(1, 3).equals(5))
        price = SPRING; 
    else if(rentalDate.substring(1, 3).equals(6) || rentalDate.substring(1, 3).equals(7)|| rentalDate.substring(1, 3).equals(8))
        price =  SUMMER;
    else if(rentalDate.substring(1, 3).equals(9) || rentalDate.substring(0, 3).equals(10)|| rentalDate.substring(0, 3).equals(11))
        price = FALL;   
    else if(rentalDate.substring(0, 3).equals(12) || rentalDate.substring(0, 3).equals(01)|| rentalDate.substring(1, 3).equals(02))
        price = WINTER;

    return price;

}

Aucun commentaire:

Enregistrer un commentaire