Link to home
Start Free TrialLog in
Avatar of biloonline
biloonline

asked on

Cannot figure out what I am doing wrong

This should be fairly easy for someone who is not exhausted as I am.
Here is my code:

public class Hw2Pr3 {
      public static void main(String[] args) {
            Dog dog1 = new Dog();
            dog1.setWeight("20 LB");
            System.out.println("dog1's weight is " + dog1.getWeight());
            
            Dog dog2 = new Dog();
            dog2.setWeight("30 LB");
            System.out.println("dog2's weight is " + dog2.getWeight());
            
      
      }
}


class Dog {
      private String weight;
      
            public void setWeight(theWeight) {
                  weight = new String(theWeight);
            }
            
            public String getWeight(){
                  return weight;
            
      }      
}

It's giving me 2 errors:
--------------------Configuration: Hw2Pr2 - JDK version 1.5.0 <Default> - <Default>--------------------
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Hw1Pr2\Hw2Pr2\Hw2Pr3.java:20: <identifier> expected
                public void setWeight(theWeight) {
                                               ^
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Hw1Pr2\Hw2Pr2\Hw2Pr3.java:27: ')' expected
        }      
               ^
2 errors

Process completed.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You forgot the type of the parameter
I think String since it is called like

dog1.setWeight("20 LB");
>>
public String getWeight(){
              return weight;
>>

should be

public String getWeight(){
              return weight;
}
>>I think String

OK - but the key point is - you need a parameter *type*
>> OK - but the key point is - you need a parameter *type*
That's for sure ;)
Avatar of biloonline
biloonline

ASKER


>>
public String getWeight(){
              return weight;
>>

should be

public String getWeight(){
              return weight;
}

<--- That's exactly what I have.

Problem was I was missing the 'String' in public void setWeight(theWeight) {

Thanks guys again, you are a big help.
8-)
Thanks