Description
Aims: 1. Get acquaint with the NetBeans Java programming environment.
2. Learn the structure and format of a Java program.
3. Use simple print statements to display text and symbols.
Procedure:
0. Use a computer with both JDK and NetBeans installed. Better though, install them yourself!
Please follow tutorial 1 for download and installation details.
To begin with, start NetBeans. The following illustrations are based on version 10.
1. Under NetBeans, create a New Project [Java] [Java Application].
Name the project FirstProgram and put it under the folder H:\JAVA_ASG1 or some other
location you prefer such as your Documents\NetBeansProjects\ folder. Tick the box “Create
Main Class” with name firstprogram.FirstProgram. Click Finish.
2. If you haven’t ticked the box in step 1, no regret! Create a New File [Java] [Java Class].
Name the class FirstProgram and put it under the project FirstProgram.
Let the Location be Source Packages and put it in package firstprogram. Click Finish.
FirstProgram
FirstProgram
FirstProgram
FirstProgram
firstprogram.FirstProgram
firstprogram
e.g. C:\ …\FirstProgram.java
Copyright © 2019 CUHK, Designed by Michael FUNG Page 2 of 5
3. Key in the following program with comment, the declaration statement and proper
style/indentation carefully. Remember to save the file frequently. Fill in also your own student
ID and name.
package firstprogram;
/**
* First Program in Java
* Aim: Get acquainted with the JDK + NetBeans programming environment
* Learn the structure and format of a Java program by example
*
* Remark: Type class names, variable names, method names, etc. AS IS
* You should type also ALL the comment lines (text in gray) AS IS too!
*
* I declare that the assignment here submitted is original
* except for source material explicitly acknowledged,
* and that the same or closely related material has not been
* previously submitted for another course.
* I also acknowledge that I am aware of University policy and
* regulations on honesty in academic work, and of the disciplinary
* guidelines and procedures applicable to breaches of such
* policy and regulations, as contained in the website.
*
* University Guideline on Academic Honesty:
* http://www.cuhk.edu.hk/policy/academichonesty
* Faculty of Engineering Guidelines to Academic Honesty:
* https://www.erg.cuhk.edu.hk/erg/AcademicHonesty
*
* Student Name : xxx
* Student ID : xxx
* Date : xxx
*/
As you type the program in the
Editor window, this Navigator
window will grow and change!
Output window shows you printouts as well as error and warning messages.
Some of them are clickable!
This window supports user interaction through keyboard inputs.
NaughtyWindow
Project window shows your
project organization tree
structure.
Editor window. Colour highlighting shows syntax of the code.
Press key
Copyright © 2019 CUHK, Designed by Michael FUNG Page 3 of 5
public class FirstProgram {
public void welcomeMessage() {
// TODO: write your own statements to show your SID in Arabic numerals and in Morse Code
System.out.print(“My SID is “);
System.out.println();
// TODO: write your own statements to display the first 5 letters of your Last Name
// in BIG capital letter font (ASCII Art)!
// Note: altogether there are NINE output lines
}
/**
* Starting point of your Java program, the main() method of your class
*/
public static void main(String[] args) {
// declare an object variable
FirstProgram myObject;
// create a new object and assign it to a variable
myObject = new FirstProgram();
// send message to your object
myObject.welcomeMessage();
}
}
4. Under NetBeans, pick menu [File] [Project Properties] Categories [Run]. Browse
and pick firstprogram.FirstProgram as [Main Class]. Try toggling some options
under Categories [Documenting] too. Click OK to dismiss the Project Properties dialog.
5. Build the project. If there are errors caused by typos, don’t panic. Double-click on the first
error message in the Output window. Check the error or bug, correct it and re-compile. Feel
tired? Take a rest.
6. When you finish and there is no more error, you are ready to try out the program.
7. Run the application. Enjoy your work.
Sample Output for FUNG with SID 1234567890:
M y S I D i s 1 2 3 4 5 6 7 8 9 0
M y S I D i n M o r s e C o d e i s . – – – – . . – – – . . . – – . . . . – . . .. . – . . . . – – . . . – – – . . – – – – . – – – – –
M y L a s t N a m e i s
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| _ _ _ | | | | | | \ | | | _ _ \
| | _ | | | | | \ | | | | \ /
| _ | | | | | | . ` | | | _ _
| | | | _ | | | | \ | | | _ \ \
\ _ | \ _ _ _ / \ _ | \ _ / \ _ _ _ _ /
8. Click menu [Run] [Generate Javadoc] and check your program’s documentation.
Note: IF you missed setting up the package name properly during file creation (Step 2&3,)
you may need to Right-clickRefactorMove (Ctrl-M) your class FirstProgram into
a new package named firstprogram in order to generate Javadoc successfully.
The following defines the look-and-feel of the alphabets A–Z in ASCII Art, which consists of the
space symbols , forward- and back-slashes / \, vertical bars |, minus symbols -, underscores _,
backticks `, single quotes ‘, dots ., carets ^, and uppercase letter Vee.
Copyright © 2019 CUHK, Designed by Michael FUNG Page 4 of 5
A: B: C: D: E:
F: G: H: I: J:
K: L: M: N:
O: P: Q: R: S:
T: U: V: W:
X: Y: Z:
Please be reminded of the following notes:
There is always one column of spaces between consecutive BIG letters of your Last Name.
Do not confuse the backtick ` and the single quote ‘.
Do not confuse the minus symbol – and the underscore _.
To print a backslash \, you should type double backslashes \\ in the program. It’s special.
Copyright © 2019 CUHK, Designed by Michael FUNG Page 5 of 5
Your Task:
Zip and Submit your whole NetBeans project folder in an archive file FirstProgram.zip (ZIP
instead of RAR or other file formats) via our Online Assignment Collection Box on Blackboard
button to complete the submission.
Marking Scheme and Notes:
1. The submitted program should be free of any typing mistakes, compilation errors and warnings.
2. Comment/remark, indentation, style are under assessment in every programming assignments
unless specified otherwise. This program gives you an example of a well-formatted source file.
Variable naming, proper indentation for code blocks and adequate comments are important.
3. We will check and grade your work on correctness of your submission file type and filename,
NetBeans project filename, package name, Java class filename, accuracy of your SID and the
corresponding Morse Code representation, as well as accuracy of your Last Name shown in
accordance to the ASCII Art look-and-feel we defined.
4. Remember to do your submission by the due date. No late submission would be accepted.
5. If you submit multiple times, ONLY the content and time-stamp of the latest one would be
counted. You may delete (i.e. take back) your attached file and re-submit. We ONLY take into
account the last submission.
University Guideline for Plagiarism
Attention is drawn to University policy and regulations on honesty in academic work, and to
the disciplinary guidelines and procedures applicable to breaches of such policy and regulations.
Details may be found at http://www.cuhk.edu.hk/policy/academichonesty/. With each
assignment, students are required to submit a statement that they are aware of these policies,
regulations, guidelines and procedures.