diff --git a/src/classes/field_access.md b/src/classes/field_access.md index 09865939..d38fca27 100644 --- a/src/classes/field_access.md +++ b/src/classes/field_access.md @@ -1,7 +1,7 @@ # Field Access You can access the value of any field in a class by writing the name of a variable holding an instance -of that class, `.`, then the name of that field. +of that class, plus a `.`, then the name of that field. ```java class Muppet { diff --git a/src/instance_methods/challenges.md b/src/instance_methods/challenges.md index 45cc118f..64612248 100644 --- a/src/instance_methods/challenges.md +++ b/src/instance_methods/challenges.md @@ -111,34 +111,6 @@ void main() { ## Challenge 4. -Make a `Rectangle` class which has a `width` field and a `height` -field. Give it an instance method named `toCharArray` which gives -a `char[]` that can be printed to display a rectangle of the given -width and height. - -```java,editable -// ------------ -// CODE HERE -// ------------ - -void main() { - Rectangle rectangle = new Rectangle(); - rectangle.width = 3; - rectangle.height = 4; - - /* - *** - *** - *** - *** - */ - char[] c = rectangle.toCharArray(); - IO.println(c); -} -``` - -## Challenge 5. - Update the definition for the `Taco` class so that it has a method named `deluxe`. This should set the taco to have beef, sour cream, cheese, and onion. Use the existing instance methods instead of directly accessing @@ -185,7 +157,7 @@ void main() { } ``` -## Challenge 6. +## Challenge 5. Why doesn't this code function as you'd expect? Fix it by changing one line. @@ -203,4 +175,32 @@ void main() { oscar.setGrouchy(true); IO.println(oscar.grouchy); } -``` \ No newline at end of file +``` + +## Challenge 6. + +Make a `Rectangle` class which has a `width` field and a `height` +field. Give it an instance method named `toCharArray` which gives +a `char[]` that can be printed to display a rectangle of the given +width and height. + +```java,editable +// ------------ +// CODE HERE +// ------------ + +void main() { + Rectangle rectangle = new Rectangle(); + rectangle.width = 3; + rectangle.height = 4; + + /* + *** + *** + *** + *** + */ + char[] c = rectangle.toCharArray(); + IO.println(new String(c)); +} +```