0% found this document useful (0 votes)
16 views3 pages

Elementary Programming Tutorial Guide

This tutorial provides instructions for writing basic Java programs, including a 'HelloWorld' program, experimenting with compiler errors, calculating the area of a triangle, and checking divisibility of an integer. Students are required to submit their source code and results in a single Word file by a specified deadline. The tutorial emphasizes understanding error messages and debugging techniques.

Uploaded by

wydfifa23
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Elementary Programming Tutorial Guide

This tutorial provides instructions for writing basic Java programs, including a 'HelloWorld' program, experimenting with compiler errors, calculating the area of a triangle, and checking divisibility of an integer. Students are required to submit their source code and results in a single Word file by a specified deadline. The tutorial emphasizes understanding error messages and debugging techniques.

Uploaded by

wydfifa23
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Tutorial 1 Elementary Programming

MUST READ - Put all the source code and answers into a word file, NAME:
and upload the word file (just ONE Word file! name it with “your
ID+date”, e.g. 202512340001_20250930.doc).
STU ID:
Note: there’s a deadline for uploading.
DATE:

1. Start with the first program


a. Write a program named “HelloWorld”, which can be executed to carry out the
printing task of the string “Hello, world!” together with your name in one line, e.g.
“Hello, world! Lifeng”.
b. To compile and execute the program you will need a command window. (For
MS OS user: ) To create one, choose Run from the Start menu, type in “cmd” and
press Ok. (For Mac user: ) Choose Terminal from the tools.
Type “javac [Link]” to compile your program. If your prompt returns
‘silently’, compilation was successful. If error messages are displayed then you will
need to return to the editor and fix the typing mistakes. When you have fixed the
errors, save your file again, and recompile it.
c. Once it compiles, you may run the program by typing “java HelloWorld”.
Note the existence of two files: the source (.java file) that we edit, and the ‘runnable’
(.class file) that the compiler produces.

 SOURCE CODE (TEXT)


The text is needed. (PLEASE REMOVE THE PROMPT INFO IN
GRAY)
 EXECUTION RESULTS (TEXT OR SNAPSHOTS)

 THINKING ON THE QUESTION, DISCUSSION AND CONCLUSION


You have to write something here, about anything that
is not concluded above. Mainly the
thoughts/ideas/opinions/algorithms you used to solve the
task, and the method you designed or other things you’d
like to say.

2. Experiment with the compiler


Introduce some errors and re-compile the program. Try each one (as following) at a
time, which means make the error on purpose, save the program, and try to compile it.
Fix the error so that the program will compile and then try the next one. Suggested
errors:
 delete the “}” at the end of the file
 misspell “main” as “man”
 misspell “HelloWorld” as “helloworld”
 delete the “;”
 delete the closing “"”
 misspell “args” as “double”
It is important to become familiar with the error messages (some are not very helpful)
so that you can practise deducing the likely cause of mistakes. Note that the error is
often identified at the wrong location, or causes a different error to be indicated. You
need to think about what the compiler is telling you and some interpretation may be
required.
NOTE: always try to solve one error at a time, meaning that fix the first error, compile
it and then still fix the newly generated first one (if exists).

 SOURCE CODE (TEXT)

 EXECUTION RESULTS (TEXT OR SNAPSHOTS)

 DISCUSSION AND CONCLUSION

3. Write a program with three points (x1, y1), (x2, y2), (x3, y3) of a triangle, set the
value to be 1.5, -3.4, 4.6, 5, 9.5, and -3.4 respectively, and then calculate and display
the area. The formula for computing the area of a triangle is

TIP: a method from Math class (no need to import explicitly) can be invoked to
get the square root of a certain value, use like this: [Link](val)

 SOURCE CODE (TEXT)

 EXECUTION RESULTS (TEXT OR SNAPSHOTS)

 DISCUSSION AND CONCLUSION

4. Write a program that prompts the user to enter an integer and determines whether it
is divisible by 5 and 6, whether it is divisible by 5 or 6, and whether it is divisible by 5
or 6, but not both. Here is a sample run of this program:
Enter an integer: 10
Is 10 divisible by 5 and 6? false
Is 10 divisible by 5 or 6? true
Is 10 divisible by 5 or 6, but not both? true
 SOURCE CODE (TEXT)

 EXECUTION RESULTS (TEXT OR SNAPSHOTS)

 DISCUSSION AND CONCLUSION

You might also like