Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC305: COMPUTER PROGRAMMING II (JAVA)

Similar presentations


Presentation on theme: "CSC305: COMPUTER PROGRAMMING II (JAVA)"— Presentation transcript:

1 CSC305: COMPUTER PROGRAMMING II (JAVA)
AJAYI, O. O.

2 INTRODUCTION Intro to JAVA as an Object-Oriented Programming Language.
Intro the Structure of Java Intro to Data Types in Java Intro to Java I/O Statements

3 INPUT Statement The NEEDFUL… …using SCANNER IMPORT TEMPORAL Scanner
ASSIGNMENT

4 ILLUSTRATION Write a Java program that accepts values for two integer variables and compute their summation.

5 STEPS & SOLUTION STEPS… Click FILE  NEW PROJECT
Under CATEGORY, select JAVA Under PROJECT, select JAVA APPLICATION Click NEXT Under PROJECT NAME, specify your desired name If needful, specify the directory for storing/saving your file OR use the default Click FINISHED

6 The look… Depending on your IDE type, you should be having something like this now… package mywork1; public class Mywork1 { public static void main(String[] args) { ……TODO – your coding goes here }

7 NEXT… Note however, your IMPORT Statement
package mywork1; import java.util.Scanner; public class Mywork1 { public static void main(String[] args) { ……TODO – your coding goes here }

8 Gradual Coding now- Illustration
I/O Statements in Java import java.util.Scanner; //under package… Public class………..{ Public static void main (String args[]){ int a,b,sum; Scanner getin = new Scanner (System.in); System.out.print(“Input me: ”); a = getin.nextInt(); System.out.print(“Input the other: ”); b = getin.nextInt(); sum = a+b; System.out.printf(“The summation of a and b is %d”, sum); }

9 I/O Statement cont’d I/O Statements in Java GUI Method Steps:
Import the JOptionPane using javax.swing.JOptionPane; Access the GUI either for: Inputting (showInputDialog…….), OR Outputting (showMessageDialog……)

10 Illustration I: A Java Program to capture and welcome user’s ID
public class ……….. { public static void main(String[] args) { String username; username = JOptionPane.showInputDialog("Enter Username: "); JOptionPane.showMessageDialog(null, "Welcome " +username, "AJ App", JOptionPane.ERROR_MESSAGE); }

11 Illustration II: A Java Program to capture values for two integers (using GUI) and then compute their summation; OUTPUTTING it (i) on console (ii) via GUI import java.util.Scanner; import javax.swing.JOptionPane; public class Mywork1 { public static void main(String[] args) { int a, b,sum; String a2, b2; a2 = JOptionPane.showInputDialog("Enter 1st No:"); b2 = JOptionPane.showInputDialog("Enter 2nd No:"); a = Integer.parseInt(a2); b = Integer.parseInt(b2); sum = a+b; System.out.printf("The sum is: %d", sum); }

12 Illustration II: OPTION II
import java.util.Scanner; import javax.swing.JOptionPane; public class Mywork1 { public static void main(String[] args) { int a, b,sum; String a2, b2; a2 = JOptionPane.showInputDialog("Enter 1st No:"); b2 = JOptionPane.showInputDialog("Enter 2nd No:"); a = Integer.parseInt(a2); b = Integer.parseInt(b2); sum = a+b; JOptionPane.showMessageDialog(null,"The sum total is" +sum, "AJ APP", JOptionPane.INFORMATION_MESSAGE); }

13 Weekend Practical Activities
Write a simple Java program that demonstrate the differences between PRINT, PRINTLN and PRINF Statements. Aside +, -, *, / which are common arithmetic operators in Java and other programming languages, Java also has % for modulus computation. With this and with your knowledge of iterative statement like do-while, while & for statement, write a Java program that converts 5710 to base 2. We would soon get to the chapter that deals with Control Statement. But I can tell you it’s the same as in C++. Review the use of Switch Statement in C++ and deploy the knowledge to write a PHONE BATTERY STATUS program such that when the battery power % is >=70 u report ‘battery can carry thru to the desert’, <70 but >29, ‘be moving close to power source’, <30 but >19, ‘am weak & thirsty for refilling’, <20 but >4, ‘I will soon disappoint u’, else ‘u succeeded in killing me, wicked owner’.


Download ppt "CSC305: COMPUTER PROGRAMMING II (JAVA)"

Similar presentations


Ads by Google