0

Excuse the naming, organization is still a work in progress. I've been trying to solve this for about half an hour, and I can't figure it out! It's 2:30 am, and i've half given up. The purpose of this program is to Parse the date from a string and print it out nicely. I know there are simpler ways of doing this, but this is the method needed for my class, or something around it.

 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package strings;

import javax.swing.JOptionPane;
import java.lang.*;

/**
 *
 * @author
 */
public class Strings {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String dateyear, datemonthnum, dateday, dateformat, slashcheck, datemonth;
        int slasharray[] = new int[2];
        int i, iplus;
        iplus = 0;
        dateformat = JOptionPane.showInputDialog("Please enter the date in mm/dd/yyyy format.");
        i = dateformat.indexOf('/');
        while (i >= 0) {
            System.out.println(i);
            System.out.println(iplus);
            System.out.println(slasharray[iplus]);
            slasharray[iplus] = i;
            iplus++;
            i = dateformat.indexOf('/', i + 1);
        }
        dateyear = dateformat.substring(slasharray[1]+1, 10);
        datemonthnum = dateformat.substring(slasharray[0]+1, slasharray[1]);
        dateday = dateformat.substring(0, slasharray[0]);
        System.out.println(dateyear);
        System.out.println(datemonthnum);
        System.out.println(dateday);
        if(datemonthnum == "01"){
            datemonth = "January";
        }
        else if(datemonthnum == "02"){
            datemonth = "February";
        }
        else if(datemonthnum == "03"){
            datemonth = "January";
        }
        else if(datemonthnum == "04"){
            datemonth = "April";
        }
        else if(datemonthnum == "05"){
            datemonth = "May";
        }
        else if(datemonthnum == "06"){
            datemonth = "June";
        }
        else if(datemonthnum == "07"){
            datemonth = "July";
        }
        else if(datemonthnum == "08"){
            datemonth = "August";
        }
        else if(datemonthnum == "09"){
            datemonth = "September";
        }
        else if(datemonthnum == "10"){
            datemonth = "October";
        }
        else if(datemonthnum == "11"){
            datemonth = "November";
        }
        else if(datemonthnum == "12"){
            datemonth = "December";
        }
        else {
        JOptionPane.showMessageDialog(null, "You have not entered a valid month. Please try again.");
        System.exit(0);
        }
        JOptionPane.showMessageDialog(null, "The Date is " + datemonth + " " + dateday + ", " + dateyear + ".");
    }

}
Arkaiid
  • 1
  • 2

0 Answers0