Presentation is loading. Please wait.

Presentation is loading. Please wait.

By - Qiong Han. DON’T FALL BEHIND IN READING Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets.

Similar presentations


Presentation on theme: "By - Qiong Han. DON’T FALL BEHIND IN READING Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets."— Presentation transcript:

1 By - Qiong Han

2 DON’T FALL BEHIND IN READING

3 Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets (graded by the LAs) in tomorrow’s class And don’t forget to submit the ZIPped file to our ftp site. It’s should be done by Thursday @midnight.

4 Submission Instruction Any questions about the submission?

5 Function v.s. Procedure What are the differences between them? Function will return some certain value Procedure will not

6 Assignment Statement public void setHeight(double newHeight) { height = newHeight }

7 Assignment Statement Previously we’ve used the “return” statement, now here comes the new one: public void setHeight(double newHeight) { height = newHeight; ^^^^^^^^^^^^^^^^^ Assignment Statement: Assign a value (could be a number, constant or variable) to a.variable }

8 What are the properties? public class C () { public int m = 100; public int getD() { return m; } public void setD(int i) { m = i; } public int getC() { return m*100; } public int convert (int i) { return i*100; }

9 Tracing Method Calls public class ABMISpreadsheet { double height; public double getHeight() { System.out.println (“getHeight Called”); return height; } public void setHeight(double newHeight) { System.out.println (“setWeight Called”); height = newHeight; } double weight; public double getWeight() { System.out.println (“getWeight Called”); return weight; } public void setWeight(double newWeight) { System.out.println (“setWeight Called”); weight = newWeight; } … }

10 Tracing Property-Values public class ABMISpreadsheet { double height; public double getHeight() { System.out.println (“Height:”+height); return height; } public void setHeight(double newHeight) { height = newHeight; System.out.println (“Height:”+height); } double weight; public double getWeight() { System.out.println (“Weight:”+weight); return weight; } public void setWeight(double newWeight) { weight = newWeight; System.out.println (“Weight:”+weight); } … }

11 Print Statement System.out.println(“setWeight called”);print statement Actual Parameter method invocation/call Method Name interactive call Target Object programmed call

12 Print Statement System.out.println(“setWeight called”); Or System.out.println(weight); Or System.out.println(“The value of weight is”+weight); Or System.out.println(“Weight:”+weight+”Height:”+height);

13 Overloading System.out.println(“setWeight called”); System.out.println(newWeight); Context of Actual Parameters Two different operations with same name String double public void println (String val) {…} public void println (double val) {…} Operation Definitions

14 Variable Declaration Errors public class ABMISpreadsheet { double height; public double getHeight() { return height; } public void setHeight(double newHeight) { height = newHeight; } double weight; public double getWeight() { return weight; } public void setWeight(double newWeight) { weight = newWeight; } public double getBMI() { return weight/(height*height); } Undefined variable double weight; Multiply defined variable double height;

15 Variable Declaration Errors How 2 avoid this? Always define a variable before you use it. So, when you’re using a variable, make sure it has been defined. In one class or method, never define the same variable twice or even more in one method. The computer will be confused about the exact type of this variable

16 How 2 correct an error? Double-click the error, the VJ++ will take to the line containing the error. Then correct the errors and build again.


Download ppt "By - Qiong Han. DON’T FALL BEHIND IN READING Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets."

Similar presentations


Ads by Google