3
1 TK2934 Object Oriented Programming Tutorial 1: Basic Java Features NAME: MATRIX NUMBER: DEPARTMENT: Section A: constructing a Java program 1. Answer ALL questions in Write, Compile and Execute sections a. Write Explain the structure of the following source code public class Test1 { public static void main (String[] args) { System.out.println ("Welcome to my first tutorial !") ; } } b. Compile C:\work>javac Test1.java The output of the compilation is (a)__________________________. It is in (b)______________form.

Tutorial 1

Embed Size (px)

DESCRIPTION

TK2934 OOP

Citation preview

Page 1: Tutorial 1

1

TK2934 Object Oriented Programming

Tutorial 1: Basic Java Features

NAME:

MATRIX NUMBER:

DEPARTMENT:

Section A: constructing a Java program

1. Answer ALL questions in Write, Compile and Execute sections

a. Write

Explain the structure of the following source code

public class Test1 {

public static void main (String[] args) {

System.out.println ("Welcome to my first tutorial !") ;

}

}

b. Compile

C:\work>javac Test1.java

The output of the compilation is (a)__________________________.

It is in (b)______________form.

Page 2: Tutorial 1

2

c. Execute C:\work>java Test1

(c)_______________ interpret the bytecode file. After running the program,

the output of the program is shown below:

Section B: Basic Java Features

1. Input, String and Output

Complete the source code with explanations.

import java.util.Scanner

public class Test2 {

public static void main (String[] args) {

String (a)________;

Scanner (b)_________ = new Scanner(System.in);

myname=mynameobj.next (c)____();

System.out.println ("Welcome to my first tutorial" (d)____________); }}

After running the program, the output is shown below:

use class Scanner from java.util package

declare a string variable named ‘myname’

create a Scanner object named

‘mynameobj’

Page 3: Tutorial 1

3

2. Operations on String

Expand and modify code in Test 2 to create Test 3 in order to produce the nickname

for naja which is naj:

3. Selection structure if-else

Expand and modify code in Test 2 to create Test 4 in order to produce an output that

shows: If the length of the name > 10, your name is long

Else your name is short

4. Using charAt

Expand and modify code in Test 2 to create Test 5 in order to produce an output that

shows your name in backward.

5. Menu based program: Create a menu based program named Tutorial1 and produce

an output like below.

Items in the menu are based on code in Test2 (option 1), Test 3 (option 2), Test 4

(option 3) and Test 5 (option 4).

SELAMAT MAJU JAYA!

import java.util.Scanner;

public class Test3 {

public static void main (String[] args) {

String myname;

Scanner mynameobj = new Scanner(System.in);

myname=mynameobj.nextLine();

(e)_______________________________

System.out.println ("Welcome to my first tutorial " +(f)_________ + " !");

}}