Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Computer Programming Lab(7).
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Computer Programming Lab 8.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
8-May-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 6 Control Structures.
Some basic I/O.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS107 Introduction to Computer Science Java Basics.
The switch statement: an N-way selection statement.
Computer Programming Lab(5).
Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
More on Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Conditional If Week 3. Lecture outcomes Boolean operators – == (equal ) – OR (||) – AND (&&) If statements User input vs command line arguments.
CS107 Introduction to Computer Science Java Basics.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
BİL528 – Bilgisayar Programlama II Making Decisions, Loops, Debugging, Designing Objects Using Classes 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-
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Clement Allen, PhD Florida A&M University SUMMER 2006.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
By Mr. Muhammad Pervez Akhtar
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
introductory lecture on java 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.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Object Oriented Programming (OOP) LAB # 3 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Common Mistakes with Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Introduction to Object Oriented
Introduction to Java Import Scanner class to use in our program
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Java Language Basics.
Chapter 7 User-Defined Methods.
Intro to ETEC Java.
Chapter No. : 1 Introduction to Java.
CSC305: COMPUTER PROGRAMMING II (JAVA)
Maha AlSaif Maryam AlQattan
SELECTION STATEMENTS (1)
Control Statement Examples
Common Mistakes with Functions
Starting JavaProgramming
Year 2 Autumn Term Week 12 Lesson 1
Object Oriented Programming (OOP) LAB # 5
SELECTION STATEMENTS (2)
Units with – James tedder
Year 2 Autumn Term Week 12 Lesson 1
Java Programming with BlueJ Objectives
Additional control structures
CMPE212 – Reminders Assignment 2 due today, 7pm.
Presentation transcript:

Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal

What is JAVA?  The Java programming language has a long history. It started in 1991 when Sun Microsystems began Their Green Project. The goal of The Green Project was to create a new portable programming language, that could be used to create applications to run on multiple operating systems without having to recompile or port the code. The original name of the language was Oak, for a large oak tree that stood outside the windows of the developers' offices.  But between the time the project began and the time the language was released, it was renamed as Java supposedly because of the amount of coffee that the developers were drinking. Java was first released to the public in 1995 and thereafter saw a rapid evolution and change. Now java is every where.

Java is used  To built Web applications.  Mobile applications except (IOS) like iphone and ipad.  Many other applications..

Java….  Is not the simplest language nor the difficult one.  Is “C-Style” language. That means if you know any language like C, C++,C#, PHP, You are going to understand the language.  It is object oriented language. That means you have to deal with every thing as object.

What is JVM?  The Java Virtual Machine (JVM) is an abstraction layer between a Java application and the underlying platform. As the name implies, the JVM acts as a “virtual” machine or processor. To the bytecodes comprising the program, they are communicating with a physical machine; however, they are actually interacting with the JVM.

What is JVM? (Java Virtual Machine)

The main syntax of the language  Import ……………………… ( import the library you need in the program, sometimes you don’t need to import any libraray).  public class {  public static void main (String [] args){  ;  …………………  } (close the main function)  } (close the class)

Output statement  System.out.println(“ ”);  System is a final class from java.lang package which is defined already in the java. That means you don’t need to import any package to run this statement.

Example #1 Hello world program  public class Welcome {  public static void main(String[] args) {  System. out.println("hello world!! "); }} }}

How can we write a program in Eclipse? 1)File → new → Java Project

How can we write a program in Eclipse? 2) Write the Project name, and Change the execution environment JRE to (use default JRE) Then press Finish

How can we write a program in Eclipse? * We can see our project in Package Explorer * The execution of the project is shown here. * If there is any errors in the program, we can find the errors detail in problems tap.

How can we write a program in Eclipse? 3) Write click on the src folder, choose new then class

How can we write a program in Eclipse? 4) Write a name of class, put a check on public static void main (String args[]) Then press Finish

How can we write a program in Eclipse? Now, we can write our program inside the main method.

How can we write a program in Eclipse?

 After that we need to run the program…  From Run menu, Choose Run and check the program you want to run. Then click OK.  You will be able to see the results in console view. How can we write a program in Eclipse?

