Urgent Need help on DATE Class

i have written the code
<page language="java">
<%@page import="java.util.Date" %>
<%
     String mydate="10/25/03";
     Date d=new Date(mydate);
     int mon=d.getMonth();
     int day=d.getDay();
     int year=d.getYear();
     out.println(d+","+mon+","+day+","+year);
%>
when i execute
Sat Oct 25 00:00:00 GMT+05:30 2003,9,6,103
can some one help me, why i am getting different month day and year

Be aware that you're using deprecated methods of the Date class. If you read the javadoc for those methods you'll discover that the results are correct. The getMonth method returns a zero-offset month with zero representing January. The getDay method returns a zero-offset day of the week (0 = Sunday...6 = Saturday) not the day of the month. Use the getDate method to return day of the month. The getYear method returns a value that is the result of subtracting 1900 from the year.

Similar Messages

  • Urgent need help in data archeiving

    hi to all,
              i had a problem in data archeiving. the problem is i want to archive data from two tables
    and also delete that data after a specific time. i got standard programs for it like sbooka and sbookd
    one is for addition of record and other is deletion of records. but how to go forward with these standard programs i am not understanding ok plz help me in this issue
    Thanks and Regards
    Kranthi Kiran Reddy

    Hi,
       1) Create a archive object for ur program using
          AOBJ transaction by specifying tables to be
          archived. DAta is stored in table Arch_obj.
          Also specify new delete,read program name.
          create archive info structure,field catalog also.
          Study EXAMPLE archive object and proceed. 
       2) First read archive data similar to program
          sbooka by changing archive object name.
          archive file will be created and stored in table
          admi_run,admi_files.
       3) Write delete program similar to sbookD to delete
          data from your z custom table.
       4 ) SARA transaction can be used to schedule
           job.
       5)  SARI transaction can be used to view archived data.
    Regards,
    Amole

  • Need help in date Validation Urgent

    Hi ,
    We need help in Date Validation.
    we have 2 Date fields on the form Start Date, End Date
    The requirement is: End Date (May not be greater than 30 years from the start date).
    I have written following script on End Date Exit event. But the problem is its calculating 30 years from the Current Date not from the Start Date
    var tDate = util.scand("mm/dd/yyyy", new Date());
    var M = tDate.getMonth();
    var D = tDate.getDate();
    var Y = tDate.getFullYear();
    var SRes = util.printd("yyyy-mm-dd", new Date((Y+30), M,D) );
    //app.alert(SRes)if (SRes <= this.rawValue){
    app.alert("May not be greater than 30 years from the start date")
    xfa.host.setFocus(
    this);}
    can someone please help me
    Regards,
    Jay

    Hi,
    You'll need to get javascript date from LCD field, and calculate & compare with the future date in javascript date.
    try following script;
    var sDate = StartDate.rawValue;
    var wkStartDate = util.scand("yyyy-mm-dd", sDate);
    var nYear = wkStartDate.getFullYear();
    var nMonth = wkStartDate.getMonth();
    var nDay = wkStartDate.getDate();
    var wkFutureDate = new Date(nYear  + 30 , nMonth, nDay);
    sDate = EndDate.rawValue;
    var wkEndDate = util.scand("yyyy-mm-dd", sDate);
    if (wkEndDate.getTime() > wkFutureDate.getTime()){
      xfa.host.messageBox("May not be greater than 30 years from the start date");
      xfa.host.setFocus(this);

  • Urgently need help with this

    Hi!!
    I urgently need help with this:
    When I compile this in Flex Builder 3 it says: The element type 'mx:Application' must be terminated by the matching end-tag '</mx:Application>'.
    but I have this end tag in my file, but when I try to switch from source view to desgin view it says, that: >/mx:Script> expected to terminate element at line 71, this is right at the end of the .mxml file. I have actionscript(.as) file for scripting data.
    This is the mxml code to terminate apllication tag which I did as you can see:
    MXML code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#007200, #000200]" width="1024" height="768" applicationComplete="popolni_vse()">
    <mx:HTTPService id="bazaMME" url="lokalnabaza/baza_MME_svn.xml" showBusyCursor="true" resultFormat="e4x"/>
    <mx:Script source="dajzaj.as"/>
    <mx:states>
    <mx:State name="Galerije">
        <mx:SetProperty target="{panel1}" name="title" value="Galerije MME"/>
        <mx:SetProperty target="{panel2}" name="title" value="opis slik"/>
        <mx:SetProperty target="{panel3}" name="title" value="Opis Galerije"/>   
        <mx:AddChild relativeTo="{panel1}" position="lastChild">
        <mx:HorizontalList x="0" y="22" width="713.09863" height="157.39436" id="ListaslikGalerije"></mx:HorizontalList>
                </mx:AddChild>
                <mx:SetProperty target="{text1}" name="text" value="MME opisi galerij "/>
                <mx:AddChild relativeTo="{panel1}" position="lastChild">
                    <mx:Label x="217" y="346" text="labela za test" id="izbr"/>
                </mx:AddChild>
                <mx:SetProperty target="{label1}" name="text" value="26. November 2009@08:06"/>
                <mx:SetProperty target="{label1}" name="x" value="845"/>
                <mx:SetProperty target="{label1}" name="width" value="169"/>
                <mx:SetProperty target="{Gale}" name="text" value="plac za Galerije"/>
            </mx:State>
            <mx:State name="Projekti"/>
        </mx:states>
    <mx:MenuBar id="MMEMenu" labelField="@label" showRoot="true" fillAlphas="[1.0, 1.0]" fillColors="[#043D01, #000000]" color="#9EE499" x="8" y="24"
             itemClick="dajVsebino(event)" width="1006.1268" height="21.90141">
           <mx:XMLList id="MMEmenuModel">
                 <menuitem label="O nas">
                     <menuitem label="reference podjetja" name="refMME" type="check" groupName="one"/>
                     <menuitem label="reference direktor" name="refdir" type="check" groupName="one"/>
                  <menuitem label="Kontakt" name="podatMME" groupName="one" />
                  <menuitem label="Kje smo" name="lokaMME" type="check" groupName="one" />
                 </menuitem>           
                 <menuitem type="separator"/>
                 <menuitem label="Galerija">
                     <menuitem label="Slovenija" name="galSvn" type="check" groupName="one"/>
                     <menuitem label="Nemčija" name="galDeu" type="check" groupName="one" />
                 </menuitem>
                 <menuitem type="separator"/>
                 <menuitem label="projekti">
                     <menuitem label="Slovenija" name="projSvn" type="check" groupName="one"/>
                     <menuitem label="Nemčija" name="projDeu" type="check" groupName="one" />
                     <menuitem label="Madžarska" name="projHun" type="check" groupName="one"/>
                 </menuitem>
             </mx:XMLList>                       
             </mx:MenuBar>
        <mx:Label x="845" y="10" text="25. November 2009@08:21" color="#FFFFFF" width="169" height="18.02817" id="label1"/>
        <mx:Label x="746" y="10" text="zadnja posodobitev:" color="#FFFFFF"/>
        <mx:Panel x="9" y="57" width="743.02814" height="688.4507" layout="absolute" title="Plac za Vsebino" id="panel1">
            <mx:Text x="0" y="-0.1" text="MME vsebina" width="722.95776" height="648.4507" id="Gale"/>
        </mx:Panel>
        <mx:Label x="197.25" y="748.45" color="#FFFFFF" text="Copyright © 2009 MME d.o.o." fontSize="12" width="228.73239" height="20"/>
        <mx:Label x="463.35" y="748.45" text="izdelava spletnih strani: FACTUM d.o.o." color="#FBFDFD" fontSize="12" width="287.60565" height="20"/>
        <mx:Panel x="759" y="53" width="250" height="705.07043" layout="absolute" title="Plac za hitre novice" id="panel3">
            <mx:Text x="0" y="0" text="MME novice" width="230" height="665.07043" id="text1"/>
            <mx:Panel x="-10" y="325.35" width="250" height="336.61972" layout="absolute" title="začasna panela" color="#000203" themeColor="#4BA247" cornerRadius="10" backgroundColor="#4B9539" id="panel2">
                <mx:Label x="145" y="53" text="vrednost" id="spremmen"/>
                <mx:Label x="125" y="78" text="Label"/>
                <mx:Label x="125" y="103" text="Label"/>
                <mx:Label x="0" y="53" text="spremenljivka iz Menuja:"/>
                <mx:Label x="45" y="78" text="Label"/>
                <mx:Label x="45" y="103" text="Label"/>
            </mx:Panel>
        </mx:Panel>
        <mx:Label x="9.9" y="10" text="plac za naslov MME vsebine" id="MMEnaslov" color="#040000"/>
         </mx:states></mx:Application>

    I know it's been a while but… did you fix this?
    It looks to me like you are terminating the <mx:Application> tag at the top. The opening tag should end like this: resultFormat="e4x">, not resultFormat="e4x"/> (Remove the /).
    Carlos

  • Need Help with Dates

    I am printing a calendar and certain events will be helds on certain dates.
    One can edit the event if it has not passed the date. Events in the past can be viewed but not edited.
    When I query the database the date must be formatted dd-MMM-yy
    I am able to get today's date by doing this:
    java.util.Date today = new java.util.Date();
    String formatString = "dd-MMM-yy";
    SimpleDateFormat sdf = new SimpleDateFormat(formatString);
    String today_str = sdf.format(today);
    My code for printing the calendar: I left out some of the table formatting in the JSP page.
    GregorianCalendar d = new GregorianCalendar();
    int today = d.get(Calendar.DAY_OF_MONTH);
    int month = d.get(Calendar.MONTH);
    d.set(Calendar.DAY_OF_MONTH,1);
    int weekday = d.get(Calendar.DAY_OF_WEEK);
    for(int i = Calendar.SUNDAY; i < weekday; i++)
    out.print("<td> </td>");
    do {
    int day = d.get(Calendar.DAY_OF_MONTH);
    out.print("<td>" + day + "</td>");
    String formatString = "dd-MMM-yy";
    SimpleDateFormat sdf = new SimpleDateFormat(formatString);
    //if(event exists on this day
    // Get results
    // print link for viewing
    // if (after today) print link for edit
    if(weekday == Calendar.SATURDAY)
    out.println("</tr><tr valign=top>");
    d.add(Calendar.DAY_OF_MONTH,1);
    weekday = d.get(Calendar.DAY_OF_WEEK);
    } while(d.get(Calendar.MONTH) == month);
    if(weekday != Calendar.SUNDAY)
    System.out.println();
    The part I need help on is this:
    //if(event exists on this day
    // Get results
    // print link for viewing
    // if (after today) print link for edit
    I'm looping through each day of the month to print the days. I have the month, day, year as integers. How can I create a date object out of that and compare it to today's date to test if it's before or after today???
    All the function in the Date class that I think would do this have been deprecated.

    Need Help with Dates
    Here is some information about dates:
    There are many edible palm fruits, and one of the most widespread and favored of these is the data (Phoenix dactylifera). Dates were cultivated in ancient land from Mesopotamia to prehistoric Egypt, possibly as early as 6000 B.C. Then--as now--dates were a staple for the natives of those dry regions. Much later, Arabs spread dates around northern Africa, and dates were introduced into California by the Spaniards in 1765, around Mission San Ignacio.
    The date prefers dry, hot climates, because date fruits are injured at temperatures of 20 degrees F, and the damp climate of the California coast was not favorable for fruit production. In the mid-1800s, the date industry developed in California's hot interior valleys and in Arizona. Now the date industry in the United States is localized mostly in the Coachella Valley, where the sandy soils permit the plants to be deeply irrigated. Today the new varieties, mostly introduced in this century, produce about 40 million pounds of dates per annum, or over 60% of the dates consumed in this country. The rest are imported mainly from Persia. According to one survey, about one million people are engaged entirely in date palm cultivation worldwide.
    Hope that helps.

  • Urgently  need help for parsing IP header

    Hi, could anyone tell which class I should use to parsing the IP header of a packet?
    Thanks many many times!

    > Hi, could anyone tell which class I should use to
    parsing the IP header of a packet?
    DatagramPacket?
    > Urgently need help for parsing IP header
    Don't flag your question as urgent, even if it is for you.
    * We all answer questions here voluntarily, in our leisure time. We do that because doing so is fun for us, because we enjoy helping people and having interesting discussions. Guess what, it is much less fun if it gets stressful. So the last thing you want to do to get us to answer your question is to pass your stress over to us.
    * People who are stressed and want a fast answer often don't even find the time to do the necessary research or to formulate their question in an easy to comprehend way. That's even less fun to work with. So you really don't want us to feel your stress. Instead you want to take your time to write a well formulated post that is fun to answer. The less likely it is for us to know that your question is urgent, the more likely you are to get a fast answer!
    * The simple notion that you want your post to be answered faster than those of the other members might feel rather unfair to some of us. Doubly so because often "urgent" questions actually are homework questions. Yours might be different, but someone who had bad experiences with this type of question might not read far enough to notice.

  • Need help in Creating classes for my assignment

    Hi ,
    I just started learning Java and have the following requirement
    1)     Create the following classes/interfaces using descriptions:
    a)     Account � data members : id:String, type:String, balance:BigDecimal, methods : Account, Account with String parameter, getId, getType, getBalance, setId, setType, setBalance, deposit, withdraw, compareTo, toString
    b)     Bank � data members: instance:Bank, accountsMap:Map, customersMap:Map, customersAccount:Map, transactionMap:Map, methods: getAccountsMap, getCustormersMap, getCustomersAccounts, getTransactionMap, associate, addTransaction, getAccount, getCustomer, getAccounts, getTransactions, deposit, withdraw, transfer
    c)     AccountDoesNotExistException, BankException, CustomerDoesNotExistException, InsufficientFundsException, InvalidAmountException, ZeroAmountException
    2)     Create the util package using the following class
    a)     AmountConverter � methods: fromDecimal(BigDecim     al), fromString(String)
    In 1 b how to Create Instance:bank in the class .Also how to do part2.If possible can you help me with all the parts.Based on these I've some more to do.

    Here is what I've come with
    ACCOUNT.JAVA
    import java.math.*;
    public class Account {
    private String Id;
    private String Type;
    private BigDecimal balance;
    public Account( ) {
    public Account(String Id,String Type,BigInteger balance) {
    this.Id = Id;
    this.Type = Type;
    this.balance = balance;
    public String getId( ) {
    return Id;
    public void setId(String Id) {
    this.Id = Id;
    public String getType( ) {
    return Type;
    public void setType(String Title) {
    this.Title = Type;
    public String getBalance( ) {
    return id;
    public void setBalance(String balance) {
    this.balance = balance;
    public String withdraw( ) {
    public String deposit( ) {
    public void setLastName(String LastName) {
    this.id = id;
    CUSTOMER.JAVA
    public class Customer {
    private String Id;
    private String Title;
    private String firstName;
    private String lastName;
    /** Construct a Customer with no data -- must be a no-argument */
    public Customer( ) {
    /** Construct a Customer with String Parameter */
    public Customer(String Id,String Title,String firstName,String lastName) {
    this.Id = Id;
    this.Title = Title;
    this.firstName = firstName;
    this.lastName = lastName;
    /** Return the Id. */
    public String getId( ) {
    return Id;
    /** Set the Id */
    public void setId(String Id) {
    this.Id = Id;
    /** Return the Title */
    public String getTitle( ) {
    return Title;
    /** Set the Title */
    public void setTitle(String Title) {
    this.Title = Title;
    /** Return the Firstname. */
    public String getFirstName( ) {
    return id;
    /** Set the Firstname. */
    public void setFirstName(String FirstName) {
    this.id = id;
    /** Return the Lastname. */
    public String getLastName( ) {
    return LastName;
    /** Set the Lastname. */
    public void setLastName(String LastName) {
    this.id = id;
    TRANSRECORD.JAVA
    import java.util.*;
    import java.math.*;
    public class TransRecord implements Comparable{
    private Date timeStamp;
    private String transType;
    private BigDecimal transAmt;
    /** Construct a Trans Record with no data -- must be a no-argument */
    public TransRecord( ) {
    /** Construct a Customer with String Parameter */
    public Customer(String transType,String transAmt) {
    this.transType = transType;
    this.transAmt = transAmt;
    /** Return the timeStamp. */
    public String gettimeStamp( ) {
    return timeStamp;
    /** Set the timeStamp */
    public void settimeStamp(Date timeStamp) {
    this.timeStamp = timeStamp;
    /** Return the TransType */
    public String getTransType( ) {
    return TransType;
    /** Set the TransType */
    public void setTransType(String TransType) {
    this.TransType = TransType;
    /** Return the TransAmt */
    public String getTransAmt( ) {
    return TransAmt;
    /** Set the TransAmt */
    public void setTransAmt(String TransAmt) {
    this.TransAmt = TransAmt;
    /** Return a String representation. */
    public String toString( ) {
    /** CompareTo method */
    public int compareTo(Object argument)
    ===============
    ACCOUNTDOESNOTEXISTEXCEPTION.JAVA
    public class AccountDoesNotExistException
                   extends Exception
         public AccountDoesNotExistException()
              super();
         public AccountDoesNotExistException(String message)
              super(message);
    =================
    BANKEXCEPTION.JAVA
    public class BankException
                   extends Exception
         public BankException()
              super();
         public BankException(String message)
              super(message);
    CUSTOMERDOESNOTEXISTEXCEPTION.JAVA
    public class CustomerDoesNotExistException
                   extends Exception
         public CustomerDoesNotExistException()
              super();
         public CustomerDoesNotExistException(String message)
              super(message);
    ACCOUNTDOESNOTEXISTEXCEPTION.JAVA
    public class AccountDoesNotExistException
                   extends Exception
         public AccountDoesNotExistException()
              super();
         public AccountDoesNotExistException(String message)
              super(message);
    INSUFFICIENTFUNDSEXCEPTION.JAVA
    public class InsufficientFundsException
                   extends Exception
         public InsufficientFundsException()
              super();
         public InsufficientFundsException(String message)
              super(message);
    INVALIDAMOUNTEXCEPTION.JAVA
    public class InvalidAmountException
                   extends Exception
         public InvalidAmountException()
              super();
         public InvalidAmountException(String message)
              super(message);
    ZEROAMOUNTEXCEPTION.JAVA
    public class ZeroAmountException
                   extends Exception
         public ZeroAmountException()
              super();
         public ZeroAmountException(String message)
              super(message);
    I need help with Bank Class and the util class.Correct me If I've missed any exceptions or if any syntax is wrong
    THanks
    AKsh

  • [Urgent] Need help calculating difference between two dates

    I'm trying to write a code to display the current day and time, then accept two dates from the user and display the difference between the two dates. To display the current date and time, I've used the SimpleDateFormatter library but I'm having difficulty calculating the difference between two dates. Could someone please help me with this?
    Below is my code so far
    import java.util.Date;
    import java.util.Scanner;
    import java.text.SimpleDateFormat;
    public class DateFormatter {
         public void displayNow()
              Date todaysDate = new Date();
              SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
              String formattedDate = formatter.format(todaysDate);
              System.out.println("Today's date and time is: "+formattedDate);
         public void calculateDifference(Date startDate, Date endDate)
              /* This is whre i need help! */
         public static void main(String[] args)
              DateFormatter df = new DateFormatter();
              Scanner sc = new Scanner(System.in);
              df.displayNow();
              System.out.println("Please enter a date: ");
              String date1 = sc.next();
              System.out.println("Please enter another date: ");
              String date2 = sc.next();
    }The methods displayNow() and calculateDifference(Date startDate, Date endDate) are essential and cannot be skipped out.

    tarahmarie101 wrote:
    Dude. I've tried doing assignments under pressure, and it doesn't work. Here's a piece of free advice. Start earlier next time, don't put "urgent" in the title of your post b/c it just pisses people off around here--and is a sure sign of an overdue homework assignment which no one around here likes helping with, and try to ask intelligent questions--don't just say "Help me!"
    Of course, it takes some time to learn what the intelligent questions are. You have my sympathy. Try asking questions about how to do a particular task, instead of asking people to tell you what to do. It starts to get easier after a while.
    actually dude i started on this on monday.. but there were so many other stuff to do along with this.. and i did try referring up the Calendar utility but it was a bit confusing actually.. it was only after that did i come to this forum.. nor am i very good at Java.. anyhoo thanks for your sympathies :P

  • URGENT: Need help reading URL of current page

    Hello kind people!
    I need help, and its very simple:
    How do i read the URL of a web page?
    For example, the URL of this page is:
    http://forums.sun.com/thread.jspa?threadID=5327796
    So how can i be able to read in this URL in my java program?
    thanks SO MUCH
    P.S. I HAVE searched the java docs and everything, the closest thing i found was request.getRequestURL().? but i have no idea how to use it. you have NO IDEA how appreciative i would be if you could simply show me exactly how to read in the URL of a given page.
    thanks SO MUCH
    Edited by: homegrownpeas on Aug 31, 2008 5:19 PM

    Going by what I understand here is a simple version of how you can read data from over HTTP.
    This expects the "page" to be text (hence an InputStreamReader instead of an InputStream.)
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.HashMap;
    * GPLv2.
    * @author karlm816
    public class HomeGrownPeas {
          * @param args
         public static void main(String[] args) {
              HashMap<String, String> params = new HashMap<String, String>();
              params.put("threadID", "5327796");
              System.out.println(loadHttpPage("http://forums.sun.com/thread.jspa", params));     
         public static String loadHttpPage(String sUrl, HashMap<String, String> params) {
              // Build the HTTP request string
              StringBuilder sb = new StringBuilder();
              if (params != null) {
                   for (String key : params.keySet()) {
                        if (sb.length() > 0) {
                             sb.append("&");
                        sb.append(key);
                        sb.append("=");
                        sb.append(params.get(key));
              System.out.println("params: " + sb.toString());
              try {
                   URL url = new URL(sUrl);
                   URLConnection connection = url.openConnection();
                   connection.setDoOutput(true);
                   connection.setRequestProperty("Content-Length", "" + sb.length());
                   connection.setUseCaches(false);
                   if (connection instanceof HttpURLConnection) {
                        HttpURLConnection conn = (HttpURLConnection) connection;
                        conn.setRequestMethod("POST");
                   OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());
                   osw.write(sb.toString());
                   osw.close();
                   // Now use sb to hold the resutls from the request
                   sb = new StringBuilder();
                   BufferedReader in = new BufferedReader(
                         new InputStreamReader(
                         connection.getInputStream()));
                   String s;
                   while ((s = in.readLine()) != null) {
                        sb.append(s);
                        // To make it more "human readable"
                        sb.append("\n");
                   in.close();
             } catch (IOException e) {
                  e.printStackTrace();
                  return null;
            return sb.toString();
    }

  • Need Help with data type conversion

    Hello People,
    I am new to java, i need some help with data type conversion:
    I have variable(string) storing IP Address
    IPAddr="10.10.103.10"
    I have to call a library function which passes IP Address and does something and returns me a value.
    The problem I have is that external function call in this library excepts IP Address in form of a byte array.
    Here is the syntax for the function I am calling through my program
    int createDevice (byte[] ipAddress).
    now my problem is I don't know how to convert the string  IPAddr variable into a byte[] ipAddress to pass it through method.

    Class InetAddress has a method
    byte[]      getAddress() You can create an instance using the static method getByName() providing the IP address string as argument.

  • Need help in date formatting

    Hi,
    I need to print date in the following format:
    Jan 21, 2007
    11:23 AM 21/01/2007
    21-01-2007 18:23
    Now as per condition of assignment the year, month, day and hour, min, sec all are entered as separate integer values.
    my code:
    import java.util.*;
    import java.text.*;
    public class stringToDate
    // Integer value of date and time variables
    int day=21;
    int month = 1;
    int year=07;
    int hour=18;
    int min=23;
    int sec=14;
    // Converting integer value into date
    public void convertIntoDate()
         String strTmp= day+"/"+month+"/"+year+" "+hour+":"+min+":"+sec;
         System.out.println("String: " + strTmp);
         DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
         try
              Date outDate = dateFormat.parse(strTmp);
              System.out.println("Converted: " + dateFormat.format(outDate));
         catch(Exception e){ System.out.println("Exception: " + e);}
    public static void main(String args[]) {
         stringToDate dF = new stringToDate();
         dF.convertIntoDate();
    }Now as per my code i am able to print in the following format:
    String: 21/1/7 18:23:14
    Converted: 21/01/0007 18:23:14
    But if i try to print in other formats it gives me following error message:
    Exception: java.text.ParseException: Unparseable date: "21/1/07"
    Please help me....

    vinee wrote:
    Hi,
    I tried different output format but still i'm facing the same issue
    Following the complete code and error message....
    import java.util.*;
    import java.text.*;
    public class stringToDate
    // Integer value of date and time variables
    int day=21;
    int month = 1;
    int year=07;
    int hour=18;
    int min=23;
    int sec=14;
    // Converting integer value into date
    public void convertIntoDate()
    DateFormat dateFormat;
    Date outDate=null;
    String strTmp= day+"/"+month+"/"+year+" "+hour+":"+min+":"+sec;
    System.out.println("Entered string for date: " + strTmp);
         // Format 01/01/0070 15:24:14
         dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
         try
         outDate = dateFormat.parse(strTmp);
         System.out.println("Converted into Date(dd/MM/yyyy HH:mm:ss): " + dateFormat.format(outDate));
         catch(Exception e){ System.out.println("Exception in format 1: " + e);}
         // Format Jan 21, 2007
         dateFormat = new SimpleDateFormat("EEE, MMM d, ''yyyy");
         try
         outDate = dateFormat.parse(strTmp);
         System.out.println("Converted into Date(EEE, MMM d, ''yyyy): " + dateFormat.format(outDate));
         catch(Exception fe)
         {System.out.println("Exception in format 2: " + fe);}
    public static void main(String args[]) {
              stringToDate dF = new stringToDate();
              dF.convertIntoDate();
    }Following is the error message:
    Entered string for date: 21/1/7 18:23:14
    Converted into Date(dd/MM/yyyy HH:mm:ss): 21/01/0007 18:23:14
    Exception in format 2: java.text.ParseException: Unparseable date: "21/1/7 18:23:14"
    Now as per the above error message format one is working fine but format 2(// Format Jan 21, 2007) have some issues...kind suggest.
    Edited by: vinee on Oct 2, 2008 4:23 AMPlease re-read my last reply.
    Once again : see [http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html]
    And your:
    int year=07; // should be:
    int year=2007;

  • Need help with a Class.

    Ok hey guys i got A project for school and i need help. I asked my teacher and he num so yea. here it is
    this is my blog class
    /* Project Name: .java
                 Name:
                Class: Programing 2 #0047-02 Pds 5&6
      Variable List:
                   Info:
    import java.util.Scanner;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class blog
         String date2;
         String user;
         String Entry;
         public void GetInfo(String Iuser,String IEntry)
              DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
              Date date = new Date();
              date2 = dateFormat.format(date);
              user = Iuser;
              Entry = IEntry:
         public void ShowInfo()
              System.out.println(date2 + " " + user + " Said: " + Entry);
    }This is my test class
    /* Project Name: .java
                 Name: Josh
                Class: Programing 2 #0047-02 Pds 5&6
      Variable List:
                   Info:
    import java.util.Scanner;
    public class test
         String user;
         String Entry;
         public static void main (String[] args)
         {     System.out.println("Welcome Please Eneter UserName");
              Scanner kb = new Scanner(System.in);
              user = kb.next();
              System.out.println("Please Enter Your Entry");
              Entry = kb.next();
              blog info = new blog();
              blog.GetInfo(user,Entry);
              blog.ShowInfo();
    }So what is sopost to do in the test it ask user to import user name and entery. It send it to blog Class, then it send it out. Here is my errors
    G:\VOC T2\Java\Chap4\test.java:21: non-static variable user cannot be referenced from a static context
              user = kb.next();
              ^
    G:\VOC T2\Java\Chap4\test.java:25: non-static variable Entry cannot be referenced from a static context
              Entry = kb.next();
              ^
    G:\VOC T2\Java\Chap4\test.java:29: non-static variable user cannot be referenced from a static context
              blog.GetInfo(user,Entry);
                           ^
    G:\VOC T2\Java\Chap4\test.java:29: non-static variable Entry cannot be referenced from a static context
              blog.GetInfo(user,Entry);
                                ^
    G:\VOC T2\Java\Chap4\test.java:29: GetInfo(java.lang.String,java.lang.String,java.lang.String) in blog cannot be applied to (java.lang.String,java.lang.String)
              blog.GetInfo(user,Entry);
                  ^
    G:\VOC T2\Java\Chap4\test.java:31: non-static method ShowInfo() cannot be referenced from a static context
              blog.ShowInfo();
                  ^
    6 errors
    Tool completed with exit code 1 Plez help

    -- "non-static X cannot be referenced from a static context" --
    You get this error because static members don't require an instance of the object to be accessed; they belong to the class. But a non-static member belongs to an instance (an individual object). There's no way for the static method to know which instance's variable to use or method to call, and thus, the compiler happily tells you that you can't access an instance member (non-static) from a class context (static).
    [The Java? Tutorial - Understanding Instance and Class Members|http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html]
    ~

  • Need help pulling data from an outside file into my array.  Please help  =)

    Hi,
    I need help adapting my array to read the interest rates from an outside file. Here is my code and the outside file I wrote. Please help. Oh, the array in question is on line 259, inside of my calculation() method.
    Thanks...
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    import java.io.*;
    import javax.swing.JOptionPane;
    public class Workshop5 extends JFrame implements ActionListener
         //declare gui components
         //declare labels
         JPanel contentPane = new JPanel();
         JPanel graphPane = new JPanel();
        JLabel instructionLabel = new JLabel();
        JLabel amountLabel = new JLabel();
         JLabel orLabel = new JLabel();
         JLabel comboBoxLabel = new JLabel();
         JLabel termLabel = new JLabel();
         JLabel rateLabel = new JLabel();
         JLabel calcLabel = new JLabel();
         JLabel paymentLabel = new JLabel();
         JLabel tableLabel = new JLabel();
         //declare font object
         Font labelFont = new Font("Tahoma", Font.PLAIN, 16);
         //declare text fields
         JTextField amountField = new JTextField(20);    
         JTextField termField = new JTextField(20);     
         JTextField rateField = new JTextField(20);
         JTextField paymentField= new JTextField(20);
         //declare combo box for loan selection
         JComboBox comboBox = new JComboBox();
        //declare button group and radio buttons
        ButtonGroup buttonGroup = new ButtonGroup();
        JRadioButton enterRadioButton = new JRadioButton("Enter amount, term, & rate", true);
        JRadioButton selectRadioButton = new JRadioButton("Select a preset term/rate loan", false);
         //declare button objects
         JButton clearButton = new JButton();
        JButton calcButton = new JButton();
        JButton quitButton = new JButton();
         //declare text area for amortization
         JTextArea amortTextArea = new JTextArea();
         JTextArea testTextArea = new JTextArea();
         //declare scroll bar for amortization table
         JScrollPane scrollPane = new JScrollPane(amortTextArea,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
         public Workshop5()
              instructionLabel.setText("Choose one of the following payment calculation options:");
              instructionLabel.setFont(new Font("Tahoma",Font.PLAIN,16));
              //adds both buttons to button group     
              buttonGroup.add(enterRadioButton);
              buttonGroup.add(selectRadioButton);
              enterRadioButton.setFont(labelFont);
              enterRadioButton.setBackground(Color.WHITE);
              enterRadioButton.setContentAreaFilled(false);
             enterRadioButton.addActionListener(this); //adds action listener to enter radio button
              orLabel.setText("OR");
              orLabel.setFont(new Font("Tahoma",Font.BOLD,18));
              selectRadioButton.setFont(labelFont);
              selectRadioButton.setBackground(Color.WHITE);
              selectRadioButton.setContentAreaFilled(false);
              selectRadioButton.addActionListener(this); //adds action listener to select radio button
              amountLabel.setText("Enter mortgage amount");
              amountLabel.setFont(new Font("Tahoma", Font.PLAIN,16));
              amountField.requestFocusInWindow();
              termLabel.setText("Enter term length in years:");
              termLabel.setFont(new Font("Tahoma", Font.PLAIN,14));
              rateLabel.setText("Enter interest rate:");
             rateLabel.setFont(new Font("Tahoma", Font.PLAIN,14));
                comboBoxLabel.setText("Select a loan:");
             comboBoxLabel.setFont(new Font("Tahoma", Font.PLAIN,14));
             comboBox.setBackground(new Color(255,255,255));
             comboBox.setFont(new Font("Tahoma", Font.PLAIN, 14));
             comboBox.setEnabled(false);
             ComboBox();
              calcLabel.setText("Press Calculate button to determine monthly payment.");
             calcLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
             calcButton.setText("Calculate");                    
             calcButton.setFont(new Font("Tahoma", Font.BOLD, 14));
             calcButton.addActionListener(this);
                //define monthly payment label
             paymentLabel.setText("Monthly payment:");
             paymentLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
             //define monthly payment text field
             paymentField.setFont(new Font("Tahoma", Font.BOLD,16));
             paymentField.setBackground(new Color(255,255,255));
             paymentField.setEditable(false); 
              //define clear button
              clearButton.setText("Clear"); 
              clearButton.setFont(new Font("Tahoma", Font.BOLD,14));
              clearButton.addActionListener(this);
              //define quit button
              quitButton.setText("Quit");
              quitButton.setFont(new Font("Tahoma", Font.BOLD,14));
              quitButton.addActionListener(this);         
              tableLabel.setText("Amoritization Table");
              tableLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
              graphPane.setBackground(Color.WHITE);
              //add components to content     
              getContentPane().add(contentPane);
              contentPane.setLayout(null);
              addComponent(contentPane, instructionLabel, 80,10,450,26);
              addComponent(contentPane, enterRadioButton, 30,40,220,30);
              addComponent(contentPane, orLabel, 280,40,100,30);
              addComponent(contentPane, selectRadioButton, 335,40,350,30);
              addComponent(contentPane, amountLabel, 100,80,220,26);
              addComponent(contentPane, amountField, 300,80,150,26);
              addComponent(contentPane, termLabel, 15,125,200,30);
              addComponent(contentPane, termField, 195,125,125,30);
              addComponent(contentPane, rateLabel, 62,160,200,30);
              addComponent(contentPane, rateField, 195,165,125,30);
              addComponent(contentPane, comboBoxLabel, 400,125,200,26);
              addComponent(contentPane, comboBox, 400,155,150,30);
              addComponent(contentPane, calcLabel, 100,200,400,30);
              addComponent(contentPane, calcButton, 250,240,100,30);
              addComponent(contentPane, paymentLabel, 150,285,200,30);
              addComponent(contentPane, paymentField, 300,285,100,30);
              addComponent(contentPane, clearButton, 100,330,100,30);
              addComponent(contentPane, quitButton, 400,330,100,30);
              addComponent(contentPane, tableLabel, 200,370,300,26);
              addComponent(contentPane, scrollPane, 10,400,450,360);
              addComponent(contentPane, graphPane, 475,400,305,360);
              //add window listener to close window when user presses X
              addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)    
                        System.exit(0);
             pack();   
         //method to add components
         private void addComponent(Container container, Component c, int x, int y, int width, int height)
              c.setBounds(x, y, width, height);
              container.add(c);
         //action performed method
         public void actionPerformed(ActionEvent event)
              Object source = event.getSource();
              if (source == calcButton)
                   Calculate();
              if (source == clearButton)
                   Clear();
              if (source == quitButton)
                   Exit();
              //defines active area based on user selection of mortgage calculation method
               //if user chooses to enter the mortgage manually, combo box fields are inactive
               if (source == enterRadioButton)
                    comboBox.setEnabled(false);
                    termField.setEnabled(true);
                 termField.setEditable(true);
                 rateField.setEnabled(true);
                 rateField.setEditable(true);
                 amountField.setText("");
                   amountField.requestFocusInWindow();
                   termField.setText("");
                  rateField.setText("");
                  paymentField.setText("");
                  amortTextArea.setText("");
              //if user chooses to select from a preset mortgage, rate and term fields are inactive
              if (source == selectRadioButton)
                   comboBox.setEnabled(true);
                   termField.setEnabled(false);
                   termField.setEditable(false);
                   rateField.setEnabled(false);
                   rateField.setEditable(false);
                   amountField.setText("");
                   amountField.requestFocusInWindow();
                   termField.setText("");
                   rateField.setText("");
                   paymentField.setText("");
                   amortTextArea.setText("");
         }//end of action performed method
         //combo box method
          public void ComboBox()
               String[] LoanArray = {" 7 years at 5.35 %", " 15 years at 5.50 %", " 30 years at 5.75 %"};
               for (int i = 0; i < LoanArray.length; i++)
                    comboBox.addItem(LoanArray);
         }//end combo box method
         //calculation method
         void Calculate()
              //resets fields
              paymentField.setText("");
         amortTextArea.setText("");
              //calculation variables
         NumberFormat currency = NumberFormat.getCurrencyInstance();
              int [] termArray = {7, 15, 30};                               //array of years
                   double [] yearlyInterestArray = {5.35, 5.5, 5.75};           //array of interest
                   int totalMonths = 0;                                    //total months
                   double Loan = 0.0;                               //amount of loan
                   double MonthlyInterest = 0.0;                               //monthly interest rate
                   double Payment = 0.0;                               //calculate payment
                   double monthlyPayment = 0.0;                                   //calculate monthly payment
                   double Interest = 0.0;                                              //variable for Interest Array input
                   int Term = 0;                                              //variable for Term Array input
                   double NewMonthlyInterest = 0.0;                               //new interest amount
                   double NewLoan = 0.0;                               //new loan amount
                   double Reduction = 0.0;                               //principle reduction
                   //validate input
                   try
                        Loan = Double.parseDouble(amountField.getText());
                   catch (NumberFormatException e)
                        JOptionPane.showMessageDialog(null,"Invalid Entry. Please enter valid loan amount.", "Error", JOptionPane.WARNING_MESSAGE);
                   //resets input fields after error message
              amountField.setText("");
              amountField.requestFocusInWindow();
                   //if select button is chosen
              if (selectRadioButton.isSelected())
                   int index = comboBox.getSelectedIndex();
                   Term = termArray[index];
                   Interest = yearlyInterestArray[index];
              //if user chooses to enter mortgage information
              else
                   if (enterRadioButton.isSelected())
                        //validates input
              try
              Term = Integer.parseInt(termField.getText());
              catch (NumberFormatException e)
                   JOptionPane.showMessageDialog(null,"Invalid entry. Please enter valid term length in years.", "Error",JOptionPane.WARNING_MESSAGE);
                   //clears fields after error message
                   termField.setText("");
                   termField.requestFocusInWindow();
              try
                   Interest = Double.parseDouble(rateField.getText());
              catch (NumberFormatException e)
                   JOptionPane.showMessageDialog(null,"Invalid entry. Please enter valid rate (without percent symbol).","Error",JOptionPane.WARNING_MESSAGE);
              //clears fields after error message
              rateField.setText("");
                             rateField.requestFocusInWindow();
                   //perform calculations
                   if (Loan > 0)
                        Loan = Double.parseDouble(amountField.getText());
                        MonthlyInterest = (Interest / 12)/100;
                        totalMonths = Term * 12;
                        monthlyPayment = Loan * MonthlyInterest *(Math.pow((1 + MonthlyInterest), totalMonths)/(Math.pow((1 + MonthlyInterest), totalMonths)-1));
              paymentField.setText("" + currency.format(monthlyPayment));
                        //send information to amortization text area
                   amortTextArea.append("Number\t");
                   amortTextArea.append(" Amount\t");
                   amortTextArea.append("Interest\t");
                   amortTextArea.append("Principle\t");
                   amortTextArea.append("Balance\n");
              NewLoan = Loan;
                        for (int i = 1; i <= totalMonths; i++)
                             NewMonthlyInterest = MonthlyInterest * NewLoan;
                             Reduction = monthlyPayment - NewMonthlyInterest;
                             NewLoan = NewLoan - Reduction;
                             amortTextArea.append(" " + i +"\t");
                             amortTextArea.append(" " + currency.format(monthlyPayment) + "\t");
                             amortTextArea.append(" " + currency.format(NewMonthlyInterest)+ "\t");
                             amortTextArea.append(" " + currency.format(Reduction) + "\t");
                             amortTextArea.append(" " + currency.format(NewLoan) + "\n");
                        //resets fields if loan amount is less than zero
                        if((Loan <= 0 || Term <= 0 || Interest <= 0))
                             paymentField.setText("");
                             amortTextArea.setText("");
         }//end calcualtion method
         //clear method
         void Clear()
              amountField.setText("");
              amountField.requestFocusInWindow();
              termField.setText("");
              rateField.setText("");
              paymentField.setText("");
              amortTextArea.setText("");
         }//end of clear method
         //main method
         public static void main(String args[])
              Workshop5 f = new Workshop5();
              f.setTitle("Carol's Mortgage Calculator");
              f.setBounds(200,100,800,800);
              f.setResizable(false);
              f.setVisible(true);
         }//end of main method
         //exit method
         void Exit()
              System.exit(0);
         }//end of exit method
    }//program end
    My data file is called: "InterestData.dat" and only contains the following text:
    5.35, 5.5, 5.75

    Ok, now I am getting this error message:
    cannot resolve symbol method lenght()
    Please help me out here, this is due tomorrow and I've been killing myself on it...
    attaching program with revised code included, see beginning of calculation method line 250:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.* ;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    import java.io.*;
    import javax.swing.JOptionPane;
    public class Workshop5 extends JFrame implements ActionListener
         //declare gui components
        //declare labels
        JPanel contentPane = new JPanel();
         JPanel graphPane = new JPanel();
         JLabel instructionLabel = new JLabel();
            JLabel amountLabel = new JLabel();
        JLabel orLabel = new JLabel();
        JLabel comboBoxLabel = new JLabel();
        JLabel termLabel = new JLabel();
        JLabel rateLabel = new JLabel();
        JLabel calcLabel = new JLabel();
        JLabel paymentLabel = new JLabel();
        JLabel tableLabel = new JLabel();
        //declare font object
        Font labelFont = new Font("Tahoma", Font.PLAIN, 16);
        //declare text fields
        JTextField amountField = new JTextField(20);
        JTextField termField = new JTextField(20);
        JTextField rateField = new JTextField(20);
        JTextField paymentField= new JTextField(20);
        //declare combo box for loan selection
        JComboBox comboBox = new JComboBox();
            //declare button group and radio buttons
            ButtonGroup buttonGroup = new ButtonGroup();
            JRadioButton enterRadioButton = new JRadioButton("Enter amount, term, & rate", true);
            JRadioButton selectRadioButton = new JRadioButton("Select a preset term/rate loan", false);
        //declare button objects
        JButton clearButton = new JButton();
            JButton calcButton = new JButton();
            JButton quitButton = new JButton();
        //declare text area for amortization
        JTextArea amortTextArea = new JTextArea();
        JTextArea testTextArea = new JTextArea();
        //declare scroll bar for amortization table
        JScrollPane scrollPane = new JScrollPane(amortTextArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
         public Workshop5()
             instructionLabel.setText("Choose one of the following payment calculation options:");
            instructionLabel.setFont(new Font("Tahoma",Font.PLAIN,16));
            //adds both buttons to button group
            buttonGroup.add(enterRadioButton);
            buttonGroup.add (selectRadioButton);
            enterRadioButton.setFont(labelFont);
            enterRadioButton.setBackground(Color.WHITE);
            enterRadioButton.setContentAreaFilled(false);
            enterRadioButton.addActionListener(this); //adds action listener to enter radio button
            orLabel.setText("OR");
            orLabel.setFont(new Font("Tahoma",Font.BOLD,18));
            selectRadioButton.setFont(labelFont);
            selectRadioButton.setBackground(Color.WHITE);
            selectRadioButton.setContentAreaFilled(false);
            selectRadioButton.addActionListener (this); //adds action listener to select radio button
              amountLabel.setText("Enter mortgage amount");
            amountLabel.setFont(new Font("Tahoma", Font.PLAIN,16));
            amountField.requestFocusInWindow();
            termLabel.setText("Enter term length in years:");
            termLabel.setFont(new Font("Tahoma", Font.PLAIN,14));
            rateLabel.setText("Enter interest rate:");
            rateLabel.setFont(new Font("Tahoma", Font.PLAIN,14));
            comboBoxLabel.setText("Select a loan:");
            comboBoxLabel.setFont(new Font("Tahoma", Font.PLAIN,14));
            comboBox.setBackground(new Color(255,255,255));
            comboBox.setFont(new Font("Tahoma", Font.PLAIN, 14));
            comboBox.setEnabled(false);
            ComboBox();
            calcLabel.setText("Press Calculate button to determine monthly payment.");
            calcLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
            calcButton.setText("Calculate");
            calcButton.setFont(new Font("Tahoma", Font.BOLD, 14));
            calcButton.setBackground(new Color(202,255,112));
            calcButton.addActionListener(this);
            //define monthly payment label
            paymentLabel.setText("Monthly payment:");
            paymentLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
            //define monthly payment text field
            paymentField.setFont (new Font("Tahoma", Font.BOLD,16));
            paymentField.setBackground(new Color(255,255,255));
            paymentField.setEditable(false);
              //define clear button
            clearButton.setText("Clear");
            clearButton.setFont(new Font("Tahoma", Font.BOLD,14));
            clearButton.setBackground(new Color(202,255,112));
            clearButton.addActionListener(this);
            //define quit button
            quitButton.setText("Quit");
            quitButton.setFont(new Font("Tahoma", Font.BOLD,14));
            quitButton.setBackground(new Color(202,255,112));
            quitButton.addActionListener(this);
              //define label for amortization table
            tableLabel.setText ("Amoritization Table");
              tableLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
            graphPane.setBackground(Color.WHITE);
            //add components to content
            getContentPane().add(contentPane);
            contentPane.setLayout(null);
              addComponent(contentPane, instructionLabel, 80,10,450,26);
            addComponent(contentPane, enterRadioButton, 30,40,220,30);
            addComponent(contentPane, orLabel, 280,40,100,30);
            addComponent(contentPane, selectRadioButton, 335,40,350,30);
            addComponent(contentPane, amountLabel, 100,80,220,26);
            addComponent(contentPane, amountField, 300,80,150,26);
            addComponent(contentPane, termLabel, 15,125,200,30);
            addComponent(contentPane, termField, 195,125,125,30);
            addComponent(contentPane, rateLabel, 62,160,200,30);
            addComponent(contentPane, rateField, 195,165,125,30);
            addComponent(contentPane, comboBoxLabel, 400,125,200,26);
            addComponent(contentPane, comboBox, 400,155,150,30);
            addComponent(contentPane, calcLabel, 100,200,400,30);
            addComponent(contentPane, calcButton, 250,240,100,30);
            addComponent(contentPane, paymentLabel, 150,285,200,30);
            addComponent(contentPane, paymentField, 300,285,100,30);
            addComponent(contentPane, clearButton, 100,330,100,30);
            addComponent(contentPane, quitButton, 400,330,100,30);
            addComponent(contentPane, tableLabel, 200,370,300,26);
            addComponent(contentPane, scrollPane, 10,400,450,360);
            addComponent(contentPane, graphPane, 475,400,305,360);
            //add window listener to close window when user presses X
            addWindowListener(new WindowAdapter()
                 public void windowClosing(WindowEvent e)
                      System.exit(0);
            pack();
           //method to add components
           private void addComponent(Container container, Component c, int x, int y, int width, int height)
                   c.setBounds(x, y, width, height);
                   container.add(c);
           //action performed method
           public void actionPerformed(ActionEvent event)
                   Object source = event.getSource();
                   if (source == calcButton)
                           Calculate();
                   if (source == clearButton)
                           Clear();
                   if (source == quitButton)
                           Exit();
                   //defines active area based on user selection of mortgage calculation method
                   //if user chooses to enter the mortgage manually, combo box fields are inactive
                   if (source == enterRadioButton)
                           comboBox.setEnabled(false);
                           termField.setEnabled(true);
                   termField.setEditable(true);
                   rateField.setEnabled(true);
                   rateField.setEditable(true);
                   amountField.setText ("");
                           amountField.requestFocusInWindow();
                           termField.setText("");
                       rateField.setText("");
                       paymentField.setText ("");
                       amortTextArea.setText("");
                   //if user chooses to select from a preset mortgage, rate and term fields are inactive
                   if (source == selectRadioButton)
                           comboBox.setEnabled(true);
                           termField.setEnabled(false);
                           termField.setEditable(false);
                           rateField.setEnabled (false);
                           rateField.setEditable(false);
                           amountField.setText("");
                           amountField.requestFocusInWindow();
                           termField.setText ("");
                           rateField.setText("");
                           paymentField.setText("");
                           amortTextArea.setText("");
           }//end of action performed method
           //combo box method
            public void ComboBox()
                   String[] LoanArray = {" 7 years at 5.35 %", " 15 years at 5.50 %", " 30 years at 5.75 %"};
                   for (int i = 0; i < LoanArray.length; i++)
                           comboBox.addItem(LoanArray);
    }//end combo box method
    //calculation method
         void Calculate()
              //resets fields
              paymentField.setText("");
              amortTextArea.setText("");
              //calculation variables
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              //declare input stream object
              InputStream istream;
              //create a file object to refer to the outside file
              File interestData = new File("InterestFile.dat");
              //assign instream to the new file object
              istream = new FileInputStream(interestData);
              try
                   StringBuffer sb = new StringBuffer();
                   BufferedReader in = new BufferedReader(new FileReader(interestData));
                   String line = "";
                   while((line = in.readLine()) != null)
                        sb.append(line);
                   in.close();
                   String fileData = sb.toString();
                   String[] splitData = fileData.split(", ");
                   double [] yearlyInterestArray = new double[splitData.length()];
                   for(int j = 0; j < splitData.length(); j++)
                        yearlyInterestArray[j] = new Double(splitData[j]).doubleValue();
              catch (IOException e)
                   JOptionPane.showMessageDialog(null, "File does not exist." + e.getMessage());
              int [] termArray = {7, 15, 30}; //array of years
              double [] yearlyInterestArray = { 5.35, 5.5, 5.75}; //array of interest
              int totalMonths = 0; //total months
              double Loan = 0.0; //amount of loan
              double MonthlyInterest = 0.0; //monthly interest rate
              double Payment = 0.0; //calculate payment
    double monthlyPayment = 0.0; //calculate monthly payment
    double Interest = 0.0; //variable for Interest Array input
    int Term = 0; //variable for Term Array input
    double NewMonthlyInterest = 0.0; //new interest amount
    double NewLoan = 0.0; //new loan amount
    double Reduction = 0.0; //principle reduction
    //validate input
    try
         Loan = Double.parseDouble(amountField.getText());
    catch (NumberFormatException e)
         JOptionPane.showMessageDialog(null,"Invalid Entry. Please enter valid loan amount.", "Error", JOptionPane.WARNING_MESSAGE);
    //resets input fields after error message
    amountField.setText("");
    amountField.requestFocusInWindow ();
              //if select button is chosen
              if (selectRadioButton.isSelected())
                   int index = comboBox.getSelectedIndex ();
                   Term = termArray[index];
                   Interest = yearlyInterestArray[index];
              //if user chooses to enter mortgage information
              else
                   if (enterRadioButton.isSelected())
              //validates input
              try
                   Term = Integer.parseInt(termField.getText());
    catch (NumberFormatException e)
         JOptionPane.showMessageDialog(null,"Invalid entry. Please enter valid term length in years.", "Error",JOptionPane.WARNING_MESSAGE);
         //clears fields after error message
         termField.setText("");
         termField.requestFocusInWindow();
    try
         Interest = Double.parseDouble(rateField.getText());
    catch (NumberFormatException e)
         JOptionPane.showMessageDialog(null,"Invalid entry. Please enter valid rate (without percent symbol).","Error",JOptionPane.WARNING_MESSAGE);
         //clears fields after error message
         rateField.setText("");
         rateField.requestFocusInWindow();
              //perform calculations
              if (Loan > 0)
                   Loan = Double.parseDouble(amountField.getText ());
                   MonthlyInterest = (Interest / 12)/100;
                   totalMonths = Term * 12;
                   monthlyPayment = Loan * MonthlyInterest *(Math.pow ((1 + MonthlyInterest), totalMonths)/(Math.pow((1 + MonthlyInterest), totalMonths)-1));
    paymentField.setText("" + currency.format(monthlyPayment));
    //send information to amortization text area
    amortTextArea.append("Number\t");
    amortTextArea.append(" Amount\t");
    amortTextArea.append("Interest\t");
    amortTextArea.append("Principle\t");
    amortTextArea.append("Balance\n");
                   NewLoan = Loan;
                   for (int i = 1; i <= totalMonths; i++)
         NewMonthlyInterest = MonthlyInterest * NewLoan;
         Reduction = monthlyPayment - NewMonthlyInterest;
         NewLoan = NewLoan - Reduction;
         amortTextArea.append(" " + i +"\t");
         amortTextArea.append (" " + currency.format(monthlyPayment) + "\t");
         amortTextArea.append(" " + currency.format(NewMonthlyInterest)+ "\t");
         amortTextArea.append(" " + currency.format(Reduction) + "\t");
         amortTextArea.append(" " + currency.format(NewLoan) + "\n");
    //resets fields if loan amount is less than zero
    if((Loan <= 0 || Term <= 0 || Interest <= 0))
         paymentField.setText("");
         amortTextArea.setText("");
         }//end calcualtion method
    //clear method
    void Clear()
    amountField.setText("");
    amountField.requestFocusInWindow();
    termField.setText("");
    rateField.setText("");
    paymentField.setText("");
    amortTextArea.setText("");
    }//end of clear method
    //main method
    public static void main(String args[])
    Workshop5 f = new Workshop5();
    f.setTitle("Carol's Mortgage Calculator");
    f.setBounds(200,100,800,800);
    f.setResizable(false);
    f.setVisible(true);
    }//end of main method
    //exit method
    void Exit()
    System.exit(0);
    }//end of exit method
    }//program end

  • Urgent : Need help in parsing XML from Sharepoint and save it into DB

    Hi ,
    I am Sharepoint guy and a newbie in Oracle . PL/SQL
    I am using UTL_DBWS Package to call a Sharepoint WebService " and was sucessfull , Now the xml has to be parsed and stored into a Table. I am facing the issue as the XML has a different namesoace and normal XPATH query is not working
    Below is the XML and need help in parsing it
    declare
    responsexml sys.XMLTYPE;
    testparsexml sys.XMLTYPE;
    begin
    responsexml := sys.XMLTYPE('<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <GetListItemsResult>
    <listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
    <rs:data ItemCount="2">
    <z:row ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Test Title 1" ows_ID="1" ows_owshiddenversion="1" ows_UniqueId="1;#{9C45D54E-150E-4509-B59A-DB5A1B97E034}" ows_FSObjType="1;#0" ows_Created="2009-09-12 17:13:16" ows_FileRef="1;#Lists/Tasks/1_.000"/>
    <z:row ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Testing Tasks" ows_ID="2" ows_owshiddenversion="1" ows_UniqueId="2;#{8942E211-460B-422A-B1AD-1347F062114A}" ows_FSObjType="2;#0" ows_Created="2010-02-14 16:44:40" ows_FileRef="2;#Lists/Tasks/2_.000"/>
    </rs:data>
    </listitems>
    </GetListItemsResult>
    </GetListItemsResponse>');
    testparsexml := responsexml.extract('/GetListItemsResponse/GetListItemsResult/listitems/rs:data/z:row/@ows_Title');
    DBMS_OUTPUT.PUT_LINE(testparsexml.extract('/').getstringval());
    end;
    The issue is with rs:data , z:row nodes.... please suggest how to handle these kind of namespaces in Oracle
    I need the parse the attribute "ows_Title" and save it into a DB
    this script would generate "Error occured in XML Parsing"
    Help is appriciated, thanks for looking

    SQL> SELECT *
      FROM XMLTABLE (
              xmlnamespaces ('http://schemas.microsoft.com/sharepoint/soap/' as "soap",
                             '#RowsetSchema' AS "z"
              'for $i in //soap:*//z:row return $i'
              PASSING xmltype (
                         '<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <GetListItemsResult>
    <listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
    <rs:data ItemCount="2">
    <z:row ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Test Title 1" ows_ID="1" ows_owshiddenversion="1" ows_UniqueId="1;#{9C45D54E-150E-4509-B59A-DB5A1B97E034}" ows_FSObjType="1;#0" ows_Created="2009-09-12 17:13:16" ows_FileRef="1;#Lists/Tasks/1_.000"/>
    <z:row ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Testing Tasks" ows_ID="2" ows_owshiddenversion="1" ows_UniqueId="2;#{8942E211-460B-422A-B1AD-1347F062114A}" ows_FSObjType="2;#0" ows_Created="2010-02-14 16:44:40" ows_FileRef="2;#Lists/Tasks/2_.000"/>
    </rs:data>
    </listitems>
    </GetListItemsResult>
    </GetListItemsResponse>')
    columns ows_MetaInfo varchar2(20) path '@ows_MetaInfo',
             ows_Title varchar2(20) path '@ows_Title',
             ows__ModerationStatus varchar2(20) path '@ows__ModerationStatus'
    OWS_METAINFO         OWS_TITLE            OWS__MODERATIONSTATUS
    1;#                  Test Title 1         0                   
    2;#                  Testing Tasks        0                   
    2 rows selected.

  • Need help with date range searches for Table Sources in SES

    Hi all,
    I need help, please. I am trying to satisfy a Level 1 client requirement for the ability to search for records in crawled table sources by a date and/or date range. I have performed the following steps, and did not get accurate results from Advanced searching for date. Please help me understand what I am doing wrong, and/or if there is a way to define a date search attribute without creating a LOV for a date column. (My tables have 500,00 rows.)
    I am using SES 10.1.8.3 on Windows 32.
    My Oracle 10g Spatial Table is called REPORTS and this table has the following columns:
    TRACKNUM Varchar2
    TITLE Varchar2
    SUMMARY CLOB
    SYMBOLCODE Varchar2
    Timestamp Date
    OBSDATE Date
    GEOM SDO_GEOMETRY
    I set up the REPORTS table source in SES, using TRACKNUM as the Primary Key (unique and not null), and SUMMARY as the CONTENT Column. In the Table Column Mappings I defined TITLE as String and TITLE.
    Under Global Settings > Search Attributes I defined a new Search Attribute (type Date) called DATE OCCURRED (DD-MON-YY).
    Went back to REPORTS source previously defined and added a new Table Column Mapping - mapping OBSDATE to the newly defined DATE OCCURRED (DD-MON-YY) search attribute.
    I then modified the Schedule for the REPORTS source Crawler Policy to “Process All Documents”.
    Schedule crawls and indexes entire REPORTS table.
    In SES Advanced Search page, I enter my search keyword, select Specific Source Group as REPORTS, select All Match, and used the pick list to select the DATE OCCURRED (DD-MON-YY) Attribute Name, operator of Greater than equal, and entered the Value 01-JAN-07. Then the second attribute name of DATE_OCCURRED (DD-MON-YY), less than equals, 10-JAN-07.
    Search results gave me 38,000 documents, and the first 25 I looked at had dates NOT within the 01-JAN-07 / 10-JAN-07 range. (e.g. OBSDATE= 10-MAR-07, 22-SEP-07, 02-FEB-08, etc.)
    And, none of the results I opened had ANY dates within the SUMMARY CLOB…in case that’s what was being found in the search.
    Can someone help me figure out how to allow my client to search for specific dated records in a db table using a single column for the date? This is a major requirement and they are anxiously awaiting my solution.
    Thanks very much, in advance….

    raford,
    Thanks very much for your reply. However, from what I've read in the SES Admin Document is that (I think) the date format DD/MM/YYYY pertains only to searches on "file system" sources (e.g. Word, Excel, Powerpoint, PDF, etc.). We have 3 file system sources among our 25 total sources. The remaining 22 sources are all TABLE or DATABASE sources. The DBA here has done a great job getting the data standardized using the typical/default Oracle DATE type format in our TABLE sources (DD-MON-YY). Our tables have anywhere from 1500 rows to 2 million rows.
    I tested your theory that the dates we are entering are being changed to Strings behind the scenes and on the Advanced Page, searched for results using OBSDATE equals 01/02/2007 in an attempt to find data that I know for certain to be in the mapped OBSDATE table column as 01-FEB-07. My result set contained data that had an OBSDATE of 03-MAR-07 and none containing 01-FEB-07.
    Here is the big issue...in order for my client to fulfill his primary mission, one of the top 5 requirements is that he/she be able to find specific table rows that are contain a specific date or range of dates.
    thanks very much!

Maybe you are looking for