Image

Imagethe_tara wrote in Imagejava_dev

a simple Java program

Very sorry if this goes against the rules, but I'll put most of this post under a LJ cut.

I've tried and I've tried but I can't seem to get it right -- very confusing for a first time user of Java.

It's a simple program, yet it's got me utterly confused. Any help would be appreciated.

I am supposed to write a program that asks for the date in the format Day Month-in-Full Year and replies in the format dd-MMM-yy (eg. 12-Jun-04).

I've been trying pretty much anything but it doesn't seem to be working out, and I have a feeling that I'm complicating matters more than they should be.


Here's what I've got so far:

import javax.swing.*;
import java.util.*;
import java.text.*;

class Lab2Portfolio
{
public static void main(String[] args)
{
String date, day, month, year;

Date todayDate;
SimpleDateFormat sdfDate;

//date = new String();
//todayDate = date.substring(0, date.indexOf(space));
//todayDate = new Date();

sdfDate = new SimpleDateFormat("dd-MMM-yy");

//date = JOptionPane.showInputDialog(null, "Enter the date (Day, Month-in-Full, Year):");
//day = date.substring(0, date.indexOf(space));
//date = date.substring(date.indexOf(space)+1, date.length());
//month = date.substring(0, date.indexOf(space));
//year = date.substring(date.indexOf(space)+1, date.length());

JOptionPane.showMessageDialog (null, "Date: " + sdfDate.format(todayDate));
}
}


It's an absolute mess at the moment, I commented out a lot of things that didn't work, or only worked a little bit. The closest I got to success was where it allowed the user to input the date and all, but then displayed the actual date, not the date inputted. Argh, I'm sure that many will see what I've done and laugh at the extreme crappiness of it, but it can't be helped.

Thanks for your time.