0% found this document useful (0 votes)
29 views

OOP Week 1

Handouts for computer programming

Uploaded by

Christina Ramos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

OOP Week 1

Handouts for computer programming

Uploaded by

Christina Ramos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Java

Programming
Object-Oriented Programming
chapters
01 Introduction 04 Programming
Language

02 History of Computers 05 Processing a Java


Program

03 Elements of a
Computer System 06 Algorithm
Introduction
course policies
Expectations from this class:
• Attendance is a MUST
(student will be dropped from the class if their absences goes over 20% of total class hours)

• Students will be marked late if they come in to class 15 minutes or later


• Three instances of tardiness will be an equivalent of 1 absence
• Submissions of outputs should only be made on or before the deadline
• Academic dishonesty (like cheating and the likes) will be penalized as
stipulated in the SIBTECH Student Handbook
laboratory rules
These are the rules to follow while inside the laboratory:
• Observe silence
• Foods and drinks are not allowed inside the laboratory
• Recreational activities during classes are not allowed, units must only
be used for the intended uses of the class.
• Always raise your hands if you want to answer and/or ask a question
• Handle laboratory equipment with care
• Uses of any gadgets will be prohibited unless required by the instructor
• Be sure to save your files from time to time as we are prone to
spontaneous power interruptions
• Never forget to clean your station before and after using
• Turn off the units properly when leaving
Brief History of
Computers
1792 – 1750 BC
First recorded usage of
Abacus as a means of
calculating through Abacus
early-mid 1800s
Charles Babbage invented
two calculating machines.
Difference engine and
Analytical engine.
Note: In 1940s, Jon Von
Neumann designed the rules
that Computers use today

1956
Invention of the transistors
that resulted in smaller,
faster more reliable, and
more energy efficient
Elements of a
Computer System
Hardware
physical components of
a computer system, they
are the tangible parts
such as the
motherboard, processor,
memory, etc…
central processing unit and
main memory

• the brain of the computer and the


single-most expensive piece of
hardware in a computer.

• arithmetic and logical operations


are carried out inside the CPU
secondary storage

• a device that stores longer-term


information (unless the device
becomes unusable or you change
the information by rewriting it)
input/output devices

• input devices feed data and


programs into computers, such as
keyboard, mouse, etc..
• output devices are devices the
computers uses to display and store
results, such as printer, monitor,
etc…
Software
set of instructions, data,
or programs used to
operate a computer and
execute specific tasks,
like MS Office, Adobe
Suite, etc…
operating system/system programs

• a computer program that works as


an interface between users and
hardware
• computers are useless without an
operating system
application programs

• a program or set of programs that


performs specific tasks
• end-users use this software
Language of a
Computer
Electrical
Signals
remember that
computers are electrical
devices, hence they can
communicate through
electrical signals
analog signals

• continuous waveforms used to


represent things, such as sound,
audio tapes, etc…
digital signals

• represents information with a


sequence of 0s and 1s
• 1 represents a high voltage, 0
represents a low voltage
Processing a Java
Program
key terms:
assembler – translates a program written in assembly language into an
equivalent program in machine language
bytecode - form of instruction set designed for efficient execution by a
software interpreter
compiler – a program that checks the source program for syntax errors
and if no errors, translates the program into bytecode
interpreter – a program that reads and translates each bytecode
instruction into your computer’s machine language, then executes it
loader – finds the binary representation of the bytecode
source program – code/program encoded through a text editor or an
IDE. (program written in a high-level language)
sample java program
`
public class MyFirstJavaProgram
{
public static void main(String[] args)
{
System.out.println(“My first Java
program.”);
}
}

Output:
processing a java program

Recall that a computer can only


understand machine language.
Therefore, in order to run a program
successfully, the code must first be
translated into the machine
language.
processing a java program
Program

Editor

Compiler Error

No Error

Library Bytecode

Loader

Interpreter
Algorithm
programming with the problem-analysis-
coding-execution cycle

programming is a process of problem


solving, so to be a skillful programmer,
one must use good problem-solving
techniques.

One common problem-solving technique


is an algorithm
STEPS
IN THE
PROBL
EM-SO
LVING
PROCE
Step 1 Step 2 Step 3 Step 4 Step 5
SS
• Analyze the • Design an • Implement the • Verify that the • Maintain the
problem and algorithm that algorithm in a algorithm program by
outline the solves the programming works with using and
problem and problem language correct logic improving it,
its solution and syntax and modifying
requirements it if the
problem
domain
changes
Problem

Analysis

Algorithm Design

Coding

Compiler Error

Library Bytecode

Loader

Interpreter Error

Results
Let’s practice!
Design an Algorithm to play a number guessing game:

The objective is to randomly generate an integer greater than or equal to 0 and less
than 100. Then, prompt the player (user) to guess the number. If the player guesses
the number correctly, output an appropriate message. Otherwise, check whether the
guessed number is less than the random number. If the guessed number is less than
the random number, output the message “Your guess is lower than the number. Guess
Again!”; otherwise output the message “Your guess is higher than the number. Guess
Again!”. The player is prompted to guess the random number until the player enters
the correct number.
Let’s Practice!
Things we need:
random number
guess number

suppose;
random number = num
guess number = guess
Let’s Practice!
pseudocode:

if (guess is equal to num)


Print “You guessed the correct number.”
otherwise
if (guess is less than num)
Print “Your guess is lower than the number. Guess Again!”
otherwise
Print “Your guess is higher than the number. Guess Again!”
Try This!
Design an Algorithm that calculates the monthly paycheck of a salesperson at a local
department store:

Every salesperson has a base salary. The salesperson also receives a bonus at the end
of each month, based on the following criteria: If the salesperson has been with the
store for five years or less, the bonus is $10 for each year that he or she has worked
there. If the sales person has been with the store for more than five years, the bonus is
$20 for each year that he or she has worked there. The salesperson can earn an
additional bonus as follows: If the total sales made by the salesperson for the month
are greater than $5000 but less than $10000, he or she receives a 3% commission on
the sale. If the total soles made by the sales person for the month are at least $10000,
he or she receives a 6% commission on the sale.
Try This!
To calculate the salesperson’s paycheck, you need to know:
the base salary
the number of service years
total sales made for the month

suppose;
base salary = baseSalary
the number of service years = noOfServiceYears
total sales for the month = totalSales
bonus = bonus
additional bonus = addBonus
THANK
S! Does anyone have any
questions?
[email protected]
+63 968 275 6798

CREDITS: This presentation template was created by Slidesgo, including


icons by Flaticon, infographics & images by Freepik
Please keep this slide for attribution

You might also like