Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/classes/field_access.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
60 changes: 30 additions & 30 deletions src/instance_methods/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -203,4 +175,32 @@ void main() {
oscar.setGrouchy(true);
IO.println(oscar.grouchy);
}
```
```

## 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));
}
```
Loading