So basically, I decided to go back in time over my winter break to catch up on some exercises and knowledge where I've fallen behind. I went back to some earlier text book stuff to try to catch up over winter break. So now, I'm back at exercise 95 and need help, which I would totally appreciate. Here are the intructions:
I need help with b:
You may have noticed that the Person class's talk instance method causes a small decrease to occur in the value of the instance variable myWeight each time it is called. If eric is an instance of the Person class with an initial weight of 67.2kg, what will his weight be after five calls to talk? Modify the following code by adding an accessor method for the instance variable myWeight. Then run the program and verify your answer to part (a). public class Person { private double myHeight; private double myWeight; private String myHair; public Person( double height, double weight, String hair ) { myHeight = height; myWeight = weight; myHair = hair; } public void sleep( int hours ) { for ( int i = 0 ; i < hours ; i++ ) System.out.println( "Sleeping ... " ); } public void talk() { myWeight -= 0.01; System.out.println( "Talking ... " ); }
The above is code I'm not allowed to edit. Here is what I wrote:
public void getWeight(){ return myWeight; } public static MyWeightIs (double myWeight) { Person John = new Person (2.5, 40.2, "multicolored"); return John.getWeight() ); }
Here is the code that comes after that I can't edit:
So whatever I can't edit is written in stone essentially. I'll try any suggestion. Thanks so much.
NOTE: ignore the earlier "& #65279" because that just appeared in the preview window, in case it shows up. I didn't write that part.