0

I am wanting to calculate the days between the start date of cycle and end date of cycle. the user will input the dates. i want to be able to use that input to calculate how long the cycle last as numberofdays.

the following is my current code and basic idea of how i want it to run. I have seen similar posts but nothing towards using an unknown user date. Any help would be appreciated thank you.

import java.util.Scanner;
import java.util.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.awt.*;
import java.time.*;
import java.util.Calendar;

public class project1
{
    public static void main (String [] args)
    {
        int StartDate = 0;                                                                      //Declaring Number of Toppings
        int EndDate = 0 ;                                                                   //Declaring Charge Per Topping in decimal


    Scanner inNumber= new Scanner (System.in);                                                          //Crate Scanner for input of number of toppings
    Scanner inText = new Scanner(System.in);                                                            //Creat Scanner for input of Name of Customers

    System.out.println("                 Female Calendar Entry System                    ");
    System.out.println( " "  ) ;


    String CustomersName = " ";
    System.out.print( "Please enter your name ==> ") ;
    CustomersName = inText.nextLine();                                                              //Inputing Customers Name

    System.out.println( " "  ) ;

    Date thisDate= new Date();
    SimpleDateFormat dateForm = new SimpleDateFormat ("dd/MM/Y");
    String startDate = dateForm.format(thisDate);
    System.out.println("                 Todays Date " +(dateForm.format(thisDate)));

    System.out.println( " "  ) ;

    // To take the input
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter Cycle start date ");

    String date = scanner.next();

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/Y");
    Date date2=null;
    System.out.println( " "  ) ;  
    Scanner scanner2 = new Scanner(System.in);
    System.out.println("Enter Cycle end date ");
    String date3 = scanner.next();
    SimpleDateFormat date3Format = new SimpleDateFormat("dd/MM/Y");
    Date date4=null;

        System.out.println("\n\n--- Female Calender Results ---");                              //Recipt for pizza order with name number of topings and overal price
        System.out.println( " "  ) ;
        System.out.println("Client Name: " + CustomersName);
        System.out.println("Lenght of cycle:")  ; // this should have the number of days the cycle lasted
        System.out.println("Aproximently next cycle: " + (" "));  // this should have 28 days end date of cycles
        System.out.println(" ");
    }
}
Traian GEICU
  • 1,750
  • 3
  • 14
  • 26
TXITECH
  • 1
  • 1
  • 1
    Does this answer your question? [Calculating days between two dates with Java](https://stackoverflow.com/questions/20165564/calculating-days-between-two-dates-with-java) – OH GOD SPIDERS May 29 '20 at 15:28
  • 2
    The posts you've seen probably all have shown exactly what you want. It doesn't matter if the user date is "unknown", what are variables for? *FYI:* You may want to switch to [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html). The old API (`Date`, `SimpleDateFormat` etc.) is already a meme, please don't use it. – akuzminykh May 29 '20 at 15:31
  • I have read through the suggested Stackoverflow, but i am having trouble converting it to what i need. And when you say Java.time whats the actual import title cause it dosent exist on mine so it claims ? – TXITECH May 29 '20 at 15:41
  • @TXITECH Just importing something doesn't mean you are using it. You are using the classes from the older API. Could you add whatever you've tried and describe the problems you're having? You may also want to add the [date] tag so more people will find the question. – akuzminykh May 29 '20 at 16:03

0 Answers0