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:
--------------------Config uration: Hw2Pr2 - JDK version 1.5.0 <Default> - <Default>----------------- ---
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Hw1Pr2\Hw2Pr 2\Hw2Pr3.j ava:20: <identifier> expected
public void setWeight(theWeight) {
^
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Hw1Pr2\Hw2Pr 2\Hw2Pr3.j ava:27: ')' expected
}
^
2 errors
Process completed.
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
Dog dog2 = new Dog();
dog2.setWeight("30 LB");
System.out.println("dog2's
}
}
class Dog {
private String weight;
public void setWeight(theWeight) {
weight = new String(theWeight);
}
public String getWeight(){
return weight;
}
}
It's giving me 2 errors:
--------------------Config
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Hw1Pr2\Hw2Pr
public void setWeight(theWeight) {
^
C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\Hw1Pr2\Hw2Pr
}
^
2 errors
Process completed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You forgot the type of the parameter
I think String since it is called like
dog1.setWeight("20 LB");
dog1.setWeight("20 LB");
>>
public String getWeight(){
return weight;
>>
should be
public String getWeight(){
return weight;
}
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*
>> OK - but the key point is - you need a parameter *type*
That's for sure ;)
That's for sure ;)
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