|
SESSION 6 Part8 |
Exercises |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
So finally, I have a test.
Let's try reviewing
what we've done today.
Write the answers inside
the main functionof KNMain.java.
The sentence you wrote before
in the main function (on line 20)
is no longer needed
so it's fine
to delete it. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You've worked hard.
There were a lot of
things
to remember
today. |
|
|
|
I'm still fine,
I promise! |
|
|
|
|
|
|
|
Exercise 1 |
|
Question 1:
Please make the following text display in
the standard output. |
|
Today when I went to the local takoyaki store to buy
takoyaki,it started raining.
I didn't have an umbrella so I was thinking of going
home,
but
I figured it was okay so I forged on ahead.
But when I went there, the store was closed.
I forgot that today was a holiday.
When I started to return home, the rain became a
downpour, and I was completely soaked.
This always happens, and it's like I'm a rain-caller.
I give up, I've got make a habit of taking a folding
umbrella
with me. |
|
Note: takoyaki is a popular type of food in Japan. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
H-hang on…
Is this about me…!?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Hoho~♪ |
|
|
|
B-but how
did you know!? |
|
|
|
|
This might get
scary soon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now, now,
do your best on the test. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For now I'll endure…
For now I'll endure…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tap tap |
|
|
Geez!!
Later I'm gonna
tell you off!
But I didn't write it in
my diary or anything…
|
|
|
|
|
|
|
|
Koto's answer code(KotoTest's KNMain.java) from line 17 |
|
・・・ |
|
|
|
017 |
|
public static void
main(String[] args) { |
|
018 |
|
// TODO code
application logic here |
|
019 |
|
|
|
020 |
|
//System.out.println("Hello
world!"); |
|
021 |
|
|
|
022 |
|
System.out.println("Today
when I went to the local takoyaki store to buy"); |
|
023 |
|
System.out.println("takoyaki,it
started raining."); |
|
024 |
|
System.out.println("I
didn't have an umbrella so I was thinking of going
home,"); |
|
025 |
|
System.out.println("but
I figured it was okay so I forged on ahead."); |
|
026 |
|
System.out.println("But
when I went there, the store was closed."); |
|
027 |
|
System.out.println("I
forgot that today was a holiday."); |
|
028 |
|
System.out.println("When
I started to return home, the rain became a"); |
|
029 |
|
System.out.println("downpour,
and I was completely soaked."); |
|
030 |
|
System.out.println("This
always happens, and it's like I'm a rain-caller."); |
|
031 |
|
System.out.println("I
give up, I've got make a habit of taking a folding
bumbrella"); |
|
032 |
|
System.out.println("with
me."); |
|
033 |
|
} |
|
・・・ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Oh, are you done?
Oh!?
You didn't delete the program
(line 20)
you wrote before…
but instead left it as a comment?
This is a method called
"to comment out",
where you disable a program
by
turning it into a comment.
It is used when testing, for
processes that you
want to stop
temporarily, and for debugging
and
searching for the cause of errors.
Of course, it can also be used to
preserve code,like you've done here.
You understood that very well.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Wow, really!?
I just didn't want to delete
it
because it's my very first
commemorative program,
but…
Is it really okay to leave it?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ahh, well,
it's okay, but…
You're so girlish
like that. |
|
|
|
Ehehe |
|
|
|
|
Run Results (Output Window)
(sorry.this is a japanese version.) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
How is it?
I think it displayed properly,
but…
…was I right? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The run results seem to
be
displayed properly.
Not bad at all. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*heart
pounding* |
|
|
|
Fuu~
|
|
|
|
Boo. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Geez,
it's good enough,
isn't it? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I'm not saying it's not good enough.
There isn't just one way of
constructing a program.
It's fine to use character string linking,
and there's also ways to do it that
I haven't told you yet.
Even if there is just one goal,
there's not just one answer.
When you need processing speed, or
when you're creating with lots of
people…
Even if what you create is the same,
there's various ways that you can do it.
So it's important to be flexible.
A program is where your individuality
shines through.
Isn't that true for drawing a picture? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It really is
true. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Hmm….
Yeah, it is.
Even if you draw the
same thing,
Each person's picture
is different.
So programs are like
that, too. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Just like that!
So, let's end for today
at a point we understand.
There were lots of things
to remember this time.
Are you still going to follow
along with me? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You worked hard |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Of course!
I'm still fine!
Cuz I'm gonna check
later
and practice. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Yes, try reviewing again
any points
that were
unclear.
I think you'll get the
hang
of it. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ahhhh.
I'm tired but
it was fun. |
|
|
|
OTSUKARE-
SUNday |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It ended up getting long
this time, too.
Next time will be How to
write a program part 2.
I'm planning to do
operators and variables.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Okay!
I'm gonna do
my absolute best!
Thank you so much.
Please help me out
next time too!! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Learn to touch-type |
Typing speed is not necessarily needed for
writing programs.
However, you will be able to write a lot of
code.
It could be said that touch-typing is
indispensible when typing for
long periods.
If you use a typing game,
you will enjoy yourself as you become capable of
touch-typing.
Please consider trying it out.
|
|
|
Understand the structure of source files |
The source file is the foundation file that
creates the program.
You need to properly grasp its structure.
Comments, packages, imports, classes, and the
main function
are its major components.
At this stage, it's fine if you have a basic
grasp of their names, where to enter them,
and a summary of what they do, so please
remember these things.
They will appear many times in the future, so we
think you'll come to understand them naturally.
Not all components have appeared in the sessions
so far.
We are avoided being complicated, so there are
components we are intentionally postponing or
omitting.
In future we will expand the images and explain
them where needed.
|
|
|
Understand the program flow |
Java application programs start with the main
function,
and end with completion of the main function.
The flow for running the source file is "from
top to bottom".
It's simple, right? You create something complex
via simple assembly.
Surprisingly, this may be true for most things.
In future we will be studying a different flow.
But they are basically simple.
|
|
|
Remember the basics of how to write programs |
Programs are also a "language".
Although the form is different, they are
essentially a substitution for English.
If you don't really understand, you might try
thinking about them by substituting them with
English.
There is not just one way of creating programs.
Even for something which has the same goal,
there are various ways to create it,
such as placing importance on execution speed,
or expandability, or development speed.
This is where you can show your own style.
Try to make sure you are always flexible. |
|
|
|
Terms for today |
Bug |
Debug |
Error |
Package |
Class |
Main function (main method) |
Comment |
Definition |
Block |
Statement |
Indent |
Comment out |
|
|
|
The number of things to remember has increased quite a lot.
Let's take our time as we move forward. |
|
|
|
|
|
|
|
|
|
|
|
|