You are on page 1of 63

Fundamentals of Computing 1

Lecture Title:
Introduction Java Programming

@2013 by Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Carnegie Mellon university Email: nguyenthianhdao@duytan.edu.vn
Duy Tan University
Agenda

 Introduction to Java Programming


 Downloading and Installing JDK
 Introduction to Netbeans
 Basic Java programs with println
statements
 Static methods
 Exercises

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
2
Java
 Developed by Sun Microsystems
 Initiated by James Gosling and released in 1995
 Designed for embedded systems, web
apps/servers
 Runs on many platforms (Windows, Mac, Linux,
cell phones...)
 The language taught in this course

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh 3


Duy Tan University
3
Compile/run a program Java
1. Write it.
 code or source code: The set of instructions in a program.

2. Compile it.
• compile: Translate a program from one language to another.
 byte code: The Java compiler converts your code into a format named byte
code that runs on many computer types.

3. Run (execute) it.


 output: The messages printed to the user by a program.

source code byte code output


compile
run

4
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
4
Agenda

 Introduction to Java Programming


 Introduction to Netbeans
 Basic Java programs with println
statements
 Static methods
 Exercises

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh 5


Duy Tan University
5
Installing Netbeans
 https://www.oracle.com/technetwork
/java/javase/downloads/jdk-
netbeans-jsp-3413139-esa.html
 JDK with Netbeans IDE 8.2 for Java
developers

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
8
Introduction to Netbeans
 NetBeans IDE is a free, open source
 Supports application development in
various languages, including Java,
HTML5, PHP and C++…
 Runs on Windows, Linux, Mac OS X,
and other UNIX-based systems

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
9
Start Netbeans
 Start-> Netbeans 8.2

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
10
Start Netbeans

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
11
Agenda

 Introduction to Java Programming


 Introduction to Netbeans
 Basic Java programs with println
statements
 Static methods
 Exercises

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh 12


Duy Tan University
12
Structure of a Java program
public class name { class: a program
public static void main(String[] args) {
statement;
statement;
method: a named group
... of statements
statement;
}
} statement: a command to be executed

 Every executable Java program consists of a class,


 that contains a method named main,
 that contains the statements (commands) to be executed.
 A statement is terminated with a semicolon

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
13
A Java program
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
System.out.println();
System.out.println("This program produces");
System.out.println("four lines of output");
}
}
 Its output:

Hello, world!

This program produces


four lines of output

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
14
System.out.println
 prints a line of output on the console.
 Two ways to use System.out.println :
• System.out.println("text");
Prints the given message as output.
• System.out.println();
Prints a blank line of output.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
15
Java names
 Class Names : For all class names the first letter should
be in Upper Case
 Example: class MyFirstJavaClass
 Program File Name : Name of the program file should
exactly match the class name.
 Method Names - All method names should start with a Lower
Case letter.
 Example public void myMethodName()
 Case Sensitivity
 Java is case sensitive, which means identifier Hello and
hello would have different meaning in Java.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
16
Java identifiers
 All Java components require names. Names used for
classes, variables and methods are called identifiers.
 All identifiers should begin with a letter (A to Z or a to z) and
can have any combination of digit character (0 to 9), currency
character ($) or an underscore (_) but no spaces.
 A key word cannot be used as an identifier.
 Most importantly identifiers are case sensitive
 Example
legal: age, $salary, _value, __1_value
illegal: me+u, 49ers, side-swipe, Ph.D's, my value

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
17
Java keywords
 keyword: An identifier that you cannot
use because it already has a reserved
meaning in Java.
abstract default if private this
boolean do implements protected throw
break double import public throws
byte else instanceof return transient
case extends int short try
catch final interface static void
char finally long strictfp volatile
class float native super while
const for new switch
continue goto package synchronized

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
18
Syntax
 syntax: The set of legal structures and commands that
can be used in a particular language.
 Every basic Java statement ends with a semicolon ;
 The contents of a class or method occur between { and }
 …
 syntax error (compiler error): A problem in the
structure of a program that causes the compiler to fail.
 Missing semicolon
 Too many or too few { } braces
 Illegal identifier for class name
 Class and file names do not match
...

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
19
Syntax error example
1 public class Hello {
2 pooblic static void main(String[] args) {
3 System.owt.println("Hello, world!")_
4 }
5 }

 Compiler output:
Hello.java:2: <identifier> expected
pooblic static void main(String[] args) {
^
Hello.java:3: ';' expected
}
^
2 errors

 The compiler shows the line number where it found


the error.
 The error messages can be tough to understand!
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
20
String literal
 A sequence of characters to be printed.
 enclosed by the double quote
 The quotes do not appear in the output.

 Examples:
