session 2 of programming
TRANSCRIPT
Pimp UR Knowledge II
Intro. To programming using Java
SESSION NO.2
What Are We Going To Do
• 2.1. Session’s Quiz
• 2.2. Quick Revision
• 2.3. Java tools(If statements and loops)
• 2.4. General Examples
• 2.5. Session’s Quiz
• 2.6. Session’s Report
• 2.7. Questions time
QUIZ
• Write a Java program that reads 2 numbers and prints out their sum.
Java Tools
If Statements:
• It’s normally as the if statements we use in verbal language:
• If … Condition … Answer of Condition >and> If not … Another Answer
Form:
if(Condition){
Answer Code}
else {
the other Answer Code}
Java Tools
Loops:
• Loops are used to repeat a piece of your code several times which could be
user defined or conditioned.
Form:For( int i = start ; i < finish ; i(+or-)=step)
{Code}
FINALLY!
Good programming style :
• Use good names for variables and methods
• Add whitespaces
• Don't duplicate tests
GENERAL EXAMPLES
Lets Play Java
EXAMPLE 1
Make a Java Program to simulate a waiter’s job in a restaurant where the
customer is asked for his desired food and dessert after the waiter tells the
menu. After the customer finishes his order he is told the cost.
Pizza Burger Grilled Fish Chocolate
Cake
Juice Coke
40 17 60 15 10 5
EXAMPLE 2
Write a salary program for a company to calculate the salary of the employee
according to the following table
Worker Type Base Salary
For 40
hours/hour
Over time
>40
Over Time
>60
Taxes
Worker 50 *1.5 *2 3%
Engineer 65 *2 *3 5%
Manager 80 *2 *3 7%
CEO 150 _______ ______ 10%
EXAMPLE 3
Design a Java Program to draw a Diamond shape using any symbol
EXAMPLE 4
• Write a Java Program to print out a sequence which it’s Start, Step,
Kind(Arithmetic or Geometric), End. Are Given to you as an input from the
user.
QUIZ
Design a Java Program to find numbers that it’s remainder after division on 3,
4, 5, 6, 7, 8 is 2. And Prints them out.
Design a Java Program that reads a number and prints out the Odd, Even,
Prime numbers till this number separated.
REPORT
Design a Java program that reads numbers as an input then puts them in an
array then:
• Sort Them in an ( ascending, descending ) an save both of them in a separate
array.
• Find The Maximum and Minimum Value and it’s Location in the array.
• Give an option to search for a value if available in the array or not if
available show the user the location