Köll & Sam Classroom Blog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    Originally posted by JosAH
    Read this.

    kind regards,

    Jos
    Does commandment #10 have anything to do with a senile granny's knitting? ROFL, but only because I'm currently trying to unravel some of my knitting that I did about 5 years ago. It's some visualization software in Excel for multi-dimensional data. I think that egoless programming is probably an oxymoron: the only programmers that can and do laugh at their awful code know that their code is actually head and shoulders above anyone else's. Have a great day!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      Originally posted by SammyB
      ...the only programmers that can and do laugh at their awful code know that their code is actually head and shoulders above anyone else's. Have a great day!
      I see wisdom :)

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        Shouldn't this be in the discussion section? Not much of a question.

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          Why is my text all red up there, that's happened before?!?

          I am still beating the beast even after reading the information, and I surely appreciate it. I learn by accepting critics, I get it from the professors, I see you guys as professors within your own means, gt it here as well

          Truth is I am still going to ask questions, rest assured I am not calling myself Java programmer until I can actually write this stuff, for now, I am modifying the works of our great professor, making up a desgn that best attack the lab she has set forth. I try to find bits and pieces of code from past and even future labs to give her what she needs, then I come here and talk about it.

          My friends, I still cannot shake it...

          I will attempt to load a zip containing only the design, the original code called for fixed array:

          [CODE=JAVA]

          Person[] person; //declare the person array
          person = new Person[5]; //and then create it

          [/CODE]

          As shown, the code beyond this one was with the help of the professor and you, but it got interesting when I had to make it work when I went to work on the ideas I got.

          Will post later, being pulled away here;-)

          Thanks!

          Köll

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            Originally posted by Dököll
            Why is my text all red up there, that's happened before?!?
            ...
            That's because you have included code which had unbalanced quotes in it.

            The code-specific tags are not 100% so when your code stopped in the middle of a string, they didn't handle returning from string mode when the tags were closed.

            Fixed now - but you may want to look at what you're posting for clues like that. It may also help you to fix some code possibly. I'm no Java expert so I can't be sure on that one ;)

            Comment

            • Dököll
              Recognized Expert Top Contributor
              • Nov 2006
              • 2379

              What do you know, pretty simple, thanks on that... I'll fetch my other one and attempt to fix it. Yes will let you know if I cannot fix...

              Thanks again NeoPa!

              Köll

              Comment

              • Dököll
                Recognized Expert Top Contributor
                • Nov 2006
                • 2379

                It was my last day today at work, pretty somber leave but my colleagues were so nice, I could not begin to tell you... thing is they understand my having to go, it's actually for a Java position, I am being paired up with folks who know and will be sent to training, pretty interesting quite honestly, seems like it's all falling into place. I am babbling but I am happy that the group I left is even now stronger, moved up to a bigger IT division, which we had to contact now and then for the more specific IT stuff, we're/my colleagues are now right there. I don't feel so bad anymore, send my boss the code library to the database built for the clan. Hopefully I did not leave any work behind, tried not to, 'til the last hour, should be okay, I think:-)

                On a different note, here is what I could salvage out of my design, could not do the zip, silly me:-)

                Code:
                Köll S. Cherizard
                Lab 7
                Version 200800000408
                
                Automobiles need to be entered via pop up menus or else.  Entries at this point should dictate size of array/InputDialog pop up in the program; if user enters 1, only 1 automobile should carry ratings of three types, ID and name should also be vital.  Each automobile’s own ID, Rating ranging from Endurance, Dependability and handling, and name of each automobile must be stored according to number of instances added to array or InputDialog.  Must enter speed of each vehicle, names and so on ought to further differentiate from Semi-Sporty autos to the Sportiest of them all.  
                
                [B]IMPORTANT:[/B] Make available number format exception to fend off bogus data such as vowels, characters as a dash, period and more, in pop up menus. 
                
                Sort data result or view using bubble sort method; add a search method, sort by user ID and search by auto name. Distinguish ratings to make available Semi-Sporty and Sportiest automobile average rating levels, display rating levels of either with Ids sorted.
                
                [B]Declare variables:[/B] NumberOfAutomobiles, AutoName, ID, Speed, Rating1, Rating2, Rating3
                
                NumberOfAutomobiles as integer
                AutoName as string
                ID as integer
                Speed as char
                Rating1 as int or double
                Rating2 as int or double
                Rating3 as int or double
                		
                Add Loop to make available for Rating Scale 1, 2, and 3
                Use for loop to add Ratings one by one then find length of search, any type of user input, necessary to restrict user entries at this point.
                		
                	if automobile Rating1 less than average and is specific to the name of auto for Rating1 and data valid, user has found a Semi-Sporty Auto Automobile 
                			
                			
                	if automobile Rating1 higher than average and is specific to the name of auto for Rating1 and data valid, user has found a Sportiest Auto Automobile 
                				
                [B]WARNING: [/B] The ratings will need match ID numbers of each auto
                           Add a bubble to sort by ID and bring in a linear search option, it's a must
                
                
                Add Loop to fetch all automobile added into the program
                Use for loop to search and find length of text user need searching, compare against already added data to InputDialog.
                		
                	
                			
                
                				
                [B]IMPORTANT: [/B] The ratings will need match ID numbers of each auto
                           Add a bubble to sort by ID, and bring in a linear search option
                           
                      
                [B]TO DO: [/B] Add/distinguish Rating 1 from Rating 2, and so on, and output ALL
                       separately for all to see… Make program scalable in case you need
                       to add stuff; build templates if needed…
                
                [B]RESEARCH:[/B]
                
                ·	Use LAB6 for fixed-array code – in class lab
                ·	Use Book for undefined array examples – homework # 5 example
                ·	Use LAB 5 for Number Format exception – in class lab
                ·	Use entry instances to determine array size – user InputDialog
                ·	Use bubble sort method near the end – Discussion, Web site search
                ·	Use Linear search method code example – discussion, Web site search
                ·	[B]MISC: [/B] Print to system of MessageDialog
                I have a long way to go, I got some leads on getting the program to loop for more entries. I am attempting usng String [] out of my:

                [CODE=JAVA]

                public static void main(String[] args) {


                ...


                ...


                then adding an istance where it should fetch/equal entries made


                String[] drivers = new String[numTypeAuto];

                Something like that...

                [/CODE]

                Still researching, but please jump in, I could be doing this in a simpler way.

                In a bit, and thanks for everything. Wish me luck on 2morrow;-)

                Köll
                Last edited by Dököll; Apr 17 '08, 04:08 AM. Reason: took JAVA out of [CODE=JAVA]...

                Comment

                • Dököll
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 2379

                  Good heavens I did it again, UNbelievable:-)

                  Alright, let me figure this out...

                  Comment

                  • Dököll
                    Recognized Expert Top Contributor
                    • Nov 2006
                    • 2379

                    Originally posted by Dököll
                    Good heavens I did it again, UNbelievable:-)

                    Alright, let me figure this out...
                    Now that it's fixed, above does not make sense... My text was red again, so I removed the JAVA, not sure why I had to do that there. Anyway, thanks NeoPa, I re-read your post and I nailed it, it seems:-)

                    In a bit!

                    Köll
                    Last edited by Dököll; Apr 17 '08, 04:16 AM. Reason: it'sfixed;-)

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      No worries Köll.

                      I'd suggest checking the code you post first though. It's possible to get around the problem using simple [ CODE ] tags (text) rather than the Java ones, but as we all (developers) know very well, understanding and fixing the root cause of a problem (the code posted) is far more reliable than always skipping around the problems caused.

                      Think of it as more of an opportunity to find bugs than as a problem posting.

                      Comment

                      • Dököll
                        Recognized Expert Top Contributor
                        • Nov 2006
                        • 2379

                        Originally posted by NeoPa
                        No worries Köll.

                        I'd suggest checking the code you post first though. It's possible to get around the problem using simple [ CODE ] tags (text) rather than the Java ones, but as we all (developers) know very well, understanding and fixing the root cause of a problem (the code posted) is far more reliable than always skipping around the problems caused.

                        Think of it as more of an opportunity to find bugs than as a problem posting.
                        That indeed, Ade, the answer is usually right there, just have to focus now and again:-)

                        Reporting a small victory since then, the array is working, silly me:

                        template code...

                        [CODE=JAVA]
                        package processAutomobi le;

                        /**
                        * @author Köll S. Cherizard
                        * @professor :-)
                        * @Lab 7
                        * @version 200800000408
                        */

                        import javax.swing.*;

                        class ProcessAutomobi leArray {

                        public static void main (String[] args) {
                        String autoName, speed;
                        int numTypeAuto = 0, autoIDNumber; //declare variables...
                        int rating1; //declare variables...
                        int rating2; //declare variables...
                        int rating3; //declare variables...
                        char autoSpeed;
                        //read in data values
                        numTypeAuto = Integer.parseIn t(JOptionPane.s howInputDialog( null,"Enter Number of Automobiles:")) ;

                        Automobile[] automobile; //declare the Automobile array
                        automobile = new Automobile[numTypeAuto]; //and then create it
                        for (int i = 0; i < automobile.leng th; i++) { //create a new Automobile and assign values

                        autoName = JOptionPane.sho wInputDialog(nu ll,"Enter Favourite Automobile name:");
                        autoIDNumber = Integer.parseIn t(JOptionPane.s howInputDialog
                        (null,"Enter Automobile ID Number:"));

                        rating1 = Integer.parseIn t(JOptionPane.s howInputDialog
                        (null,"Enter Rating Scale for Endurance (Example: 5 through 10):")); //ask to enter rating scale 1 of favourite auto
                        rating2 = Integer.parseIn t(JOptionPane.s howInputDialog
                        (null,"Enter Rating Scale for Handling (Example: 5 through 10):")); //ask to enter rating scale 2 of favourite auto
                        rating3 = Integer.parseIn t(JOptionPane.s howInputDialog
                        (null,"Enter Rating Scale for Dependability (Example: 5 through 10):")); //ask to enter rating scale 3 of favourite auto
                        speed = JOptionPane.sho wInputDialog(nu ll,"Enter Speed of this Automobile name:"); //ask to enter speed of each favourite auto
                        autoSpeed = speed.charAt(0) ;
                        automobile[i] = new Automobile( );
                        automobile[i].setSizeOfArray ( numTypeAuto ); //create user-defined number of Automobiles to be entered
                        automobile[i].setAutoName ( autoName ); //create instances of each favourite new Automobile
                        automobile[i].setAutoID ( autoIDNumber ); //create instances of each favourite new Automobile ID number
                        automobile[i].setRating1 ( rating1 ); //create instances of each favourite new Automobile rating scale 1
                        automobile[i].setRating2 ( rating2 ); //create instances of each favourite new Automobile rating scale 2
                        automobile[i].setRating3 ( rating3 ); //create instances of each favourite new Automobile rating scale 3
                        automobile[i].setAutoSpeed ( autoSpeed ); //create speed level of each favourite new Automobile speed


                        }

                        //DONE: Add/distinguish Rating 1 from Rating 2, and so on, and output ALL separately for all to see...

                        Automobile undoubtablySpor ty, //points to the Semi-Sporty Automobile
                        stupendouslySpo rty; //points to the Sportiest Automobile
                        undoubtablySpor ty = stupendouslySpo rty = automobile[0]; //initialize each strength to zero...

                        //loop to make available for Rating Scale 1, 2, and 3
                        for (int i = 1; i < automobile.leng th; i++) {

                        if ( automobile[i].getRating1() < undoubtablySpor ty.getRating1() ) { //found Automobile
                        undoubtablySpor ty = automobile[i];
                        }

                        else if ( automobile[i].getRating1() > stupendouslySpo rty.getRating1( ) ) { //found Automobile
                        stupendouslySpo rty = automobile[i];
                        }
                        }
                        System.out.prin tln("(1) Rating Scale # 1 for Automobile named : " + stupendouslySpo rty.getAutoName () + " is " + stupendouslySpo rty.getRating1( ));
                        System.out.prin tln("(2) Rating Scale # 1 for Automobile named: " + undoubtablySpor ty.getAutoName( ) + " is " + undoubtablySpor ty.getRating1() );






                        //loop to make available for Rating Scale 1, 2, and 3
                        for (int o = 1; o < automobile.leng th; o++) {

                        if ( automobile[o].getRating2() < undoubtablySpor ty.getRating2() ) { //found Automobile
                        undoubtablySpor ty = automobile[o];
                        }

                        else if ( automobile[o].getRating2() > stupendouslySpo rty.getRating2( ) ) { //found Automobile
                        stupendouslySpo rty = automobile[o];
                        }
                        }
                        System.out.prin tln("(1) Rating Scale # 2 for Automobile named : " + stupendouslySpo rty.getAutoName () + " is " + stupendouslySpo rty.getRating2( ));
                        System.out.prin tln("(2) Rating Scale # 2 for Automobile named: " + undoubtablySpor ty.getAutoName( ) + " is " + undoubtablySpor ty.getRating2() );




                        //loop to make available for Rating Scale 1, 2, and 3
                        for (int b = 1; b < automobile.leng th; b++) {

                        if ( automobile[b].getRating3() < undoubtablySpor ty.getRating3() ) { //found Automobile
                        undoubtablySpor ty = automobile[b];
                        }

                        else if ( automobile[b].getRating3() > stupendouslySpo rty.getRating3( ) ) { //found Automobile
                        stupendouslySpo rty = automobile[b];
                        }
                        }
                        System.out.prin tln("(1) Rating Scale # 3 for Automobile named : " + stupendouslySpo rty.getAutoName () + " is " + stupendouslySpo rty.getRating3( ));
                        System.out.prin tln("(2) Rating Scale # 3 for Automobile named: " + undoubtablySpor ty.getAutoName( ) + " is " + undoubtablySpor ty.getRating3() );

                        //DONE: Add/distinguish Rating 1 from Rating 2, and so on, and output ALL separately for all to see...

                        String searchAutoName = JOptionPane.sho wInputDialog(nu ll,"Name of Automobile to search:");
                        int i = 0;

                        //still more Automobiles to search
                        while ( i < automobile.leng th && !automobile[i].getAutoName(). equals( searchAutoName ) ) {i++;
                        }
                        if (i == automobile.leng th) { //not found - unsuccessful search
                        System.out.prin tln( searchAutoName + " was not in the array" );
                        }
                        else {
                        //found - successful search
                        System.out.prin tln("You have searched " + searchAutoName + ", looks like it is found at position " + i);
                        }
                        }
                        }

                        [/CODE]

                        Below was in the wrong portion of the code, I asked for the integer to grab instances which would help determine size of array then I grabbed everything before looping through, thus

                        [CODE=JAVA]

                        Automobile[] automobile; //declare the Automobile array
                        automobile = new Automobile[numTypeAuto]; //and then create it
                        for (int i = 0; i < automobile.leng th; i++) { //create a new Automobile and assign values

                        [/CODE]

                        Should be right after user has entered number of automobiles to work with:

                        [CODE=JAVA]

                        //read in data values
                        numTypeAuto = Integer.parseIn t(JOptionPane.s howInputDialog( null,"Enter Number of Automobiles:")) ;

                        Automobile[] automobile; //declare the Automobile array
                        automobile = new Automobile[numTypeAuto]; //and then create it
                        for (int i = 0; i < automobile.leng th; i++) { //create a new Automobile and assign values

                        autoName = JOptionPane.sho wInputDialog(nu ll,"Enter Favourite Automobile name:");
                        autoIDNumber = Integer.parseIn t(JOptionPane.s howInputDialog
                        (null,"Enter Automobile ID Number:"));

                        [/CODE]


                        It should not be added as this...

                        [CODE=JAVA]

                        Automobile[] automobile; //declare the Automobile array
                        automobile = new Automobile[numTypeAuto]; //and then create it
                        for (int i = 0; i < automobile.leng th; i++) { //create a new Automobile and assign values

                        //automobile[i] = new Automobile( ); // don't need this here
                        automobile[i].setSizeOfArray ( numTypeAuto ); //create user-defined number of Automobiles to be entered
                        automobile[i].setAutoName ( autoName ); //create instances of each favourite new Automobile
                        automobile[i].setAutoID ( autoIDNumber ); //create instances of each favourite new Automobile ID number
                        automobile[i].setRating1 ( rating1 ); //create instances of each favourite new Automobile rating scale 1
                        automobile[i].setRating2 ( rating2 ); //create instances of each favourite new Automobile rating scale 2
                        automobile[i].setRating3 ( rating3 ); //create instances of each favourite new Automobile rating scale 3
                        automobile[i].setAutoSpeed ( autoSpeed ); //create speed level of each favourite new Automobile speed

                        [/CODE]

                        I was getting one instance of an auto because my code never looped through anything. I'd already gotten what needed from each InputBox, so the code stopped after enterring 1 auto.

                        Now I need to use bubble sort example to see how to fit it in, wish me luck there:-)
                        Last edited by Dököll; Apr 28 '08, 02:52 AM. Reason: removed prof name...

                        Comment

                        • Dököll
                          Recognized Expert Top Contributor
                          • Nov 2006
                          • 2379

                          ...I was getting one instance of an auto because my code never looped through anything. I'd already gotten what needed from each InputBox, so the code stopped after enterring 1 auto.

                          Now I need to use bubble sort example to see how to fit it in, wish me luck there:-)
                          Truth be told, I think I stunk pretty bad for the last exam; I actually thought I had one more month, was probably sleeping, a lot of sleepless nights. I think I did alright in the final exam, have yet to see the scores, gbut should surely pass. Above code was satisfactory as is, will see what score I get, part of the code was in fact a topic in the exam...

                          One should never stop programming, by the way, if that's your thing, school is out, well really 'til September but... I have what I think is a puzzle, not relating to school, I figured why not include in this blog... I muscled through this bit of code from my book at work, it works wonders, what a surprise;-) Tried it @ home just to get curious, lo and behold, it does not work; is this because my system is not part of a network?

                          What do you make of it?

                          Oh!

                          Here's the error I am getting:

                          [CODE=JAVA]

                          java.lang.NoCla ssDefFoundError : dbMailMePackage/MailMeSolid
                          Caused by: java.lang.Class NotFoundExcepti on: dbMailMePackage .MailMeSolid
                          at java.net.URLCla ssLoader$1.run( Unknown Source)
                          at java.security.A ccessController .doPrivileged(N ative Method)
                          at java.net.URLCla ssLoader.findCl ass(Unknown Source)
                          at java.lang.Class Loader.loadClas s(Unknown Source)
                          at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
                          at java.lang.Class Loader.loadClas s(Unknown Source)
                          at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
                          Exception in thread "main"

                          [/CODE]

                          Code firing such error:-(

                          [CODE=JAVA]

                          package dbMailMePackage ;

                          /**
                          * @author Köll S. Cherizard
                          * @project MailFrenzy
                          * @version 200800001405
                          */

                          import java.util.*;
                          import javax.mail.*;
                          import javax.activatio n.*;
                          import javax.mail.inte rnet.*;

                          public class MailMeSolid {

                          public static void main(String[] args) {
                          String to = "this is just forthe site_@gmail.com ";
                          String from = "this is just forthe site_@gmail.com ";
                          String host = "smtp.gmail.com ";

                          Properties properties = new Properties();
                          properties.put( "mail.smtp.host ", host);
                          properties.put( "mail.debug ", "false");
                          Session session = Session.getInst ance(properties );
                          try {
                          Message msg = new MimeMessage(ses sion);
                          msg.setFrom(new InternetAddress (from));
                          InternetAddress[] address = {new InternetAddress (to)};
                          msg.setRecipien ts(Message.Reci pientType.TO,ad dress);
                          msg.setSubject( "&&&");
                          msg.setSentDate (new Date());
                          msg.setText("?? ? " +
                          "!!!.\n"+
                          "%%%");
                          Transport.send( msg);}
                          catch (MessagingExcep tion messenger) {
                          messenger.print StackTrace();}
                          }

                          }

                          [/CODE]

                          Beats me guys, please let me know what you think is happening that I do not see.

                          Thanks for your help!

                          Dököll
                          Last edited by Dököll; May 15 '08, 02:15 AM. Reason: text... and [QUOTE]...

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            [QUOTE=Dököll][CODE=JAVA]

                            java.lang.NoCla ssDefFoundError : dbMailMePackage/MailMeSolid
                            Caused by: java.lang.Class NotFoundExcepti on: dbMailMePackage .MailMeSolid
                            at java.net.URLCla ssLoader$1.run( Unknown Source)
                            at java.security.A ccessController .doPrivileged(N ative Method)
                            at java.net.URLCla ssLoader.findCl ass(Unknown Source)
                            at java.lang.Class Loader.loadClas s(Unknown Source)
                            at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
                            at java.lang.Class Loader.loadClas s(Unknown Source)
                            at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
                            Exception in thread "main"

                            [/CODE]

                            There was no need to post your code because the exception indicates that the
                            JVM can't even find your class. It's a classpath problem; your .class file should
                            be stored somewhere in a path /foo/bar/dbMailMePackage/MailMeSolid.cla ss.
                            Then your classpath should contain the directory /foo/bar/

                            kind regards,

                            Jos

                            Comment

                            • Dököll
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 2379

                              [QUOTE=JosAH]
                              Originally posted by Dököll
                              [CODE=JAVA]

                              java.lang.NoCla ssDefFoundError : dbMailMePackage/MailMeSolid
                              Caused by: java.lang.Class NotFoundExcepti on: dbMailMePackage .MailMeSolid
                              at java.net.URLCla ssLoader$1.run( Unknown Source)
                              at java.security.A ccessController .doPrivileged(N ative Method)
                              at java.net.URLCla ssLoader.findCl ass(Unknown Source)
                              at java.lang.Class Loader.loadClas s(Unknown Source)
                              at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
                              at java.lang.Class Loader.loadClas s(Unknown Source)
                              at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
                              Exception in thread "main"

                              [/CODE]

                              There was no need to post your code because the exception indicates that the
                              JVM can't even find your class. It's a classpath problem; your .class file should
                              be stored somewhere in a path /foo/bar/dbMailMePackage/MailMeSolid.cla ss.
                              Then your classpath should contain the directory /foo/bar/

                              kind regards,

                              Jos
                              Very cool Jos, thanks for your input on this one!

                              I wanted to demonstrate that indeed a class does exist, I just could not figure out why it was saying it is not there. So .class is not where it should be eh!

                              Super, let's try that, thanks Jos...

                              In a bit!

                              Comment

                              • JosAH
                                Recognized Expert MVP
                                • Mar 2007
                                • 11453

                                [QUOTE=Dököll]
                                Originally posted by JosAH
                                Very cool Jos, thanks for your input on this one!

                                I wanted to demonstrate that indeed a class does exist, I just could not figure out why it was saying it is not there. So .class is not where it should be eh!

                                Super, let's try that, thanks Jos...

                                In a bit!
                                The classpath mechanism is extremely easy actually: if you have a class
                                foo.bar.YourCla ss (foo and bar are package names) then a .class file should
                                exist somewhere in a directory X/foo/bar/YourClass.class . The X part should
                                be an element in the classpath variable. Check your compiler flags for the
                                option that stores the compiled files in their correct directory.

                                kind regards,

                                Jos

                                Comment

                                Working...