its a simple program thats return the weight of the dog bt whenever any one entered a negative weigh it ll also display that as a positive weight
for eg if enter -50 it ll show you +50 or 50 ....but it is just repeating the 1st entered weight i.e 45
so if u entered 45 once and -80 on second time the o/p should be 45 & 80 not 45 and 45
plz tell me whats wrong in the code so that i can learn
thnx in advance
public class Dog { private int weight; public int getweight() { return weight; } public void setweight(int newweight){ if (newweight > 0){ weight = newweight; } } }public class TestDog { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Dog d = new Dog(); //System.out.print("the weight of the dog is " + d.getWeight()); d.setweight(45); System.out.print(" the weight of the dog is " + d.getweight()); String newLine = System.getProperty("line.separator"); System.out.println("" + newLine + ""); d.setweight(-25); System.out.print("the weight of the dog is " + d.getweight()); } }