Köll & Sam Classroom Blog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #31
    Here is what kept me up last night:

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #32
      Originally posted by Dököll
      Here is what kept me up last night:

      http://www.thescripts.com/forum/show...78#post2844578
      "Class or interface expected error"

      A right curly brace too many in the middle of the code; keep that one in mind.
      The line number from the error diagnostic is the give away.

      kind regards,

      Jos

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #33
        Originally posted by JosAH
        "Class or interface expected error"

        A right curly brace too many in the middle of the code; keep that one in mind.
        The line number from the error diagnostic is the give away.

        kind regards,

        Jos
        Here's one that's not a give-away. I thought that it was going to keep me up all night, but it all of the sudden just went away. The error message was "C:\Documen ts and Settings\Sam\My Documents\CSD22 4\Homework\Chap ter3\Assignment s\KilowattApple t.java:12: KilowattApplet is not abstract and does not override abstract method actionPerformed (java.awt.event .ActionEvent) in java.awt.event. ActionListener
        public class KilowattApplet extends Applet implements ActionListener"

        Code was
        Code:
        // Chapter: 3, Programming Assignment 6
        // Programmer: Sam Barrett
        // Date:  24 Sep 2007
        // Filename: KilowattApplet.java
        // Program: Applet
        // Purpose: Calculate Annual Appliance Running Cost
        import java.applet.*;
        import java.awt.*;
        import java.awt.event.*;
        public class KilowattApplet extends Applet implements ActionListener
        {
         public void init()
         {
          this.lblWelcome = new Label("Welcome to the Appliance Energy Calculator");
          this.lblCost = new Label("Please enter the cost per kilowatt-hour in cents:		   ");
          this.txtCost = new TextField(10);
          this.lblHours = new Label("Please enter the kilowatt-hours consumed:				  ");
          this.txtHours = new TextField(10);
          this.btnCalculate = new Button("Calculate");
          this.lblRunningCost = new Label("Click the Calculate Button to display the average energy cost	   ");
        		setForeground(Color.black);  // Never use Purple, some of us cannot see the text
        		add(this.lblWelcome);
        		add(this.lblCost);
        		add(this.txtCost);
        		add(this.lblHours);
        		add(this.txtHours);
        		add(this.btnCalculate);
        		this.btnCalculate.addActionListener(this);
        		add(this.lblRunningCost);
         }
         public void actionPreformed(ActionEvent e)
         {
          double dCost = Double.parseDouble(this.txtCost.getText());
          double dHours = Double.parseDouble(this.txtHours.getText());
          double dAverage = dCost * dHours;
          this.lblRunningCost.setText("The average annual cost to operate this appliance is $" + Math.round(dAverage*100)/100D);
         }
         // Components
         private Label lblWelcome;
         private Label lblCost;
         private TextField txtCost;
         private Label lblHours;
         private TextField txtHours;
         private Button btnCalculate;
         private Label lblRunningCost;
        }
        The funny thing was that someone else in class had the same error and it took us as a class at least 30 minutes to find the mistake!

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #34
          Originally posted by SammyB
          Here's one that's not a give-away. I thought that it was going to keep me up all night, but it all of the sudden just went away. The error message was "C:\Documen ts and Settings\Sam\My Documents\CSD22 4\Homework\Chap ter3\Assignment s\KilowattApple t.java:12: KilowattApplet is not abstract and does not override abstract method actionPerformed (java.awt.event .ActionEvent) in java.awt.event. ActionListener
          public class KilowattApplet extends Applet implements ActionListener"
          I've seen that error diagnostic more than often and always I had misspelled the
          method name 'actionPerforme d'. I always tend to spell it with a leading capital A.
          Dunno why; my fingers seem to like that ;-)

          kind regards,

          Jos

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #35
            Originally posted by JosAH
            I've seen that error diagnostic more than often and always I had misspelled the
            method name 'actionPerforme d'. I always tend to spell it with a leading capital A.
            Dunno why; my fingers seem to like that ;-)

            kind regards,

            Jos
            I always forgot the first r and wrote it as actionPeformed

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #36
              Originally posted by r035198x
              I always forgot the first r and wrote it as actionPeformed
              The one I hate most is the PropertyChangeL istener with its propertChange method;
              it is called when the bound property has changed and I alway type those
              darn things as 'PropertyChange dListener' or 'propertyChange d' with a parameter
              type of 'PropertyChange dEvent'. I don't even check anymore: when I see the
              compiler whining again about classes not being declared abstract and yaddayadda,
              I simply remove the 'd' from the methods and inner classes ...

              kind regards,

              Jos

              Comment

              • SammyB
                Recognized Expert Contributor
                • Mar 2007
                • 807

                #37
                I guess that I should have realized that you-all would see it at once. It's one of those error messages that is so cryptic that you remember it. The funny thing was that I had no clue, but I had made some mistakes, so I retyped the code at the end and of course I was mystified as to why the message went away.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #38
                  Originally posted by SammyB
                  I guess that I should have realized that you-all would see it at once. It's one of those error messages that is so cryptic that you remember it. The funny thing was that I had no clue, but I had made some mistakes, so I retyped the code at the end and of course I was mystified as to why the message went away.
                  It's one of the compiler messages that are not tied to a specific line where some
                  syntax mistake should be. There is no syntactic mistake in that code; it was
                  just the fact that you stated that your class implements the ActionListener interface
                  which it effectively doesn't because there is no 'actionPerforme d' method defined;
                  the class isn't defined to be abstract either so all the compiler can tell you is what
                  I just wrote. It is a semantic mistake which the compiler checks for you.

                  kind regards,

                  Jos

                  Comment

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

                    #39
                    Originally posted by JosAH
                    "Class or interface expected error"

                    A right curly brace too many in the middle of the code; keep that one in mind.
                    The line number from the error diagnostic is the give away.

                    kind regards,

                    Jos
                    That sounds very familiar...just got word through Java forum on this:-)

                    Will keep this and any other curve balls in mind...

                    In a bit!

                    Comment

                    • SammyB
                      Recognized Expert Contributor
                      • Mar 2007
                      • 807

                      #40
                      Originally posted by Dököll
                      That sounds very familiar...just got word through Java forum on this:-)

                      Will keep this and any other curve balls in mind...

                      In a bit!
                      If I were you, I would download Eclipse, http://www.eclipse.org/downloads/ (top-most download). It is a Java IDE, looks alot like VB's IDE, has intellisense, and tutorials. You will have about an hour learning curve, but it makes development much easier!

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #41
                        Originally posted by SammyB
                        If I were you, I would download Eclipse, http://www.eclipse.org/downloads/ (top-most download). It is a Java IDE, looks alot like VB's IDE, has intellisense, and tutorials. You will have about an hour learning curve, but it makes development much easier!
                        Slight nitpick: Eclipse is *also* a Java IDE; Eclipse itself is about 'everything and
                        nothing' as they say so themselves. It's the JDT (Java Development Tool) that
                        makes Eclipse a Java IDE, but there's also a CDT (C and C++) and there's a whole
                        lot more to Eclipse; I use it on a daily basis; it's a great thing.

                        kind regards,

                        Jos

                        Comment

                        • SammyB
                          Recognized Expert Contributor
                          • Mar 2007
                          • 807

                          #42
                          Originally posted by JosAH
                          Slight nitpick: Eclipse is *also* a Java IDE; Eclipse itself is about 'everything and
                          nothing' as they say so themselves. It's the JDT (Java Development Tool) that
                          makes Eclipse a Java IDE, but there's also a CDT (C and C++) and there's a whole
                          lot more to Eclipse; I use it on a daily basis; it's a great thing.

                          kind regards,

                          Jos
                          nit received and agreed upon ;o)>>
                          But, since you use Eclipse on a daily basis, a couple of questions. As part of each chapter, we develop the sample application as an Applet. The book is assuming that you are using TextPad and gives you a three line Html program which not only calls the Applet, but also specifies the height & width. With Eclipse, I have not created the html document; I just use the menu: Run > Run As > Java Applet, which works OK, but I have to resize the Applet. How do you add the html doc to your project and run it instead of using the Run As command.

                          Second, it is annoying to have to press both the tab key and the Enter key to use an intellisense suggestion. Can I change the preferences so that the tab key alone selects & uses the current line?

                          Thanks!

                          Comment

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

                            #43
                            I have an open book next week. It'd be nice to see what else is out there thank you for ypur suggestion Sam. Hope all is well with your projects...Got a project due in two weeks, tonight's lab was not too bad can use some examples there. Must code, in a bit...

                            Comment

                            • SammyB
                              Recognized Expert Contributor
                              • Mar 2007
                              • 807

                              #44
                              Originally posted by Dököll
                              I have an open book next week. It'd be nice to see what else is out there thank you for ypur suggestion Sam. Hope all is well with your projects...Got a project due in two weeks, tonight's lab was not too bad can use some examples there. Must code, in a bit...
                              Projects are fine, but it's almost midnight and I'm not done yet for class tomorrow. Second test was very ugly: expecting about an 85, but I got 111 (there was extra credit) on the first test, so it evens out.

                              The most annoying problem was:
                              Insert parantheses, if necessary, to make the following statement correct
                              33 = 3*6-3+2+6*4-4/Math.pow(2,1)

                              Does she know how many different ways you could insert parens? Argh!

                              You are blessed to have an Open Book test!

                              Comment

                              • NeoPa
                                Recognized Expert Moderator MVP
                                • Oct 2006
                                • 32634

                                #45
                                Originally posted by SammyB
                                ...Does she know how many different ways you could insert parens? Argh!
                                ...
                                Are all the ones you're thinking about necessary Sammy?
                                If so, one example should be an adequate answer. She'll be looking for you not to parenthesise a sub-expression which is already hierarchically prioritised.

                                Comment

                                Working...