HELP, date class and parsing input

I have reviewed many posts in these forums and have found that detail gets the best results so I apologize in advance if this is detailed. I am taking a Java class and am not doing so hot. The last time I programmed was in 1998 and that was Ada, I very soon moved to Networking. I guess those that can't program become networkers, I don't know, but I am frustrated here.
Any how I am trying to write a rather simple program, but it is the manipulation of the date I am having difficulty with. Here are the requirements:
Overall Requirements
Create a class named Date that stores date values and prints out the date in either a pure numeric format or a name and number format (see sample session for format details).
Date.java class file
? Date objects should store the date in two int instance variables ─ day and month, and it should include the String instance variable, error, initialized with null.
Implement a 1-parameter Date constructor that receives a dateStr string parameter and performs complete error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error checking. That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value, using an appropriate concatenation of a string constant, input substring, and/or API exception message.
Constructors use the same exception handling rules as methods: In a try block, include the parsing of the month and day substrings and other error-checking logic that will not work if parsing fails.
? Take into account the actual number of days in each month, but assume that there are always 28 days in February.
? To extract day and month numbers from the given date string, use String?s indexOf method to find the location of the slash character, and String?s substring method to extract month and day substrings from the input string.
? Include a method for printing the date with a numeric format. Use the zero-pad flag in a printf method call to get exactly two digits for each month and day.
? Include a method for printing the date with an alphabetic format.
Include a getError method which returns the value of the error instance variable.
DateDriver.java class file : In your driver class, include a loop that repeatedly:
? Asks the user to enter a date or ?q? to quit. ? If the entry is not ?q?, instantiate a Date object.
? If the error variable is null: o Print the date using numeric format.o Print the date using alphabetic format. Otherwise, print the value of the error variable.
I want to figure this out on my own as much as possible but have until tomorrow night to do so..............I need to understand how I can use Strings indexOf to parse the dateStr so I can locate the /. I see I can use it to find the position of a specified character, but I am not sure of the syntax I need to use. But then once I find the / I need to use the String's substring method to extract month and day. I think I might be able to get that, if I can get the / figured out.
The below is what I have in my Class and my Driver so far:
*DateDriver.java (driver program)
* Christine Miller-Lane
*Overall Requirements
*Create a class named Date that stores date values and prints out the date in either a pure numeric
format or a name and number
*format (see sample session for format details).
*DateDriver.java class file
*In your driver class,
*????????? If the error variable is null:
*     ◦     Otherwise, print the value of the error variable.
import java.util.*;
public class DateDriver
Date datevalue;
public static void main(String[] args)
     Scanner stdIn = new Scanner(System.in);
     while (!xStr.equalsIgnoreCase("q"))
     try
          System.out.println("Enter a date in the form mm/dd ("q" to quit): ";
          value = stdIn.nextLine();
          datevalue = new Date(value);                                                        //instaniate the date object
          System.out.println //print date in numeric format
          System.out.println //print date in alphabetic format
          break;
          catch
          System.out.println("print value of error variable.");
          stdIn.next(); // Invalid input is still in the buffer so flush it.
     } //endloop
     }//end main
} //end class?
* Date.java
* Christine Miller-Lane
*Overall Requirements
*Create a class named Date that stores date values and prints out the date in either a pure numeric format or a name
*and number format (see sample session for format details).
*Date.java class file
*????????? Date objects should store the date in two int instance variables ─ day and month, and it should include
*the String instance variable, error, initialized with null.
*     ?     Implement a 1-parameter Date constructor that receives a dateStr string parameter and performs complete
*     error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error
*     checking. That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the
*     Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance
*     variable to a non-null string value, using an appropriate concatenation of a string constant, input substring,
*     and/or API exception message.?
*     ?     Constructors use the same exception handling rules as methods: In a try block, include the parsing of the
*     month and day substrings and other error-checking logic that will not work if parsing fails.
*????????? Take into account the actual number of days in each month, but assume that there are always 28 days in February.
*????????? To extract day and month numbers from the given date string, use String?s indexOf method to find the
*location of the slash character, and String?s substring method to extract month and day substrings from the input string.
import java.util.*;
public class Date
     Scanner stdIn = new Scanner(System.in);
     boolean valid = false
     int day;
     int month;
     String error = null;
     String dayStr;
     String monthStr;
     String dateStr;
     public Date(String dateStr)
