Chapter 2-Fields, Constructor, Method, Accessor, Mutator, substring, Calling method, Encapsulation

Basic Structure of OOP

IMG_2683.JPG

Key Concepts

屏幕快照 2016-12-23 下午11.36.11.png%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-23-%e4%b8%8b%e5%8d%8811-36-22

2.21

public pet(String petName)
{
name = petName
}

2.22

public Date(String dateYearMonthDay)
{
yearMonthDay = dateYearMonthDay
}

2.26

public int getTotal()
{
return Total;
}

2.33

public void increase(int points) {
score+=points; //compound assignment statement
}

2.36

My cat has green eyes.

2.37

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-23-%e4%b8%8b%e5%8d%8811-40-21

2.41

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-23-%e4%b8%8b%e5%8d%8811-40-57

2.43

屏幕快照 2016-12-23 下午11.41.18.png

未知.png

2.44

2.png

2.45

3.png

2.48

if (amount <= 0)
{
System.out.println(“Use a positive amount rather than: ”+ amount);
}else{
balance = balance + amount;
}

2.54

4.png

2.56 2.57

5.png

Calling method

6.png

7.png

substring is a method. An index value of zero represents the first character of a string, so getLoginName takes the first four characters of the name string and the first three characters of the id string and then concatenates them together to form a new string. This new string is returned as the method’s result. For instance, if name is the string “Leonardo da Vinci” and id is the string “468366”, then the string “Leon468” would be returned by this method.

11.png

22

When I typed in “cat”+9+3, the system did not output the result of 9+3 but both 9 and 3. Why?

Encapsulation

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-23-%e4%b8%8b%e5%8d%888-12-52

留下评论