8. Methods 1


#1

I need help,

I dont get the Exercice Add a method called bark to the Dog class by typing:

    class Dog{
      
      int age;
    
    	public Dog(int dogsAge) {
        
        age = dogsAge;
        
      }
      
      public void bark() {
        
        System.out.println("Woof!");
        
      }
    
    
    	public static void main(String[] args) {
        
        Dog spike = new Dog(7);
    
    	}
    
    }

This is the code i got from the Website he sais its the right but when i press run it s sais wrong

I need Help!


#2

What does it say is wrong?


#3

Look at where your class delimiters are. You have closed the entire class including the public static void main in one declaration. Any java interpreter will spit an error.


#4

Could you explain exactly how i can resolve the problem @dondabreraozemail_co


#5

Did you edit your original entry ? I thought I saw an extra } when I looked at it the first time


Ok I had some time to get back to this issue. There is nothing wrong with your code as you have it now. I thought I saw an extra } bracket previously. May have been another problem I was looking at though. Anyway, your code as it stands is good. I've been checking all the problems here on Java's Netbeans IDE.
If you still can't get it to run, one or more of the following reasons persist.
1) The codecademy interface is a bit weird. There is a problem in the parser that checks the user input. Sometimes it will accept whitespace between things like
public void bark () and sometimes not public void bark()
2) What browser are you using ? I had problems with IE11 and switched to Firefox.
Whoever programmed these lessons did'nt pay a lot of attention to letting users fix input errors.


#6

No, but i fixed the Porblem.
Now my problime is the exercice with "pubic void run () { ...}". Dont no where to put it


#7

This is another dog class method. Just put it directly underneath the
public void bark method.
All class methods and fields have to go before the last bit of code which is

public static void main .......

This is what I complained about in an earlier post. It's an extremely bad idea to end a class declaration with
public static void main

This should be in a separate module by itself when you start using a development environment like Netbeans or Eclipse


#8

Thanks but to go sure could you send the code how i need to write it. Thanks!


#9

No you need to do it yourself. How did you manage to write the code for
public void bark ?

Use it as an example


#10

How did you fix this problem anyway ? I'm curious.


#11

I have the same issue.


#12

I have the same problem too


#13

Please clarify what you need explaining


#14

Please clarify what you need explained


#15

having same problem, checked it several times :frowning:


#16

I have the same issue. And it happens only on the second part of the problem.
I checked it a zillion times. I typed inside it. Perhaps its a bug?


#17

@mariaazharkhan, @jocremustech

  1. Go here https://discuss.codecademy.com/c/learn-java/object-oriented-programming
  2. Use the + New Topic button
  3. Fill in the template
  4. Someone will help

#18