// Look for the slash and set appropriate error if one isn't found. use String?s indexOf method to find the
//location of the slash character and String?s substring method to extract month and day substrings from the input string.
// Convert month portion to integer. Catch exceptions and set appropriate error if there are any.
Integer.parseInt(dateStr);
// Validate month is in range and set appropriate error if it isn't.
// Convert day portion to integer. Catch exceptions and set appropriate error if there are any.
// Validate day is in range based on the month (different days per month) and set appropriate error if it isn't.
//public void printDate()      //Include a method for printing the date with a numeric format. Use the zero-pad flag in a printf method
                                   //call to get exactly two digits for each month and day.
//{                                   //Include a method for printing the date with an alphabetic format.      
//     } // end print report
//     public getError()
                              //Include a getError method which returns the value of the error instance variable.
}//end class Date
Here is sample out put needed::::::::
Sample Session:
Enter a date in the form mm/dd ("q" to quit): 5/2
05/02
May 2
Enter a date in the form mm/dd ("q" to quit): 05/02
05/02
May 2
Enter a date in the form mm/dd ("q" to quit): 52
Invalid date format ? 52
Enter a date in the form mm/dd ("q" to quit): 5.0/2
Invalid format - For input string: "5.0"
Enter a date in the form mm/dd ("q" to quit): 13/2
Invalid month ? 13
Enter a date in the form mm/dd ("q" to quit): 2/x
Invalid format - For input string: "x"
Enter a date in the form mm/dd ("q" to quit): 2/30
Invalid day ? 30
Enter a date in the form mm/dd ("q" to quit): 2/28
02/28
February 28
Enter a date in the form mm/dd ("q" to quit): q
I am trying to attack this ONE STEP at a time, even though I only have until Sunday at midnight. I will leave this post and get some rest, then attack it again in the morning.
Edited by: stillTrying on Jul 12, 2008 8:33 PM

Christine,
You'r doing well so far... I like your "top down" approach. Rough out the classes, define ALL the methods, especially the public one... but just sketch out the requirements and/or implementation with a few comments. You'll do well.
(IMHO) The specified design is pretty crappy, especially the Exception handling
[The Constructor] performs complete error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error checking. That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value, using an appropriate concatenation of a string constant, input substring, and/or API exception message.Please allow me to shred this hubris piece by piece.
[The Constructor] performs complete error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error checking.Umm... Well I suppose it could... but NO, the constructor should delegate such "complex validation" to a dedicated validate (or maybe isValid) method... which might even be made publicly available... it's a good design.
That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value ...Utter Bollocks! When passed an invalid input string the, Date constructor should throw an InvalidDataException (or similar). It should not SILENTLY set some dodgy error errorMessage attribute, which is returned later by a "print" method. We tried that in masm, fortran, ada, basic, c, and pascal for twenty odd years. It sucked eggs. And it STILL sucks eggs. Java has a "proper" try/catch exception handling mechanism. Use it.
I mean, think it through...
  someDate = get a date from the user // user enters invalid date, so someDate is null and errMsg is set.
  report = generateReport() // takes (for the sake of argument) three hours.
  emailReport(someDate, report) // only to fail at the last hurdle with an InvalidDataException!And anyways... such implementation details are traditionally the implementors choice... ie: it's usually between the programmer and there tech-manager (if they're lucky enough to have one).
Cheers. Keith.