"hello"
"This is a string. It's very long!"
 Is used in method println
 Restrictions:
 May not span multiple lines.
"This is not
a legal String."
 May not contain a " character.
"This is not a "legal" String either."

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
21
Escape sequences
 escape sequence: A special sequence of
characters used to represent certain special
characters in a string literal.
\t tab character
\n new line character
\" quotation mark character
\\ backslash character
 Example:
System.out.println("\\hello\nhow\tare \"you\"?\\\\");

 Output:
\hello
how are "you"?\\
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
22
Questions
 What is the output of the following println
statements?
System.out.println("\ta\tb\tc");
System.out.println("\\\\");
System.out.println("'");
System.out.println("\"\"\"");
System.out.println("C:\nin\the downward
spiral");

 Write a println statement to produce this


output:
/ \ // \\ /// \\\
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
23
Answers
 Output of each println statement:
a b c
\\
'
"""
C:
in he downward spiral

 println statement to produce the line of


output:
System.out.println("/ \\ // \\\\ /// \\\\\\");
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
24
Questions
 What println statements will generate this output?
This program prints a
quote from the Gettysburg Address.

"Four score and seven years ago,


our 'fore fathers' brought forth on
this continent a new nation."

 What println statements will generate this output?


A "quoted" String is
'much' better if you learn
the rules of "escape sequences."

Also, "" represents an empty String.


Don't forget: use \" instead of " !
'' is not the same as "

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
25
Answers
 println statements to generate the output:
System.out.println("This program prints a");
System.out.println("quote from the Gettysburg Address.");
System.out.println();
System.out.println("\"Four score and seven years ago,");
System.out.println("our 'fore fathers' brought forth on");
System.out.println("this continent a new nation.\"");

 println statements to generate the output:


System.out.println("A \"quoted\" String is");
System.out.println("'much' better if you learn");
System.out.println("the rules of \"escape sequences.\"");
System.out.println();
System.out.println("Also, \"\" represents an empty String.");
System.out.println("Don't forget: use \\\" instead of \" !");
System.out.println("'' is not the same as \"");

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
26
Comments
 comment: A note written in source code by the
programmer to describe or clarify the code.
 Comments are not executed when your program runs.

 Syntax:
// comment text, on one line
or,
/* comment text; may span multiple lines */

 Examples:
// This is a one-line comment.
/* This is a very long
multi-line comment. */

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
27
Using comments
 Where to place comments:
 at the top of each file (a "comment header")
 at the start of every method (seen later)
 to explain complex pieces of code

 Comments are useful for:


 Understanding larger, more complex programs.
 Multiple programmers working together, who must
understand each other's code.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
28
Comments example
public class MyFirstJavaProgram{

/* This is my first java program.


* This will print 'Hello World' as the output
* This is an example of multi-line comments.
*/

public static void main(String []args){


// This is an example of single line comment
/* This is also an example of single line comment. */
System.out.println("Hello World");
}
}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
29
Agenda

 Introduction to Java Programming


 Introduction to Eclipse
 Basic Java programs with println
statements
 Static methods
 Exercises

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh 30


Duy Tan University
30
Algorithm
 algorithm: A list of steps for solving a problem.
 Example algorithm: Write a program to print these
figures using main method.
______
/ \
/ \
\ /
\______/

\ /
\______/
+--------+

______
/ \
/ \
| STOP |
\ /
\______/

______
/ \
/ \
+--------+

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
31
Development strategy
______ First version (unstructured):
/ \
/ \
\ /  Create an empty program and main method.
\______/

\ /  Copy the expected output into it, surrounding


\______/
+--------+
each line with System.out.println syntax.

/
______
\  Run it to verify the output.
/ \
| STOP |
\ /
\______/

______
/ \
/ \
+--------+

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
32
Program version 1
public class Figures1 {
public static void main(String[] args) {
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println("+--------+");
System.out.println();
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("| STOP |");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("+--------+");
}
}
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
33
Problems with version 1
 lack of structure: Many tiny steps; tough to remember.
 redundancy:
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println("+--------+");
System.out.println();
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("| STOP |");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("+--------+");
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
34
Structured algorithms
 structured algorithm: Split into
coherent tasks.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
35
Development strategy 2
______ Second version (structured, with redundancy):
/ \
/ \
\ /  Identify the structure of the output.
\______/

\ /
\______/  Divide the main method into static methods
+--------+
based on this structure.
______
/ \
/ \
| STOP |
\ /
\______/

______
/ \
/ \
+--------+

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
36
Output structure
______
/ \
/ \ The structure of the output:
 initial "egg" figure
\ /
\______/
 second "teacup" figure
\ /
 third "stop sign" figure
\______/
+--------+  fourth "hat" figure

______
/ \ This structure can be represented by methods:
/ \
| STOP |  egg
\ /
 teaCup
\______/
 stopSign
______
/ \  hat

/ \
+--------+ Instructor: Dao, Nguyen Thi Anh
Professor: Lynn Robert Carter
Duy Tan University
37
Program version 2
public class Figures2 {
public static void main(String[] args) {
egg();
teaCup();
stopSign();
hat();
}
public static void egg() {
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
}
public static void teaCup() {
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println("+--------+");
System.out.println();
}
...
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
38
Program version 2, cont'd.
...
public static void stopSign() {
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("| STOP |");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
}
public static void hat() {
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("+--------+");
}
}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
39
Removing redundancy
 A well-structured algorithm can describe repeated tasks
with less redundancy.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
40
Development strategy 3
______
/ \
/ \ Third version (structured, without redundancy):
\ /
\______/
 Identify redundancy in the output, and create
\ / methods to eliminate as much as possible.
\______/
+--------+
 Add comments to the program.
______
/ \
/ \
| STOP |
\ /
\______/

______
/ \
/ \
+--------+

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
41
Output redundancy
______
/ \
/ \
\ / The redundancy in the output:
\______/

\ /  egg top: reused on egg, stop sign, hat


\______/  egg bottom: reused on egg, teacup, stop
+--------+
sign
______  divider line: used on teacup, hat
/ \
/ \
| STOP |
\ /
This redundancy can be fixed by methods:
\______/  eggTop

 eggBottom
______
/ \  line
/ \
+--------+
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
42
Program version 3
// Prints several figures, with methods for structure and redundancy.
public class Figures3 {
public static void main(String[] args) {
egg();
teaCup();
stopSign();
hat();
}
// Draws the top half of an an egg figure.
public static void eggTop() {
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/ \\");
}
// Draws the bottom half of an egg figure.
public static void eggBottom() {
System.out.println("\\ /");
System.out.println(" \\______/");
}
// Draws a complete egg figure.
public static void egg() {
eggTop();
eggBottom();
System.out.println();
}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
43
Program version 3, cont'd.
// Draws a teacup figure.
public static void teaCup() {
eggBottom();
line();
System.out.println();
}
// Draws a stop sign figure.
public static void stopSign() {
eggTop();
System.out.println("| STOP |");
eggBottom();
System.out.println();
}
// Draws a figure that looks sort of like a hat.
public static void hat() {
eggTop();
line();
}
// Draws a line of dashes.
public static void line() {
System.out.println("+--------+");
}
}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
44
Static methods
 static method: a static method is a method
that belongs to a class rather than an instance of a class
class. The method is accessible to every instance
method A
of a class, but methods defined in an instance are  statement
only able to be accessed by that member of a  statement
class.  statement

 denotes the structure of a program


method B
 eliminates redundancy by code reuse  statement
statement
 procedural decomposition:

dividing a problem into methods method C


 statement
 statement
 statement

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
45
Using static methods
1. Design the algorithm.
 Look at the structure, and which commands are repeated.
 Decide what are the important overall tasks.

2. Declare (write down) the methods.


 Arrange statements into groups and give each group a name.

3. Call (run) the methods.


 The program's main method executes the other methods to
perform the overall task.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
46
Declaring a method
Gives your method a name so it can be executed
 Syntax:
public static void methodName() {
statement;
statement;
...
statement;
}

 Example:
public static void printWarning() {
System.out.println("This product causes cancer");
System.out.println("in lab rats and humans.");
}
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
47
Calling a method
Executes the method's code
 Syntax:
methodName();

 You can call the same method many times if you like.

 Example:
printWarning();

 Output:
This product causes cancer
in lab rats and humans.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
48
Program with static method
public class FreshPrince {
// This method prints the lyrics to my favorite song.
public static void rap() {
System.out.println("Now this is the story all about how");
System.out.println("My life got flipped turned upside-down");
}

public static void main(String[] args) {


rap(); // Calling (running) the rap method
System.out.println();
rap(); // Calling the rap method again
}

Output:
Now this is the story all about how
My life got flipped turned upside-down

Now this is the story all about how


My life got flipped turned upside-down

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
49
Methods calling methods
public class MethodsExample {
public static void main(String[] args) {
message1();
message2();
System.out.println("Done with main.");
}
public static void message1() {
System.out.println("This is message1.");
}
public static void message2() {
System.out.println("This is message2.");
message1();
System.out.println("Done with message2.");
}
}
 Output:
This is message1.
This is message2.
This is message1.
Done with message2.
Done with main.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
50
Control flow
 When a method is called, the program's execution...
 "jumps" into that method, executing its statements, then
 "jumps" back to the point where the method was called.

public class MethodsExample {


public static void main(String[] args) {
public static void message1() {
message1();
System.out.println("This is message1.");
}
message2();
public static void message2() {
System.out.println("This is message2.");
System.out.println("Done with main."); message1();
}
System.out.println("Done with message2.");
}
...
} public static void message1() {
System.out.println("This is message1.");
}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
51
When to use methods
 Place statements into a static method if:
 The statements are related structurally, and/or
 The statements are repeated.

 You should not create static methods for:


 An individual println statement.
 Only blank lines. (Put blank printlns in main.)
 Unrelated or weakly related statements.
(Consider splitting them into two smaller methods.)

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
52
Agenda

 Introduction to Java Programming


 Introduction to Netbeans
 Basic Java programs with println
statements
 Static methods
 Exercises

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh 53


Duy Tan University
53
Exercise 1 - create a new Java program
 Write a program Java named Exercise1 to produce the
following console output. Note the blank lines; you should
include those in your output.
Hello, world!
I am learning to program in Java.
I hope it is a lot of fun!

I hope I get a good grade!

Maybe I'll change my major to computer science.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
54
Exercise 2 - syntax errors

 The following program contains some errors!


What are they?
1 public class Tricky
2 public static main(String args) {
3 System.out.println(Hello world);
4 system.out.Pritnln("Do you like this program"?);
5 System.out.println()
6
7 System.println("I wrote it myself.";
8 {
9}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
55
Exercise 2 - corrected version

 Here is a corrected version of the program:


1 public class Tricky {
2 public static void main(String[] args) {
3 System.out.println(“Hello world”);
4 System.out.println("Do you like this program?");
5 System.out.println();
6
7 System.out.println("I wrote it myself." );
8 }
9 }

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
56
Exercise 3 - What's the output?

 How many lines of output are produced (including


blank lines)?
public class Tricky {
public static void main(String[] args) {
System.out.println("Testing, testing,");
System.out.println("one two three.");
System.out.println();

System.out.println("How much output");


System.out.println();
System.out.println("will there be?");
}
}
Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh
Duy Tan University
57
Exercise 4 - Exploring syntax errors
 How many unique error messages are you able to
cause the compiler to produce?
 Naming your file incorrectly, then compiling.
 Forgetting a keyword such as void or class
 Forgetting a quotation mark "
 Forgetting a parenthesis ( or )
 Forgetting a dot .
 Using too many or too few braces { or }
 Notice that the error messages don't always
make it obvious what is wrong. But they usually
tell you the right line number to correct.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
58
Exercise 5 - What's the output?

 How many lines of output are produced


(including blank lines)?
public class Tricky {
public static void main(String[] args) {
System.out.println("Testing, testing,");
System.out.println("one two three.");
System.out.println();
System.out.println("How much output");
System.out.println();
System.out.println("will there be?");
}
}

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
59
Exercise 6 - What's the output?
 What output is produced by the following
code?
System.out.println("Shaq is 7'1");
System.out.println("The string \"\" is an empty
message.");
System.out.println("\\'\"\\\\\"");

 Answer:
Shaq is 7'1
The string "" is an empty message.
\'"\\"

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
60
Exercise 7 -FightSong
 Write a following program to produce the output (using static method):

Go, team, go!


You can do it.

Go, team, go!


You can do it.
You're the best,
In the West.
Go, team, go!
You can do it.

Go, team, go!


You can do it.
You're the best,
In the West.
Go, team, go!
You can do it.

Go, team, go!


You can do it.

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
61
Exercise 8 - MuchBetter?
 Write a complete Java program named MuchBetter
that produces the following output (note the blank
line):
A "quoted" String is
'much' better if you learn the
rules of "escape sequences."

Also, "" represents an empty String.


Don't forget: use \" instead of " !
‘ ‘ is not the same as "

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
62
Exercise 9 - Spikey

 Write a complete program named Spikey


that produces the following output:
\/
\\//
\\\///
///\\\
//\\
/\

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
63
Exercise 10 - Lanterns
 Write a complete program named Lanterns that produces the following output. Use static
methods to capture structure and remove redundancy.

*****
*********
*************

*****
*********
*************
* | | | | |*
*************
*****
*********
*************

*****
*********
*************
*****
* | | | | |*
* | | | | |*
*****

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh


Duy Tan University
64
Agenda

 Introduction to Java Programming


 Introduction to Netbeans
 Basic Java programs with println
statements
 Static methods
 Exercises

Professor: Lynn Robert Carter Instructor: Dao, Nguyen Thi Anh 65


Duy Tan University
65

You might also like