Test and trust Class.isInstance or try and catch Class.cast ?

I found this related thread, with no answer to my question.
In the below code, there is a certain level of redundancy in that I am checking that I can do the Class.cast() prior to doing it, via Class.isInstance().
I can either omit the isInstance() check and just count on cast() throwing an exception, or I can ignore the ClassCastException (do nothing in the catch block, as shown below).
Which is better? Is it faster if I just omit the instance check and let cast() detect the errors? Is there a style convention here?
    protected <T extends ParentClass> List<T> getItemsOfType(Class<T> clazz){
        List<T> retval = new ArrayList<T>();
        for(ParentClass t : items.values()){
            if(clazz.isInstance(t)){
                try{
                    retval.add(clazz.cast(t));
                catch(ClassCastException cce){
                    // should never happen
    }Thanks for your time

Derrick.Rice wrote:
I found this related thread, with no answer to my question.
In the below code, there is a certain level of redundancy in that I am checking that I can do the Class.cast() prior to doing it, via Class.isInstance().
I can either omit the isInstance() check and just count on cast() throwing an exception, or I can ignore the ClassCastException (do nothing in the catch block, as shown below).
Which is better? Is it faster if I just omit the instance check and let cast() detect the errors? Is there a style convention here?Whatever you decide, just keep in mind that there is a semantic difference too:
if(clazz.isInstance(t)) retval.add(clazz.cast(t));will only add instances of the requested class, whereas
try { retval.add(clazz.cast(t)); } catch(ClassCastException e) {} will also add null values.

Similar Messages

  • How the try and catch blocks work?

    For the following section of code from the class QueueInheritanceTest...how the try and catch blocks work?
    The Class...
    public class QueueInheritance extends List {
    public QueueInheritance() { super( "queue" ); }
    public void enqueue( Object o )
    { insertAtBack( o ); }
    public Object dequeue()
    throws EmptyListException { return removeFromFront(); }
    public boolean isEmpty() { return super.isEmpty(); }
    public void print() { super.print(); }
    Testing...
    public class QueueInheritanceTest {
    public static void main( String args[] ){
    QueueInheritance objQueue = new QueueInheritance();
    // Create objects to store in the queue
    Boolean b = Boolean.TRUE;
    Character c = new Character( '$' );
    Integer i = new Integer( 34567 );
    String s = "hello";
    // Use the enqueue method
    objQueue.enqueue( b );
    objQueue.enqueue( c );
    objQueue.enqueue( i );
    objQueue.enqueue( s );
    objQueue.print();
    // Use the dequeue method
    Object removedObj = null;
    try { while ( true ) {
    removedObj = objQueue.dequeue();
    System.out.println(removedObj.toString()+" dequeued" );
    objQueue.print();
    catch ( EmptyListException e ) {
    System.err.println( "\n" + e.toString() );

    If you want a basic introduction to try/catch blocks, read any introductory text or the tutorials on this site.
    Here are some:
    Sun's basic Java tutorial
    Sun's New To Java Center.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns."
    In terms of this particular case, it looks like the code is using an exception being thrown to get out of a loop. IMHO that's bad design -- exceptions should be used for exceptional circumstances, and if you use it to get out of a loop, then you're certain it's going to happen, and that means that it's not exceptional.
    When you post code, please wrap it in  tags so it's legible.

  • Oracle Arrays and getVendorConnection API and Class Cast Exception

    I 've gone through various threads relating to the topic of Oracle Arrays and the getVendorConnecton API call to avoid the class Cast Exception.. i ve used all these but am still facing the problem...
    I would appreciate it if some one could resolve the following queries :
    I am using Weblogic 8.1 SP5 with oracle 8i
    1. I read that the need to use the getVendorConnection API to make pl/sql proc calls with oracle arrays from the WL Server wont be required to avoid classCastException...
    I tried to use the connection from the WL connection pool ..but it didnot work....I used the getVendorConnection API ..which also doesnot seem to work..
    I got the Heurisitc Hazard exception...I used the Oracle 9i driver ie ojdbc14.jar ...after this the exception is not coming but still the code doesnt seem to work...
    the snippet of the code is pasted below :
    ~~~~~~~~~~~~~~~~~~~~~~~code is : ~~~~~~~~~~~~~~~~~~~
    /*below :
    logicalCon is the Connection from the WL connection pool
    JDBCcon is the JDBC connection. */
    <div> try </div>
    <div>{ </div>
    <div>
    <b>vendorConn</b> = ((WLConnection)logicalCon).getVendorConnection();
    </div>
    <div>
    //Calling the procedure
    </div>
    <div>
    //java.util.Map childMap1 = JDBCcon.getTypeMap();
    </div>
    <div>
    java.util.Map childMap1 = <b>vendorConn</b>.getTypeMap();
    </div>
    <div>
    childMap1.put("SST_ROUTE_ENTRY", Class.forName("svm.stport.ejb.StaticRouteEntry"));
    </div>
    <div>
    //JDBCcon.setTypeMap(childMap1);
    <b>vendorConn</b>.setTypeMap(childMap1);
    </div>
    <div>
    // Create an oracle.sql.ARRAY object to hold the values
    </div>
    <div>
    /*oracle.sql.ArrayDescriptor arrayDesc1 = oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", JDBCcon); */
    </div>
    <div>
    oracle.sql.ArrayDescriptor arrayDesc1 =
    oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", <b>vendorConn</b>); // here if i use the JDBCcon it works perfectly.... <u>^%^%^%</u>
    </div>
    <div>
    code to fill in the sst route entry array....
    .....arrayValues1 */
    </div>
    <div>
    /* oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, JDBCcon, arrayValues1); */
    </div>
    <div>
    oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, <b>vendorConn</b>, arrayValues1);
    </div>
    <div>
    callStatement = logicalCon.prepareCall( "? = call procName(?, ?, ?)");
    </div>
    <div>
    /* ..code to set the ?s ie array1 */
    </div>
    <div>
    callStatement.execute();
    </div>
    <div>
    }catch(Exceptio e){
    </div>
    <div>
    }</div>
    <div>
    finally </div>
    </div>{</div>
    <div>System.out.println(" I ve come to finally"); </div>
    <div>}</div>
    <div>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~code snippet ends here ~~~~~~~~~~~~~~``
    </div>
    I have observed that the control immediately comes to the finally block after the call to the createDescriptor line above with <u>^%^%^%</u> in the comment. If i use the JDBCCon in this line...it works perfectly fine.
    Any pointers to where anything is getting wrong.
    I have jst set the vendorCon to null in the end of the file and not closed it. Subsequently i have closed the logicalCon. This has been mentioned in some of the thread in this forum also.
    Thanks,
    -jw

    Jatinder Wadhwa wrote:
    I 've gone through various threads relating to the topic of Oracle Arrays and the getVendorConnecton API call to avoid the class Cast Exception.. i ve used all these but am still facing the problem...
    I would appreciate it if some one could resolve the following queries :
    I am using Weblogic 8.1 SP5 with oracle 8i
    1. I read that the need to use the getVendorConnection API to make pl/sql proc calls with oracle arrays from the WL Server wont be required to avoid classCastException...
    I tried to use the connection from the WL connection pool ..but it didnot work....I used the getVendorConnection API ..which also doesnot seem to work..
    I got the Heurisitc Hazard exception...I used the Oracle 9i driver ie ojdbc14.jar ...after this the exception is not coming but still the code doesnt seem to work...
    the snippet of the code is pasted below :
    ~~~~~~~~~~~~~~~~~~~~~~~code is : ~~~~~~~~~~~~~~~~~~~Hi. Show me the whole exception and stacktrace if you do:
    try
    vendorConn = ((WLConnection)logicalCon).getVendorConnection();
    java.util.Map childMap1 = vendorConn.getTypeMap();
    childMap1.put("SST_ROUTE_ENTRY" Class.forName("svm.stport.ejb.StaticRouteEntry"));
    vendorConn.setTypeMap(childMap1);
    oracle.sql.ArrayDescriptor arrayDesc1 =
    oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR",
    vendorConn);
    oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, vendorConn, arrayValues1);
    callStatement = logicalCon.prepareCall( "? = call procName(? ? ?)");
    callStatement.execute();
    }catch(Exception e){
    e.printStackTrace();
    finally
    try{logicalCon.close();}catch(Exception ignore){}
    System.out.println(" I ve come to finally");
    /*below :
    logicalCon is the Connection from the WL connection pool
    JDBCcon is the JDBC connection. */
    <div> try </div>
    <div>{ </div>
    <div>
    <b>vendorConn</b> = ((WLConnection)logicalCon).getVendorConnection();
    </div>
    <div>
    //Calling the procedure
    </div>
    <div>
    //java.util.Map childMap1 = JDBCcon.getTypeMap();
    </div>
    <div>
    java.util.Map childMap1 = <b>vendorConn</b>.getTypeMap();
    </div>
    <div>
    childMap1.put("SST_ROUTE_ENTRY", Class.forName("svm.stport.ejb.StaticRouteEntry"));
    </div>
    <div>
    //JDBCcon.setTypeMap(childMap1);
    <b>vendorConn</b>.setTypeMap(childMap1);
    </div>
    <div>
    // Create an oracle.sql.ARRAY object to hold the values
    </div>
    <div>
    /*oracle.sql.ArrayDescriptor arrayDesc1 = oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", JDBCcon); */
    </div>
    <div>
    oracle.sql.ArrayDescriptor arrayDesc1 =
    oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", <b>vendorConn</b>); // here if i use the JDBCcon it works perfectly.... <u>^%^%^%</u>
    </div>
    <div>
    code to fill in the sst route entry array....
    .....arrayValues1 */
    </div>
    <div>
    /* oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, JDBCcon, arrayValues1); */
    </div>
    <div>
    oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, <b>vendorConn</b>, arrayValues1);
    </div>
    <div>
    callStatement = logicalCon.prepareCall( "? = call procName(?, ?, ?)");
    </div>
    <div>
    /* ..code to set the ?s ie array1 */
    </div>
    <div>
    callStatement.execute();
    </div>
    <div>
    }catch(Exceptio e){
    </div>
    <div>
    }</div>
    <div>
    finally </div>
    </div>{</div>
    <div>System.out.println(" I ve come to finally"); </div>
    <div>}</div>
    <div>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~code snippet ends here ~~~~~~~~~~~~~~``
    </div>
    I have observed that the control immediately comes to the finally block after the call to the createDescriptor line above with <u>^%^%^%</u> in the comment. If i use the JDBCCon in this line...it works perfectly fine.
    Any pointers to where anything is getting wrong.
    I have jst set the vendorCon to null in the end of the file and not closed it. Subsequently i have closed the logicalCon. This has been mentioned in some of the thread in this forum also.
    Thanks,
    -jw

  • HT1567 I can't import an audio cd to itunes to add to my library. I ran a diagnostics test and it had a red light next to: Unable to access audio cd. I am wondering if anyone else has had this problem and if there is an easy solution?

    I can't import an audio cd to itunes to add to my library. I ran a diagnostics test and it had a red light next to: Unable to access audio cd. I am wondering if anyone else has had this problem and if there is an easy solution?

    Satellite L675-S7113 Specifications (PSK3AU-07C02S)
    Satellite L675-S7113 Support Page
    rwls wrote:...since I got it 3 years ago I've been unable to burn an audio CD from ITunes or Windows media although it worked once after the computer had been shut off for awhile..and didn't find the problem until after my warranty had expired...
    From your statements above, it sounds like you never tried to burn a CD for at least the first year that you owned the laptop, as it had a one year warranty on it. While you might have used it frequently to install software,  play DVDs, Blu-Ray disks, etc, that's unclear from your statements. Nonetheless, it might just be dirty-dusty. So, before deleting-uninstalling any software, and given they're cheap, try a CD-DVD Cleaner Disk first and see if that resolves your problems.
    Let us know what happens. Good luck.
    Mike

  • I am trying to update the new OS however, I keep getting an error messaging saying to have my connectivity checked since it is not connected. I ran a diagnostics test and everything passed. Any ideas on how I can to make sure a connection is established?

    I am trying to update the new OS system on my iPhone 4, however, when I connect to iTunes and try to download, I keep getting an error message that says the connection is not established. I ran a diagnostics test and everything passed, however, I'm not sure why I keep getting an error message when the software is at the end of downloading.
    Any tips?

    Disable your firewall/security software.

  • Hello. My mac pro early 2008 restarts after sleep mode and it works slower. I tested it with apple hardwear test and it seems to be ok. Thank you.

    Hello. My mac pro early 2008 restarts after sleep mode and it works slower. I tested it with apple hardwear test and it seems to be ok. Thank you.

    Try this:
    clone your system and repair it with Disk Warrior instead
    Or try a clean test system install on another drive
    A must: SmcFanControl 2.2 - a mere 400 rpm extra to keep air cooling up
    Try to run w/o externals. MyBook included.
    Is that a 7200.11 1TB? they had a lot of issues.
    Run AHT off your OEM DVD.
    2008 had to have EFI and SMC updates to deal with freezes on wake from sleep, and like all models, high inrush current.  Hopefully you have a UPS and is 1500VA unit.
    When you do hard restart from power button, you almost certainly add more directory errors and to files requiring immediate attention to repair and rebuild the directory; and to scan and repair and delete cache and temp files and folders. A must. Invest in bootable backups SuperDuper along with Disk Warrior (or TechTool Pro 6, maybe Drive Genius 3 but I'd rate that #3).
    TimeMachine has its own bad habits, especially with Green drives and some externals.
    Try to rule out everything and then add back one at a time.
    And it may just be time to replace the 8800, very common, a couple threads this week, and it is 3 yrs old.  Might want ATI 5870 or 5770.

  • Unit tests and QA process

    Hello,
    (disclaimer : if you agree that this topic does not really belong to this forum please vote for a new Development Process forum there:
    http://forum.java.sun.com/thread.jspa?forumID=53&threadID=504658 ;-)
    My current organization has a dedicated QA team.
    They ensure end-user functional testing but also run and monitor "technical" tests as well.
    In particular they would want to run developer-written junit tests as sanity tests before the functional tests.
    I'm wondering whether this is such a good idea, and how to handle failed unit tests:
    1) Well , indeed, I think this is a good idea: even if developer all abide by the practice of ensuring 100% of their test pass before promoting their code (which is unfortunately not the case), integration of independant development may cause regression or interactions that make some test fail.
    Any reason against QA running junit tests at this stage?
    However the next question is, what do they do with failed tests : QA has no clue how important a given unit test is with regard to the whole application.
    Maybe a single unit test failed out of 3500 means a complete outage of a 24x7 application. Or maybe 20% of failed tests only means a few misaligned icons...
    2) The developer of the failed package may know, but how can he communicate this to QA?
    Javadocing their unit testing code ("This test is mandatory before entering user acceptance") seems a bit fragile.
    Are there recommended methods?
    3) Even the developer of the failed package may not realize the importance of the failure. So what should be the process when unit tests fail in QA?
    Block the process until 100% tests pass? Or, start acceptance anyway but notify the developper through the bug tracking system?
    4) Does your acceptance process require 100% pass before user acceptance starts?
    Indeed I have ruled out requiring 100% pass, but is this a widespread practice?
    I rule it out because maybe the failed test indeed points out a bad test, or a temporary unavailability of a dependent or simulated resource.
    This has to be analyzed of course, as tests have to be maintained as well, but this can be a parallel process to the user acceptance (accepting that the software may have to be patched at some point during the acceptance).
    Thank you for your inputs.
    J.

    >
    Any reason against QA running junit tests at this
    stage?
    Actually running them seems pointless to me.
    QA could be interested in the following
    - That unit tests do actually exist
    - That the unit tests are actually being run
    - That the unit tests pass.
    This can all be achieved as part of the build process however. It can either be done for every cm build (like automated nightly) or for just for release builds.
    This would require that the following information was logged
    - An id unique to each test
    - Pass fail
    - A collection system.
    Obviously doing this is going to require more work and probably code than if QA was not tracking it.
    However the next question is, what do they do with
    failed tests : QA has no clue how important a given
    unit test is with regard to the whole application.
    Maybe a single unit test failed out of 3500 means a
    complete outage of a 24x7 application. Or maybe 20%
    of failed tests only means a few misaligned icons...
    To me that question is like asking what happens if one class fails to build for a release build.
    To my mind any unit test failure is logged as a severe exception (the entire system is unusable.)
    2) The developer of the failed package may know, but
    how can he communicate this to QA?
    Javadocing their unit testing code ("This test is
    mandatory before entering user acceptance") seems a
    bit fragile.
    Are there recommended methods?Automatic collection obviously. This has to be planned for.
    One way is to just log success and failure for each test which is gathered in one or more files. Then a seperate process munges the result file to collect the data.
    I know that there is a java build engine (add on to ant or a wrapper to ant) which will do periodic builds and email reports to developers. I think it even allows for categorization so the correct developer gets the correct error.
    >
    3) Even the developer of the failed package may not
    realize the importance of the failure. So what
    should be the process when unit tests fail in
    QA?
    Block the process until 100% tests pass? Or, start
    acceptance anyway but notify the developper through
    the bug tracking system?
    I would block it.
    4) Does your acceptance process require 100% pass
    before user acceptance starts?
    No. But I am not sure what that has to do with what you were discussing above. I consider unit tests and acceptance testing to be two seperate things.
    Indeed I have ruled out requiring 100% pass, but is
    this a widespread practice?
    I rule it out because maybe the failed test indeed
    points out a bad test, or a temporary unavailability
    of a dependent or simulated resource.Then something is wrong with your process.
    When you create a release build you should include those things that should be in the release. If they are not done, missing, have build errors, then they shouldn't be in the release.
    If some dependent piece is missing for the release build then the build process has failed. And so it should not be released to QA.
    I have used version control/debug systems which made this relatively easy by allowing control over which bug/enhancements are included in a release. And of course requiring that anything checked in must be done so under a bug/enhancement. They will even control dependencies as well (the files for bug 7 might require that bug 8 is added as well.)

  • "invalid password "on Iweb Test. and on SEO Tool, Login Failed Login Authentication Failed, ALL SETTING ARE CORRECT HELP

    I have been updating my site over the last week, using Iweb SEO TOOL, but suddenly 2 days ago I can no longer update when i go to publish it says "invalid password "on Iweb Test. and on SEO Tool, Login Failed Login Authentication Failed, the password and all settings are correct.
    I am 100% sure the all the setting are correct, as it has been working for the last 7 months and I have just been updating it, then suddenly it stopped, I have all the FTP settings wrote down, and even changed the passwords twice hoping that may work to no avail.

    Try the following:
    delete the iWeb preference files, com.apple.iWeb.plist and com.apple.iWeb.plist.lockfile, that resides in your Home() /Library/Preferences folder.
    go to your Home()/Library/Caches/com.apple.iWeb folder and delete its contents.
    Click to view full size
    launch iWeb and try again.
    If that doesn't help continue with:
    move the domain file from your Home/Library/Application Support/iWeb folder to the Desktop.
    launch iWeb, create a new test site, save the new domain file and close iWeb.
    go to the your Home/Library/Application Support/iWeb folder and delete the new domain file.
    move your original domain file from the Desktop to the iWeb folder.
    launch iWeb and try again.

  • Sources for G3 Ibook Hardware test and Installation Disks

    Greetings All!
    Subject says it all. I bought my 14" 900mHz G3 iBook with insurance off eBay last Feb and it's been working just great (just know how to handle it like a baby!). Since it came without the Hardware test and installation CDs in case of emergency, what source options do I have?
    Thanks!
    James Greenidge

    You may want to try _calling Apple_ to see if they have the CD's available. If they do, they will send them to you (for a fee).

  • Missing Load Test and Coded UI Templates

    Missing Load Test and Coded UI Templates even though i have installed Premium Version of Visual studio 2010.
    How can we install these?
    saikalyan

    Hi saikkalyan,
    Based on your issue, as far as I know that the Premium Version of Visual studio 2010 is only support the Unit test and coded UI test template.
    And I know that the load test template is only supported with the Ultimate version of Visual Studio 2010.
    Reference:
    https://msdn.microsoft.com/en-us/library/ms182572(v=vs.100).aspx
    So if you want to get the load test project template, you will need to install the VS2010 Ultimate.
    However, as you said that the coded UI test template missing in the VS2010 Premium, I suggest you could try to
    delete your ItemTemplatesCache, ProjectTemplatesCache folder and then run the the devenv /InstallVSTemplates switch and
    devenv /Setup switch. Please refer to the following steps:
    Step1: Please open Windows Explorer, and navigate to <Visual Studio Installation Path>\Common7\IDE (by default is <C:\Program Files(x86) \Microsoft Visual Studio 10.0\Common7\IDE>)
    Step2:
     Delete the ItemTemplatesCache, ProjectTemplatesCache folder; 
    Step3: Open Visual Studio Command Prompt (2010 x64 Cross Tools Command Prompt under Start menu -> All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools
    (run it with Administrator privilege: right-click the program -> Run as administrator); 
    Step4: Run the devenv /InstallVSTemplates switch and the devenv /Setup switch
    http://msdn.microsoft.com/en-us/library/ms241279.aspx
    http://msdn.microsoft.com/en-us/library/ex6a2fad.aspx
    If you want to get both the load test and coded UI test template, you will need to install the VS2010 Ultimate as I pervious said.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Repost as question for points: What did I do wrong? (Try and Catch program)

    This has to be a try and catch program.
    This is the given output sample:
    OUTPUT SAMPLE #2 for input.txt: 12345 222256 -3 123 -56784 555557 6345678 x x x 81234 121212 x x 123434 x x 1009098 2099
    Please input the name of the file to be opened: input.txt
    For number 12345 the sum of digits is: 15
    For number 222256 the sum of digits is: 19
    Found an integer (-3), but it is negative. Will ignore!
    For number 123 the sum of digits is: 6
    Found an integer (-56784), but it is negative. Will ignore!
    For number 555557 the sum of digits is: 32
    For number 6345678 the sum of digits is: 39
    For number 81234 the sum of digits is: 18
    For number 121212 the sum of digits is: 9
    For number 123434 the sum of digits is: 17
    For number 1009098 the sum of digits is: 27
    For number 2099 the sum of digits is: 20
    Here is what I have so far.
    import java.util.Scanner;
      import java.io.*;// FileNotFoundException
    public class Assignment3b {
      public static void main (String[]args){
        Boolean fileOpened = true; 
        String fileName;
        int n,mod=0,sum=0,t=0;
        Scanner inputFile = new Scanner(System.in);
        System.out.print("Please input the name of the file to be opened: ");
        fileName = inputFile.nextLine();
        System.out.println();
        try {
                inputFile = new Scanner(new File(fileName));
            catch (FileNotFoundException e) {
                System.out.println("--- File Not Found! ---");
                fileOpened = false;
            if (fileOpened) {
              while (inputFile.hasNext()){
                if (inputFile.hasNextInt()){
                  n = inputFile.nextInt();
                  t=n;
                  while(n>0){
                    mod = n % 10;
                    sum = mod + sum;
                    n = n/10;
                  System.out.println ("For number " + t + " the sum of digits is : " + sum);
                  mod = 0;
                  sum = 0;
                  while (n<0) {
                    System.out.println ("Found an integer (" + t + "), but it negative. Will ignore!");
                    inputFile.next();
                    n = inputFile.nextInt();
                else {
                  inputFile.next();
    }Everything seems to work fine until, it is time to deal with negative numbers. How can I fix this. Please put your reply in layman's terms to the best of your ability.
    Thanks and God Bless.

    // COSC 236                                Assignment # 3
    // YOUR NAME: Anson Castelino
    // DUE-DATE:
    // PROGRAM-NAME: Assignment # 3 Prt2
    //import packages
      import java.util.Scanner;
      import java.io.*;// FileNotFoundException
    public class Assignment3b {
      public static void main (String[]args){
        Boolean fileOpened = true; 
        String fileName;
        int n,mod=0,sum=0,t=0;
        Scanner inputFile = new Scanner(System.in);
        System.out.print("Please input the name of the file to be opened: ");
        fileName = inputFile.nextLine();
        System.out.println();
        try {
                inputFile = new Scanner(new File(fileName));
            catch (FileNotFoundException e) {
                System.out.println("--- File Not Found! ---");
                fileOpened = false;
            if (fileOpened) {
              while (inputFile.hasNext()){
                if (inputFile.hasNextInt()){
                  n = inputFile.nextInt();
                  t=n;
                  while(n>0){
                    mod = n % 10;
                    sum = mod + sum;
                    n = n/10;
                  System.out.println ("For number " + t + " the sum of digits is : " + sum);
                  mod = 0;
                  sum = 0;
                  if (n<0) {
                    System.out.println ("Found an integer (" + t + "), but it is negative. Will ignore!");
                    inputFile.next();
                  inputFile.hasNext();
                else {
                  inputFile.next();
    }Updated code.
    current output is as follows:
    Please input the name of the file to be opened: [DrJava Input Box]
    For number 12345 the sum of digits is : 15
    For number 222256 the sum of digits is : 19
    For number -3 the sum of digits is : 0 <-------- this part is not suppose to be here.
    Found an integer (-3), but it is negative. Will ignore!
    For number -56784 the sum of digits is : 0 <-------- this part is not suppose to be here.
    Found an integer (-56784), but it is negative. Will ignore!
    For number 6345678 the sum of digits is : 39
    For number 81234 the sum of digits is : 18
    For number 121212 the sum of digits is : 9
    For number 123434 the sum of digits is : 17
    For number 1009098 the sum of digits is : 27
    For number 2099 the sum of digits is : 20
    >

  • Limit to number of tests and learning objects in a Content folder in OLM

    All,
    Before I ask my question I want to preference a few things:
    1. My company has been using OLM for approximately 2 years.
    2. For the most part we use OLM to track compliance, meaning that we use Online tests to track compliance to specific company standard operating procedures. Which as you can imagine is a lot of documents.
    So, with this is mind. We setup a course, offiering (with associated test) and class to determine if an employee has completed reviewing the changes to a document, as each document revises.
    Now to my question...
    Today we noticed that some of the tests for this compliance process in OLM were not being displayed. All of the tests exist in their own folder for this process. Note: There is a single content folder on the content tab of OLM for all of these tests. And when we check the count from the front end we see that there are 1001 displayed from the dministrator front end of OLM.
    However, some of these are not listed here. Even eif you click next all the way to item (test) number 1001.
    So, Is there a limit to the number of test or learning objects that can exist in a content folder in OLM?
    If so what is this limit? Is it 1000? 1001?
    My understanding is that you cannot move a test in the content hierarchy, if it is bound to a folder or even a parent learning oject it forever stays there. And you cannot delete it once it has attempts against it.
    So where does this leave us... We know that some of the tests in this content folder are missing because our catalog has less items in the same associated folder. In other words we have better organization in the catalog (for courses, offering and classess, because each course has its own folder. So if we go to a known missing Offering we can determine the learning object / test associated with it. If we copy the name of this test and search for it on the Content tab it is in fact found.
    So we know it is there and we know that people have competed it as a result of the status of the enrollment, yet we cannot go to it on the Content tab.
    This leaves me baffled.
    Is there any way that we can get to these from the Administrator Front end? Can we move them on the back end?
    Any help anyone can provide is sincerely appreciated. I am doing a deep dive with my IT staff on this next week to come to some resolution on this, because we have had to halt our process until we have a resolution.
    Thanks for your help!
    Brian Urbanek - Luminex Corporation Training Operations Manager

    Hey Brian,
    I believe you should be able to personalize the number of rows displayed to overcome the pre-defined limit.
    Or check this thread, it might help.
    How to remove the limitation on no. of rows
    Hope all is well,
    Scott
    http://www.seertechsolutions.com

  • How to migrate siebel BI report to TEST and PROD from DEV without manually?

    Hi,
    i have developed siebel BI reports in DEV environment. Now want to migrate in test and prod. Is there any automated process available or need to manually. Adding reports to views and uploading templates etc.
    Thanks,
    lax

    Hi,
    try this online training: http://www.oracle.com/technology/obe/admin/owb10gr2_gs.htm.
    Regards,
    Detlef

  • HT4461 I purchased an app yesterday called aptitude trainer test and it didn't work at all and today was my test I needed it from to practice so I'm asking for a refund of 2.11 back thank you

    I purchased an app yesterday called aptitude trainer test and it didn't work at all and today was my test I needed it from to practice so I'm asking for a refund of 2.11 back thank you

    We are fellow users here on these forums, you're not talking to iTunes Support.
    Did you try deleting the app and redownloading it via the Purchased tab in the App Store app on your iPad, and contacting the developer of the app ? If you did contact them and you didn't get a reply then try the 'report a problem' page to contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • HT1883 I started up using the app install DVD and tried to run a test and got stuck and froze what next? Help

    I started up using the app install DVD and tried to run a test and got stuck and froze what next? Help

    Well it started like this I've been away for 12 days and I usually inplug things before I go on vacation, I
    Come plug everything back in start up and it's stuck on the grey screen with the ape logo and the spinning gear. I left about 3hrs on this then assumed its struggle to find the start up disc so I plug the original DVD start up disc in. Then it start up with that to the install screen and could find a hard disc to install to? So I eject that DVD and try with the other DVD. And now this is where I am now.
    I have a password set on my start up and guest user. I am just trying to start up as guest user and the gear has stopped spinning and now I just have a grey screen with apple logo.
    Ups I now have a grey screen with no apple logo put the screen is textured.

Maybe you are looking for

  • HT1296 how can I sync notes on my iPhone into my Outlook

    How can I sync Notes from my iPhone 4S into Outlook? 

  • Classic synchronizing problem

    My Classic is a couple of years old and has been restored about three times now. For some reason(s) it crashes and have to go thru the resoration stages for it to work properly. Now it connects to iTunes but but has trouble synchronizing when music f

  • Mass Extraction of planning data in EHP3

    Hi, I am trying to map this functionality. For this Already I have configured Selection rule & Extraction mode.  To extract the data we need to use one report : "RMDMRPEXTRACT01" in this report a field is called " server group" which is mandatory to

  • Cannot connect to MS SQL 2008 R2 locally or remotely.

    When I try to connect to my SQL 2008 I get the following error: TITLE: Connect to Server Cannot connect to <machinename>. ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The

  • Easy question about install time

    Hello, I have been having a lot of problems with my MacBook and after posting on the forums it seems a re-install might help. This is my firt time doing a wipe/install so I backed up my files and booted from my Tiger install DVD and did a wipe/instal