Similar Messages

  • Data class and storage class

    Hi ,
    I need some info or docs on data class and stroge class of DSO /cube.
    Regards
    tapashi

    Hi Tapashi,
    Something i found about dataclass in DSO/Cube, which might be useful to you.
    Within SAP BW following data class of DDIC objects are important:
    DDIM           Dimension Tables in BW of InfoCubes
    DFACT          Facts Table in BW of InfoCubes
    DODS           ODS Tables in BW
    These have been introduced in order to improve performance while reading/writing InfoProviders. Settings of data class are maintained in "Technical Settings -> Database storage parameters" screen of TA SE11. Data class is assigned to the database tables of the InfoCube (table RSDCUBE, RSDODSO). Notice that this assignment cannot be made by any circumstances by user, only system does this while you activate InfoProvider.
    Subsequently see overview of table RSDCUBEu2019s fields with link to data class according BW versions:
    SAP BW 3.x (parameters only affect aggregates, not the cube):
    AGGRDATCLS     Data class for aggregate fact tables (only aggregates)
    AGGRSIZCAT     Size category for aggregate fact tables
    ADIMDATCLS     Data class for aggregate dimension tables
    ADIMSIZCAT     Size category for aggregate dimension tables
    Furthermore see overview of RSDODSOu2019s fields for DSO objects as InfoProvider with link to data class:
    ODSADATCLS     Data class for table with active data of the ODS
    ODSMDATCLS     Data class for table with ODS input data
    To see all available data classes check table: DDART (DD: Data Class in Technical Settings)
    To see all available size categories check table: DGKAT (DD: Size category in technical settings)
    Hope this is helpful.
    Regards
    Snehith

  • Changing of data class and size category for keyfigures .

    Hi,
    I am not able to change the data class and size category for keyfigures .
    can you please let me know how to enable the changing of data class and size category for keyfigure under Maintain DB storage parameters.

    Ok then it sounds like your primary key of 8 fields and secondary index of 3 non-unique fields appear somewhat similar to the database and it wrongly uses the secondary index. Perhaps you can try to declare the table as a SORTED table with index fields as key. I doubt this will do any good, but you can try.
    You can try to deactivate the sec. index if it is not being used.
    Or by far the best but also debatable, try to pass hints to the SQL parser by %_hints statement. Please refer to SAP note 129385 for details on hints in general and note 772497 for various hints statements for  ORACLE DB. This will surely make the DB interface use the primary index and the update would be faster. But with 1 million records, hopefully you are not looking at response time in micro seconds, are you?
    rgds,
    Prabhu

  • Data class and Delivery class in ABAP Dictionary

    Hi all,
    I want to know the exact information about Data class and Delivery class in ABAP Dictionary
    Moderator message : Search for available information. Thread locked.
    Edited by: Vinod Kumar on Aug 3, 2011 1:35 PM

    As your name Suggests, there were exactly 21 rajapandian already who wanted exact information about  Data class and Delivery class. Fortunately some has found the information by own and some were dumped by SAP Police.
    Cheers
    Amit

  • Difference between Data Class and Delivery Class

    What is the Difference between Data Class and Delivery Class , what happens Phisically to the Data .
    Moderator message: what is the difference between your question and a question that we'd welcome here in the forums?
    [Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
    Edited by: Thomas Zloch on Nov 22, 2010 1:17 PM

    What is the Difference between Data Class and Delivery Class , what happens Phisically to the Data .
    Moderator message: what is the difference between your question and a question that we'd welcome here in the forums?
    [Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
    Edited by: Thomas Zloch on Nov 22, 2010 1:17 PM

  • Help required: Classes and class values for Func Loc

    Dear All,
    I have a requirement to get the classes and values associated with a functional location.
    Any idea how to get this data, as in IL03.
    Thanks,
    nsp.

    Hello nsp,
    You can try to check out the Function module ALM_ME_TOB_CLASSES to see how they fetched class, characteristics and their values.
    You can keep a break-point in this module and run MAM30_031_GETDETAIL and check how we can pass the appropriate values.
    However, above FMs are available from PI 2004.1 SP 14 of release 4.6c, 4.7 and 5.0.
    If you are in ERP 6.0, the FM's are available.
    Hope this helps
    Best Regards,
    Subhakanth

  • "iTunes unable to load data class" and "iTunes could not back up"

    Hello all.
    I had an issue and I also have found a work around - but will be glad if this issue will be fixed.
    The issue started only in 2013, in Israel.
    I get two messages.
    When connecting the iPhone to the computer (PC) I get the following message: "iTunes unable to load data class information from sync service". When I sync or try backup (I back up to the computer), I get the following message: "iTunes could not back up the iPhone....because the back up session faild". Backup does not succeed (but sync does).
    After many trials I got the following solution:
    When I change my time zone from Jerusalem to Cairo (same time zone) backaup is working fine. Moreover - even if I stay in Jerusalem's time zone but check off the "automatic adjust clockfor daylight saving time" - it works fine. The only time I have fault is when I am in Jerusalem time zone with "automatic adjust clockfor daylight saving time" checked ON.
    So that's the story.
    Any comment, or chance of a fix (the workaround is simple, so maybe this will help other people as well)
    Regards,
    Eyal

    One more elaboration - when I update the timezone - I mean - on the computer (not on the iPhone).
    BTW - I think this is connected to the fact that in Israel the daylaight saving time period is not constant
    BR
    Eyal

  • Help on classes and methods

    I have a date class with a method which is suppose to return the date value a user type in. But no matter what the input is, it keeps returning 0/0/0. really don't know what to do.
    Please help frustration is setting up quickly.
    import java.util.*;
    import static java.lang.System.in;
    import static java.lang.System.out;
    public class Date1 {
    protected int day;
         protected int month;
         protected int year;
         protected static final int MINYEAR = 1583;
         public Date1(int newMonth, int newDay, int newYear)throws DateOutOfBoundsException
                   if((newMonth <= 0) || (newMonth > 12)){
                        throw new DateOutOfBoundsException(" Month must be in the range 1 to 12");
                   }else{
                   int month = newMonth;};
                   int day = newDay;
                   if (newYear < MINYEAR){
                        throw new DateOutOfBoundsException(" Year : " + newYear + " is too early");
                   }else{
                             int year = newYear;};
         public int monthIs(){
              return month;
         public int dayIs(){
              return day;
         public int yearIs(){
              return year;
         public String toString(){
              return(month + "/" + day + "/" + year);
         public class DateOutOfBoundsException extends Exception {
         public DateOutOfBoundsException(){
              super();
         public DateOutOfBoundsException(String message){
              super(message);
         public static void main(String[] args)throws DateOutOfBoundsException{
              Scanner myScanner = new Scanner(in);
              Date1 theDate;
              int M, D, Y;
              out.print("Please Enter a month to check for its validity: ");
              M = myScanner.nextInt();
              out.print("Please Enter a day to check for its validity: ");
              D = myScanner.nextInt();
              out.print("Please Enter a year to check for its validity: ");
              Y = myScanner.nextInt();
              theDate = new Date1(M, D, Y);
              out.println(theDate);
    Edited by: edersio on Oct 25, 2007 11:44 AM

    ShoeNinja wrote:
    You can't just print the date object. I think what you meant to do was:
    out.println(theDate.toString());
    Nonsense. When you pass this object to out, its toString method will be invoked.
    The problem is in the constructor:
    int month = newMonth;This assigns newMonth to a local variable. To assign to a field, write:
    this.month = newMonth;or just
    month = newMonth;

  • Data Classes and cubes

    Hi
    Two questions:
    1. In which function in t-code RSDCUBE I can assign data class to cube?
    2. Is there any FM, program or table where i can find information about connetion CUBE => data class
    Regards
    Adam

    Hi Adam,
    You can see this in Infocube Maintanance
    Extras --> DB performance --> Maintain DB storage parameters
    You cannot change the setting if the infocube contains data.
    You can also see the settings for the fact table or dimension tables in SE12  --> technical settings.
    Best Regards,
    Vincent

  • BI7 Upgrade - Data Classes and Unicode Conversion

    It is mentioned that we need to Convert Data Classes of InfoCube, but I still dont quite understand. Do you know what exactly is this Data Classes mean?
    NW2004s upgrade
    Also, why do we need to perform Unicode Conversion during the 3.x to BI7 upgrade?
    Please advice.

    It is mentioned that we need to Convert Data Classes of InfoCube, but I still dont quite understand. Do you know what exactly is this Data Classes mean?
    NW2004s upgrade
    Also, why do we need to perform Unicode Conversion during the 3.x to BI7 upgrade?
    Please advice.

  • Filter xml data Class and use pushView to populate List (Flex Mobile project)

    I am such noob so I apologize for my ignorance. Trying to learn and work at the same time but i'm stumped been searching and my understanding is not up to snuff just yet.
    I looked at the Mobile Shopping Cart that Adobe has little over my head to grasp and impliment but my project is similar without the cart option basically.
    I'm currently using a single view with 3 states
    <s:states>
    <s:State name="default"/>
    <s:State name="productView"/>
    <s:State name="detailsView"/>
    </s:states>
    Default state has a list that uses a xml file with categoryID number's that correspond with the main products xml file.
    Which when the item is selected it filters and updates the List on the productView and so on to the detailsView.
    Like this:
    Category -> Products-> Details
    I'm using a filterCollection from an .as Class file to complete this here is a small snipet.
    private function productService_resultHandler(event:ResultEvent):void
    var productsArray:Array = new Array();
    var resultData:XMLList = event.result..product;
    for each (var p:XML in resultData) {
    var product:Product = Product.buildProductFromAttributes( p );
         productsArray.push( product );
    products = new ArrayCollection( productsArray );
         products.filterFunction = filterForCategory;
         products.refresh();
    private function filterForCategory(item:Product):Boolean{
    return item.catID == selectedCategory;
    public function filterCollection(id:Number):void{
    selectedCategory = id;
         products.refresh();
    Project works great but incredibly slow on Mobile device iOS. In-between the states I have transition animations and it bogs right down.
    So I was trying to experiment by using pushView and basically do the same but utilize Flex's viewNavigator to see if it speeds things up but I can't get the filter function to push the filtered data to the newView component.
    Or I was thinking of trying to order the events such as seletedItem->transition->filtered Data it seems like it is all happing at once and the app just sits for 3 seconds before the state is updated.
    Any help appreciated or more info needed let me know. THX

    So I will solve this later.
    I was able to stick to the original project layout with states within views instead of view states. Ditched the transition Move effects averaging 1 to 2 seconds on all state changes.
    It is a really basic product view app that all files are local. I'm not super impressed at the first go but it works and into the First Project archieve's and will revisit it on version 2. Which will probably start soon. It's better than hello world!

  • BDT - Business Data Toolset and batch input

    hi
    i want to creat batch input for transaction REBDBE .
    i use transaction shdb in order to creat batch input - i record my moved and the despite the messege that this table record was updated i go to the table using se11 and i dont see that it was NOT updated ( i am doing the same actions but without rcording and using shdb and table record was updated )
    does anyone has an idea what can cause that???
    thanks

    Does the problem happen when you
    1) do the (initial and only) record with SHDB,
    2) or is it when you execute the program generated by SHDB?
    For option 1), I think it can't happen, or there is a bug in the sap standard REBDBE (one possibility is that the standard tests for the SHDB mode and works differently from normal use, and there would be a bug in that case). In that case, ask sap support.
    If it's with option 2, did you try to do a screen by screen execution? (execution mode "A")
    You may also try to change another flag in the launch screen, there is a flag which by default stops the call transaction after the first commit work, sometimes it is a bad option. There is also another flag which allows to make the system believe it should work as in normal use instead of "batch input" mode.
    Other possibilities :
    - check that you don't have custom code in the standard programs
    - check that you have removed all breakpoints when you execute, it may disturb the screen processing when it displays debugger screen ; it may only happen if you use the "old debugger"
    Note that business data toolset usually proposes a direct input mode (see sap documentation), but that's far more complex to use than batch input.

  • Help: URL class and continue downloading

    My problem is how to continue downloading binary resource (via HTTP 1.1) after crash. I used URL to retrieve large RAR archive, and it was ok until 1.5 Mb, but suddenly it crashed.
    URL class told me, that it is ok. So, I want to make a new session and continue downloading.
    Could you help me?

    I believe as per HTTP standards , we need to do so.
    Please advice.Well first of all I don't see where you are encoding anything. Second what exactly are you encoding?
    Please show us the code of where you encode and what you encode.
    See you in two weeks.

  • Data class/ New DB space

    BW Experts,
    Does anyone know how to create a new 'Data Class' in SAP BW. The scenario is that the DBA have created new DB Tablespace, and i need to create new data class and assign it to these new DB space.
    Any idea? help is appreciated.
    Thanks
    ASHWIN

    Aashwin
    Check this if it helps. I think this also will be done by DBA
    Thnaks
    Sat
    http://help.sap.com/saphelp_nw04/helpdata/en/0d/ed6258a0364845829ff51ee22fb4ae/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/0d/ed6258a0364845829ff51ee22fb4ae/frameset.htm
    Thnaks
    Sat

  • Data Class in ABAP dictionary

    hi,
       recently we moved the tables from tablespace PSAPBTAD to user defined tablespace & since than we have poor performance in PROD - have any one had this issue before ? any idea on data class and tablespace ?
    thanks

    I doubt data class affects performance.  It definitely affect upgrades and support packs so you'll want to confirm that every table you reorged is assigned the data class associated with its current tablespace, otherwise you can lose data.
    It could be a lot of things affecting the performance.  Maybe the reorg tool added too many small extents to the tables which is a problem only if you're not on SAN and if the tablespaces are DTMS. But I'd start with disk stats.   Take a look and see if you've got hot spots, it's the first thing I'd check.
    Oh, and how about database statistics, did you re-calc after the reorgs? It's essential.

Maybe you are looking for