Defining Variables  ; Or  = ;  For example  int x;  int x=5;  Variables can be String, int, double, char and so on.

Example #2  Write a program that add two numbers 5 and 3. Then display the result  Solution:

Input statement  To allow the user to insert anything, you have to define Scanner object and to do that  First, you need to import a package called java.util.Scanner  Import java.util.Scanner;  Second, create a scanner which obtain input from the user  Scanner input =new Scanner (System.in);  Finally, You can use your new object (input) to insert any type of data.  For example, To insert integer number  int x=input.nextint();  And to insert a string  String x=input.nextLine();

Example # 3  Write a program that asks user to insert two integers, add them and display the result.  Solution :

Condition- If statement  if ( )  Statement ;  else  Statement ;  Or  if ( )  {Statements; }  else if ( ) {  Statements; }  else  {statements;}

Switch statement  switch (variable){  case :  Statements;  break;  case :  Statements;  break;  default:  Statements;  Break; }}

Assignment 1: Conditional Statements and Switch Case  For each of the following exercise, perform each of the following steps: a) Read the problem statement. b) Formulate the algorithm using pseudo-code c) Write a Java program. d) Test, debug and execute the Java program. e) Process three complete sets of data.

Write a Java program that asks the user to input a number between 1 and 20 and prints a sentence which indicates if the number is either within the range, too high or too low. Exercise 1:

Pseudo Code: -Prompt the user to enter a number between 1 and 20 -Input the number -If the number is between 1 and 20 - Print “The number is within the range” - Else - If the number is larger than 20 - Print “The number is too high” - Else - Print “The number is too low”

Exercise 1: Solution Exercise 1: Solution

Exercise 1: Testing Exercise 1: Testing

Write a Java program that asks the user to input two numbers x and y and prints the absolute value of x-y. Exercise 2:

Exercise 2: Solution Exercise 2: Solution

Exercise 2: Testing Exercise 2: Testing

Exercise 3: Write a Java program that asks the user to enter the current month and outputs whether the month is in Winter, Spring, Summer or Autumn. Winter starts 21/12,Spring starts 21/3, Summer starts 21/6, Autumn starts 21/9.

Exercise #3 (analysis)  winter starts (21/12) and ends (20/3)  Spring starts (21/3) and ends (20/6)  Summer starts (21/6) and ends (20/9)  Autumn starts (21/9) and ends (20/12)  If the month is 1 or 2 (it must be winter regardless day)….  If the month is 4 or 5 (it must be spring)….  If the month is 7 or 8 (it must summer )….  If the month is 10 or 11 (it must Autumn )….

Exercise 3: Solution Exercise 3: Solution

Exercise 3: Testing Exercise 3: Testing

Exercise 5: Create a program which asks the user for 3 numbers representing the year, month and day e.g and then outputs in the form 8th October 2014.

Exercise # 5 Hint #1 -Order of days 1st11th22nd 2nd12th23rd 3rd13th24th 4th14th25th 5th15th26th 6th16th27th 7th17th28th 8th18th29th 9th19th30th 10th20th31st 21st

Exercise #5 Hint #2 - Order of months 1.January 2.February, 3. March, 4.April, 5.May, 6.June, 7.July, 8.August, 9.September, 10.October, 11.November 12.December

Exercise 5: Solution Exercise 5: Solution

Exercise 5: Testing Exercise 5: Testing

Exercise 6: Write a Java program that, given as input three integers representing a date as day, month, year, prints out the number day, month and year for the following day's date. Suppose that the month has always 30 days.

Exercise 6: Solution Exercise 6: Solution

Exercise 6: Testing Exercise 6: Testing

Exercise 7: Write a Java program that given as input three integers representing a time as second, minute, and hour, prints out the number second, minute and hour for the following second's time.

Exercise 7: Solution Exercise 7: Solution

Exercise 7: Testing Exercise 7: Testing

Exercise 8: Write a Java program that, given as input three integers representing a date as day, month, year, one integer representing number of days, print out the new date which is the entered date added to the number of days. Suppose that the month has always 30 days.

Exercise 8: Solution Exercise 8: Solution

Exercise 8: Testing Exercise 8: Testing