Solved

Cannot figure out what I am doing wrong

Posted on 2004-09-21
10
196 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 25 total points
ID: 12118101
public void setWeight(String theWeight) {
               weight = theWeight;
}
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 25 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

626 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