FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/strings/Turtle.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
strings
/
Turtle.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (39 loc) · 1 KB
Breadcrumbs
OnJava8-Examples
/
strings
/
Turtle.java
Copy path
File metadata and controls
40 lines (39 loc) · 1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// strings/Turtle.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import
java
.
io
.*;
import
java
.
util
.*;
public
class
Turtle
{
private
String
name
;
private
Formatter
f
;
public
Turtle
(
String
name
,
Formatter
f
) {
this
.
name
=
name
;
this
.
f
=
f
;
}
public
void
move
(
int
x
,
int
y
) {
f
.
format
(
"%s The Turtle is at (%d,%d)%n"
,
name
,
x
,
y
);
}
public
static
void
main
(
String
[]
args
) {
PrintStream
outAlias
=
System
.
out
;
Turtle
tommy
=
new
Turtle
(
"Tommy"
,
new
Formatter
(
System
.
out
));
Turtle
terry
=
new
Turtle
(
"Terry"
,
new
Formatter
(
outAlias
));
tommy
.
move
(
0
,
0
);
terry
.
move
(
4
,
8
);
tommy
.
move
(
3
,
4
);
terry
.
move
(
2
,
5
);
tommy
.
move
(
3
,
3
);
terry
.
move
(
3
,
3
);
}
}
/* Output:
Tommy The Turtle is at (0,0)
Terry The Turtle is at (4,8)
Tommy The Turtle is at (3,4)
Terry The Turtle is at (2,5)
Tommy The Turtle is at (3,3)
Terry The Turtle is at (3,3)
*/
Back
|
FazBrowse Home
|
New Git URL