Programming Fundamentals I Java Programming ICE0124ITB0121 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Programming Fundamentals I Java Programming ICE0124ITB0121

Description:

Eru Hojin Kim (eruhkim.AT.icu.ac.kr) July 4th, 2005. Lab No. 2 ... Hwang, Kim. 4. Explanation on class and object. Java: ... Hwang, Kim. 7. Practice together ... – PowerPoint PPT presentation

Number of Views:114
Avg rating:3.0/5.0
Slides: 20
Provided by: jba2
Category:

less

Transcript and Presenter's Notes

Title: Programming Fundamentals I Java Programming ICE0124ITB0121


1
Programming Fundamentals I Java
Programming(ICE0124/ITB0121)
July 4th, 2005 Lab No. 2
  • Tae-ho Hwang (fanteo.AT.icu.ac.kr)
  • Eru Hojin Kim (eruhkim.AT.icu.ac.kr)

2
2 Concept of class and object, and Control
statement
3
Agenda for Today
  • Explanation on class and object
  • Control statements
  • if
  • for, while, do while
  • switch
  • Practice together!
  • Assign Homework 2

4
Explanation on class and object
  • Java an object-oriented programming language
  • Performing a task in a program requires a method.
  • The program unit that houses a method is called a
    class.
  • A class can be used to create an instance of the
    class called an object.
  • A class has specified attributes that the object
    will have.
  • Class instance creation expressions beginning
    with keyword new create new objects.

5
Explanation on class and object
  • public an access modifier
  • public available to the public so it can be
    called by other classes declared outside the
    class declaration
  • protected intermediate level of access to the
    method or variable (we will see later)
  • private minimum level of access to the method or
    variable (we will see later)
  • Method
  • Arguments
  • Parameters

6
Control statements
  • Condition
  • if
  • if (age
  • else if ((age 18) (age
  • else
  • switch
  • switch (age)
  • case 1
  • break
  • Iteration
  • for
  • for (i 0 i
  • while
  • while (age
  • do while
  • do
  • while (age

7
Practice together
  • Get two integers, one is base number of
    multiplication, the other is the number of column
  • Print out the result of multiplication

8
Practice together (Contd)
9
Practice together
  • // Lab 2_1 2005-07-04
  • // 20050001 Gildong Hong
  • import java.util.Scanner
  • public class Lab2_1
  • public static void main(String args)
  • Scanner input new Scanner(System.in)
  • int number1
  • int number2
  • System.out.print("Enter first integer ")
  • number1 input.nextInt()
  • System.out.print("Enter second integer ")
  • number2 input.nextInt()

Lab2_1.java
10
Practice together (Contd)
  • int i 1
  • while (i
  • System.out.printf("dd2d\t", number1, i,
    number1 i)
  • if (i number2 0)
  • System.out.println()
  • i

Lab2_1.java
11
Practice together
  • Get the integer number as number1
  • Generate random number as number2
  • If the random number number2 is different from
    number1, print out the number2 and repeat above
    action
  • Otherwise exit the program with printing out END
    with ? message

12
Class Random
  • Generate random numbers Random rnd new
    Random() number rnd.nextInt(100)
  • Above code generates the random integer number
    from 0 to 100 which includes 0 and excludes 100
  • import java.util.Random

13
Practice together (Contd)
14
Practice together
  • // Lab 2_2 2005-07-04
  • // 20050001 Gildong Hong
  • import java.util.Scanner
  • import java.util.Random
  • public class Lab2_2
  • public static void main(String args)
  • Scanner input new Scanner(System.in)
  • int number1
  • int number2
  • Random rnd new Random()
  • System.out.print("Enter the integer ")
  • number1 input.nextInt()

Lab2_2.java
15
Practice together (Contd)
  • while (number1 ! (number2 rnd.nextInt(100)))
  • System.out.println(number2)
  • System.out.printf("END with d", number2)

Lab2_2.java
16
Assign Homework 2
  • Create a Java program, Homework2.java that does
    the following things
  • Input 2 integer values, one determines the shape
    of triangle, the other does the number of in a
    row or column
  • Draw triangle using while statement

17
Assign Homework 2 (Contd)
18
Assign Homework 2 (Contd)
19
Assign Homework 2 (Contd)
  • Submission
  • Compress the files to zip file (not alz) named
    like ICE0124_20050001_HW2.zip
  • Mail subject should be likeICE0124 Homework 2
    by 20050001 ???
  • Send to eruhkim.AT.icu.ac.kr
  • Due date 2005-07-11 180000
  • 50 penalty if the homework is late or you dont
    keep the above rules
Write a Comment
User Comments (0)
About PowerShow.com