?
Solved

Cannot figure out what I am doing wrong

Posted on 2004-09-21
10
Medium Priority
?
198 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:biloonline
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 100 total points
ID: 12118101
public void setWeight(String theWeight) {
               weight = theWeight;
}
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 12118102
>>public void setWeight(theWeight) {

should be

public void setWeight(int theWeight) {

or maybe

public void setWeight(double theWeight) {



0
 
LVL 37

Expert Comment

by:zzynx
ID: 12118103
You forgot the type of the parameter
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 37

Expert Comment

by:zzynx
ID: 12118109
I think String since it is called like

dog1.setWeight("20 LB");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118111
>>
public String getWeight(){
              return weight;
>>

should be

public String getWeight(){
              return weight;
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118116
>>I think String

OK - but the key point is - you need a parameter *type*
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12118128
>> OK - but the key point is - you need a parameter *type*
That's for sure ;)
0
 

Author Comment

by:biloonline
ID: 12118159

>>
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12118194
8-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12118414
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question