CSC305: COMPUTER PROGRAMMING II (JAVA)

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Computer Programming Lab(7).
Computer Programming Lab 8.
Logic & program control part 3: Compound selection structures.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
CS 106 Introduction to Computer Science I 01 / 29 / 2008 Instructor: Michael Eckmann.
Introduction to Java Programming, 4E
IC211 Lecture 8 I/O: Command Line And JOptionPane.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
The switch statement: an N-way selection statement.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Computer Programming Lab(5).
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Mixing integer and floating point numbers in an arithmetic operation.
1/23: Java Modular Components Identifiers: naming requirements for Java variables & objects Stepping out of the MS-DOS window: The Java Modular Component:
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
Computer Programming1 Computer Science 1 Computer Programming.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
JOptionPane. Import javax.swing.JOptionPane Use showInputDialog() for input. Only string values can be input. To convert an input value from a string.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
John Hurley Spring 2011 Cal State LA CS 201 Lecture 6:
Introduction to programming in java
COURSE OUTLINE INTRODUCTION DATA TYPES AND LIBRARIES
CSC111 Quick Revision.
Introduction to programming in java
Input/Output.
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
2.5 Another Java Application: Adding Integers
Something about Java Introduction to Problem Solving and Programming 1.
BIT115: Introduction to Programming
Control Statement Examples
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
Computers & Programming Languages
CS18000: Problem Solving and Object-Oriented Programming
Chapter 2 - Introduction to Java Applications
Introduction to Java Programming
Introduction to Java Brief history of Java Sample Java Program
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
F II 2. Simple Java Programs Objectives
Presentation transcript:

CSC305: COMPUTER PROGRAMMING II (JAVA) AJAYI, O. O. ajjavax@gmail.com

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

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

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

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

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 }

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 }

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); }

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……)

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); }

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); }

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); }

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’.