You are on page 1of 3

COMP 1130

Computer
Programming I

Due Date: Thursday, September 21, 2023 (see Assignment section below)
Exercises & Assignment 1: Getting Started
Objectives
 Getting familiar with Java
 Creating, editing, compiling, and running your first Java program—and probably do some debugging!
 Opportunity to provide your instructor some interesting details about yourself

1. The “Hello World” program. Create, save, compile, and run, the following “Hello World” program:

/* HelloWorld - this program displays a simple message to user, and the


current date; testing the Java compiler and JVM/JRE are running
properly.
*/

public class HelloWorld


{
public static void main (String[] args)
{
String greeting = "Hello World"; // store message

System.out.println (greeting); // display message


System.out.println (); // display blank line

}// end of main()


}// end of class

2. Your Personal Profile.


Using the HelloWorld as example, create a new program class: PersonalProfile, save as
PersonalProfile.java
and replace ***** with your study discipline. See the example at the end of this document for
commenting include.

Within the main() method, include the necessary System.out.println() statements that,
 display your name, and nickname (if you have one); ex: “My name is Bob Smith, but people
call me Bibbles.”
 display your academic study discipline (such as, Computing Science, Bachelor of Science,
Fine Arts, Business, etc.)
 display some interesting details about yourself, that you are willing to share
COMP 1130
Computer
Programming I

3. The “An Emergency Broadcast” program, and creating some errors.


Part 1 - [From PP 1.1]
Create, save, compile, and run, the following program as Test.java
// Test.java - display an alert message to the console.

public class Test


{
public static void main (String[] args)
{
System.out.println ("An Emergency Broadcast"); // display message
}// end of main()
}// end of class

Compile and run the program. If the compiler indicates any syntax errors, fix them (the program is
correct as shown).

Part 2 - [From PP 1.2] Create some errors.


Introduce the following changes to produce compiler (syntax) errors, one at a time, to the Test
program above. Record the compiler error messages, then reverse the change before proceeding to
the next change.
If no compiler error message is produced, can you think why not?

Record your observations (the error message, or when an error is not produced) in a document.

The changes (introduce one at a time, and reverse before proceeding to the next):
a. change public class Test to public class test
b. change Emergency to emergency
c. remove the first quotation mark in the string: ("An … to (An …
d. remove the last quotation mark in the string: Broadcast”); to Broadcast);
e. change main to man
f. change .println( to .bogus(
g. remove the semicolon (;) at the end of the .println statemet
h. remove the very last brace } in the program

Note: What to Upload

Question 1: Attach a screenshot of command prompt after executing the program.


Question 2: Attach a screenshot of command prompt after executing the program. Also attach
the .java file.
Question 3 Part 1: Attach a screenshot of command prompt after executing the program.
Question 3 Part 2: Write your understanding after making the changes.
COMP 1130
Computer
Programming I

** Create a .pdf file and upload on Moodle

Example output, from a program named PersonalProfile.java, running the class PersonalProfile.class,

Personal Profile of Vijal Jain, student number T0123456

I was born in ……...

I am in the ***** program at TRU, and taking An Introduction to Programming, and


this is one of my first Java programs!

When not studying, I enjoy reading comics, hiking, watching dramas, listening to
music.

You might also like