java put name before the variable name.
public class test { public static void main(String[] args) { Picture rocket = new Picture("mariner4.jpg"); rocket.translate(200, 200); rocket.draw(); Picture planet = new Picture("mars.gif"); planet.grow(-50, -50); planet.draw(); } }
public class test { public static void main(String[] args) { Day birthday = new Day(1951, 5, 26); Day lastDay = new Day(2012, 5, 26); int daysAlive = lastDay.daysFrom(birthday); System.out.println(daysAlive); } }
variable can vary and assignment has no type.
int numberOfPixels = object.methodname(arguments)
public class test { public static void main(String[] args) { Rectangle box = new Rectangle(60, 90, 20, 30); Rectangle box2 = new Rectangle(80, 120, 20, 30); box.draw(); box2.draw(); } }
public class test { public static void main(String[] args) { String river = "Mississippi"; int numberOfLetters = river.length(); System.out.println(numberOfLetters); } }
replace method
public class test { public static void main(String[] args) { String river = "Mississippi"; String result = river.replaceAll("i","x"); System.out.println(result); } }
cut space with trim()
String messyString = "Hello, Space!"; messyString.trim()
AccessorとMutator:「Accessor=アクセスするヤツ」、「Mutator=mutate(訳すと変化させる)」
An accessor method is used to return the value of a private field.
A mutator method is used to set a value of a private field. It follows a naming scheme prefixing the word “set” to the start of the method name.
Implement test program, set actual result and expected result.