Comprog Fundamentals Oblcbl Module 2nd 2021 2022
Comprog Fundamentals Oblcbl Module 2nd 2021 2022
Definition
A Computer is an electronic device that can perform activities that involve
mathematical, logical and graphical manipulations. Generally, the term is used to
describe a collection of devices that function together as a system. You can think of it
as an electronic machine operating under the control of instructions stored in its own
memory.
To make things easier to remember, these operations are also referred to as the
Input-Process-Output(IPO) Model.
● Operating System (OS): The software that manages the resources of a computer
system and schedules its operation is called Operating system. The operating
system acts as an interface between the hardware and the user programs and
facilitates the execution of programs.
Generally the OS acts as an interface between the user and the Hardware of the
computer. i.e. It is a bridge between the user and the Hardware.
The User interface provided by the OS can be character based or graphical:
o Character User Interface: It is operated with keyboard only. Ex: MS-DOS, UNIX
o Graphical User Interface: The system can be operated with mouse and
keyboard. Ex: Windows XP, Windows 7, etc.
● Translators: Computers can understand instructions only when they are written in
their own language – the machine language. Therefore, a program written in
any other language should be translated into machine language. The software
that translates the instructions of different languages is known as translators. We’ll
discuss more about translators on the next topics.
● Utility Programs: These are pre-written programs supplied by the manufacturer for
maintaining day to day activities of a computer system. Example: COPY, SORT,
MAILING, virus scanning software etc.
● Application Programs: These are user written programs to do a specific job which
can be changed to meet the individual needs. These programs are written in
different languages such as BASIC or C or by using database packages like
dBASE, Oracle.
● General Purpose Packages: These packages are developed to suit the needs of
research workers/scientists in different fields. These packages are categorized as:
o Data Analysis – ex: SPSS (Statistical Package for Social Science), MSTAT,
MICROSTAT, GENSTAT, SAS etc.
o Word Processing – ex: MS-Word, Google Docs, NORTON EDITOR, etc.
o Spreadsheet – ex: LOTUS, Google Spreadsheets, MS-Excel, etc.
o Graphics – ex: Adobe Illustrator, Adobe Photoshop, etc.
o Databases – ex: Oracle, MS Access, etc.
From what’s mentioned before, we can say that the OS is one of the most
important software in a personal computer. Without it, you won’t be able to use other
software. Today, most operating systems perform the following important functions:
Most personal computers use Windows as its operating system. Most likely, if
you’re using a laptop as your primary device for this course, it’s operating system (also
referred to as OS), is Windows. This module will help work around Windows-based
computers with more confidence.
The Desktop
The Desktop is the main Windows screen. It is the work area where dialog boxes,
windows, icons, and menus appear. Like an office desk, the desktop contains items you
can use to do your job. For instance, from your desktop, you can perform
file-management tasks and run software applications. You can customize the
appearance of the desktop to suit your preferences. The following are something that
you might see in an average Windows Desktop:
1. My Computer – Allows you to see what drives are attached to your computer
(for example, your local hard disk drive, your CD/DVD drives, any networked
shared drives, and external drives, such as a USB flash drive). You can also view
the files that are located on these drives.
2. My Documents – Supplies a ‘catch-all’ place for your personal files. Within here
you can see your files, any shared files from other computer users and any music
or pictures you may have stored. The Documents folder will sometimes be
identified by your name instead of the word “Documents.”
3. Recycle Bin – Stores any files you delete until you empty it.
4. Internet Explorer – Contains Windows’ built in web browser that integrates with
other Windows components
Components of a Desktop
1. Desktop that contains many components like icons (file, folder, shortcut. Etc.)
2. Task Bar
On your desktop, you’ll find what’s called an icon. An icon is a graphic image, a
small picture or object that represents a file, program, web page, or command. Icons
help you execute commands, open programs or documents quickly. To execute a
command by using an icon, click or double-click on the icon. It is also useful to quickly
recognize an object in a browser list. For example, all documents using the same
extension have the same icon. We can classify icons as the following:
● Folder Icons –
● File Icons –
● Shortcut Icons –
All the data on your hard drive consists of files and folders. The basic difference
between the two is that files store data, while folders store files and other folders. The
folders, often referred to as directories, are used to organize files on your computer. The
folders themselves take up virtually no space on the hard drive. Files, on the other hand,
is a collection of data – stored in one unit, identified by a filename followed by a period
and a file extension (Figure 1.6). A file can range from a few bytes to several gigabytes.
It can be documents, programs, libraries, and other compilations of data.
Figure 1.2: Filename and extension
Icon Operations
You can do various operations on the icons on
your desktop. Here are some of them:
● View/Hide Icons
o Right Click the desktop
o Click View
o Check to see if Auto Arrange has a check
mark
o If it does uncheck it
● Start programs
● Open commonly used folders
● Search for files, folders, and
programs
● Adjust computer settings
● Get help with the Windows
operating system
● Turn off the computer
● Log off from Windows or switch to
a different user account
● Switch user: If you have more than one user account on your computer, Fast User
Switching is an easy way for another person to log on to the computer without
logging you off or closing your programs and files.
● Log off: When you log off from Windows, all of the programs you were using are
closed, but the computer is not turned off.
● Lock: Locking your PC is a good option if you’ll be back soon. You'll have to
enter your password when you come back, which helps keep your work more
secure.
● Restart: The Restart button "reboots" your computer (it is sometimes called a
"warm boot" or "soft boot.") That means it saves your information to the hard
drive, turns off the computer for a moment, and then turns it back on again.
● Sleep: Clicking on Sleep puts your computer in a low-power state, but doesn't
turn it off. The main advantage is that it allows you to get back to work quickly,
without having to wait for the computer to do a full reboot.
Windows
Whenever you open a program, file, or folder, it appears on your screen in a box
or frame called a window (that's where the Windows operating system gets its name).
Although the contents of every window are different, all windows share some
things in common. For one thing, windows always appear on the desktop - the main
work area of your screen. In addition, most windows have the same basic parts.
● Title bar. Displays the name of the document and program (or the folder name if
you're working in a folder).
● Minimize, Maximize, and Close buttons. These buttons hide the window, enlarge
it to fill the whole screen, and close it, respectively (more details on these shortly).
● Menu bar. Contains items that you can click to make choices in a program.
● Scroll bar. Let’s you move the contents of the window to see information that is
currently out of view.
● Borders and corners. You can drag these with your mouse pointer to change the
size of the window.
Moving a window
To move a window, point to its title bar with the mouse pointer. Then drag the
window to the location that you want. (Dragging means pointing to an item, holding
down the mouse button, moving the item with the pointer, and then releasing the
mouse button.)
Hiding a window
Hiding a window is called minimizing it. If you want to get a window out of the
way temporarily without closing it, minimize it. To minimize a window, click its Minimize
button . The window disappears from the desktop and is visible only as a button on
the taskbar, the long horizontal bar at the bottom of your screen.
Closing a window
Closing a window removes it from the desktop and taskbar. If you're done with a
program or document and don't need to return to it right away, close it. To close a
window, click its Close button .
● Using the taskbar. The taskbar provides a way to organize all of your windows.
Each window has a corresponding button on the taskbar. To switch to another
window, just click its taskbar button. The window appears in front of all other
windows, becoming the active window—the one you're currently working in.
● Using Alt +Tab. You can switch to the previous window by pressing Alt+Tab, or
cycle through all open windows and the desktop by holding down Alt and
repeatedly pressing Tab. Release Alt to show the selected window.
Parts of a Folder/Library Window
When you open a folder or library, you see it in a window. The various parts of this
window are designed to help you navigate around Windows or work with files, folders,
and libraries more easily. A typical window is shown in Figure 1.8 and each of its parts:
● Navigation pane: Use the navigation pane to access libraries, folders, saved
searches, and even entire hard disks. Use the Favorites section to open your most
commonly used folders and searches; use the Libraries section to access your
libraries. You can also click the expand button to browse folders and subfolders.
● Back and Forward buttons: Use the Back button and the Forward button
to navigate to other folders or libraries you've already opened without closing
the current window. These buttons work together with the address bar; after you
use the address bar to change folders.
● Toolbar: Use the toolbar to perform common tasks, such as changing the
appearance of your files and folders, burning files to a CD, or starting a digital
picture slideshow. The toolbar's buttons change to show only the tasks that are
relevant.
● Address bar: Use the address bar to navigate to a different folder or library or to
go back to a previous one.
● Column headings: Use the column headings to change how the files in the file list
are organized. For example, you can click the left side of a column heading to
change the order the files and folders are displayed in, or you can click the right
side to filter the files in different ways. (Note that column headings are available
only in Details view).
● File list: This is where the contents of the current folder or library are displayed. If
you type in the search box to find a file, only the files that match your current
view (including files in subfolders) will appear.
● Search box: Type a word or phrase in the search box to look for an item in the
current folder or library. The search begins as soon as you begin typing—so if you
type "B," for example, all the files with names starting with the letter B will appear
in the file list.
● Details pane: Use the details pane to see the most common properties
associated with the selected file. File properties are information about a file, such
as the author, the date you last changed the file, and any descriptive tags you
might have added to the file.
Dialog Boxes
A dialog box is a special type of window that asks you a question, allows you to select
options to perform a task, or provides you with information. You'll often see dialog boxes
when a program or Windows needs a response from you before it can continue. Unlike
regular windows, most dialog boxes can't be maximized, minimized, or resized. They
can, however, be moved.
References:
1. Computer Concepts.2019. Tutorials Point. Retrieved from
https://www.tutorialspoint.com/computer_concepts/computer_concepts_tutorial.pdf
2. Discovering Computers: A Gateway to Information. 2011. Gary B. Shelly, Thomas J. Cashman,
Misty E. Vermaat.
3. Introduction to Computers. Retrieved from
https://www.just.edu.jo/~mqais/CIS99/PDF/Ch.01_Introduction_%20to_computers.pdf
Module 2: The Word Processing Program
LESSON OBJECTIVES
At the end of this unit, I can:
Title Bar
This is located at the very top of the screen. On the Title bar, MS Word displays
the name of the document you are currently using. If you have a document open right
now, at the top of your screen, you should see "Document1 - Microsoft Word" or a
similar name.
If you’re currently using Microsoft Office 2010 or higher, and are familiar with
Microsoft Office 2007, you will notice some changes. The File tab replaces the Microsoft
Office Button and the File menu used in earlier releases of Microsoft Office.
Ribbon
The Ribbon is located underneath the Quick Access Toolbar in the top portion of
the document. It has eight tabs: File, Home, Insert, Page Layout, References, Mailings,
Review, and View that contain many features of Word. Each tab leads to a new ribbon
which is divided into groups. The groups are logical collections of features designed to
perform functions that you will utilize in developing or editing your Word document.
Status Bar
This bar appears at the very bottom of the screen and provides such information
as the current page, current section, total number of pages, inches from the top of the
page, current line number, and current column number. There is also a Zoom Slider at
the right end of the Status bar which can be easily manipulated to change the size of
the document as you view it. It does not affect the actual size, only the way you look at
it on the screen.
ENGAGE
Have you written a long document before? Maybe a research project or an
academic paper? When a document is very long it is difficult to remember which page
or pages contain what information. Good thing because MS Word allows you to insert a
Table of Contents to easily organize and navigate your document.
Most people would do it manually but it would really take a lot of work. With the right
formatting, MS Word can create and update a Table of Contents automatically.
We will use MS Word 2016 to show you how to create a Table of Contents but you can
use the same method in earlier versions of MS Word.
To create a Table of Contents with three sections, use Heading 1 for the Chapter
heading (Introduction and Mechanisms of Greenhouse Effect). Then use Heading 2 for
the Section title (Functional Units of the house) and use Heading 3 for the specific topics
(Modeling and Materials).
Go to styles group and format the text you want, in this case the Chapter Title, Section
title and so on. Don’t worry if the formatting changes after you apply a heading style.
You just need to highlight the text and format it as you want it to (ex: Times New Roman,
12).
After using the heading styles and formatting the text, you can now insert the Table of
Contents (TOC). Make sure that you are on the page where you want to insert the TOC.
Select the References Tab, then click on the Table of Contents command. Choose a
built-in table then the Table of Contents will appear in your document.
Note: If you edit or added pages in your document, just click on Table of Contents and
select Update Table. Choose Update the entire table so MS Word will update the page
numbers and text.
For additional information about creating the Table of Contents: watch Module 2:
Creating a Table of Contents in Microsoft Word
Bibliography
If you need to write a research paper, then you would have to include a bibliography. It
is a list of sources such as books, articles or even websites that you used in your research
and write your paper. A bibliography makes it easy for someone else to see where you
found your information. It might look something like this;
We will use MS Word 2016 to show how to create a Bibliography. When creating a
bibliography, you must know what style to use. MS Word comes with built-in style guides
such as MLA, APA and others.
Click on the References tab, then select your preferred style in the Citations and
Bibliography group.
STEP 2: Citations and Sources
To add citations, click on the Insert Citation button and select Add new source
Then a dialog box will appear. Enter all the needed information such as author, title and
type of source (book, article or website) then click OK. The citation will appear in the
document, and the source will be saved. You can quickly add another citation for the
source by clicking Insert Citation and selecting the source from the drop-down menu.
STEP 3: Insert Bibliography
Now that you have added all your sources, just click Bibliography. The bibliography will
appear in the current page and you can transfer it where you want it to be, usually at
the end of the document. Your sources will already be formatted to match the
selected style guide. Again, you can change the font style and size (ex: Times New
Roman, 12).
For additional information about setting up and inserting a Bibliography: watch Module
2: Adding Citations & References Using MS Word
EXPLORE
Formatting your Technical Paper on MS Word
This section provides instructions for formatting any technical paper with MS
Word. We’ll assume that you are already familiar with the basic features of MS Word.
When you write a research paper, it is important to follow a particular formatting style
throughout your paper. A consistent style enhances readability and helps to give your
paper a professional appearance. For this section, our basis will be on the format set
out in the Publication Manual of the American Psychological Association (APA).
By following the previous steps, your document should look like the following:
● Title page
● Abstract (if required)
● Body
● References
● Appendixes
Essentially, a page break is a point at which a piece of continuous text is split into
two pages. With the Page Break feature of Word, you can easily divide your paper into
sections. To insert a page break:
1. Place the cursor after the last text character you typed in a section
2. Click on the Insert tab.
3. Click the Page break button in the Pages group.
Abstract
The abstract is a one-paragraph, self-contained summary of the most important
elements of the paper. The abstract begins on a new page and should not exceed 120
words. All numbers in the abstract (except those beginning a sentence) should be
typed as digits rather than words. To format an abstract:
Body
The body of the paper begins on a new page. Subsections of the body of the
paper do not begin on new pages. All paragraphs are to be indented ½ inch from the
left margin.
Headings
Headings are used to organize the document and reflect the relative
importance of sections.
● Main (first level) headings use centered uppercase and lowercase letters (e.g.,
Method, Results, References).
● Subheadings (second level headings) are italicized and use flush left, uppercase
and lowercase letters (e.g., Participants, Apparatus, and Procedure as
subsections of the Method section).
● If the names of the authors of a source are part of the formal structure of the
sentence, the year of publication appears in parentheses following the
identification of the authors. Example: Smith and Jones (2004) found Einstein’s
theory flawed.
● If the authors of a source are not part of the formal structure of the sentence,
both the authors and years of publication appear in parentheses, separated by
semicolons. Example: Subsequent research supports these results (Brown &
Greene, 2006; Hamilton, 2008).
● The same general rules regarding author(s) and date(s) apply to electronic
sources cited within your research paper. For a source without an identified
author, use the first few words of the title to document the source within the text,
followed by the date of publication, if given. Example: His status as a figure in
pop culture has grown in the last generation (“Einstein Online,” n.d.).
Please take note that the ampersand symbol (&) is used when multiple authors
are identified in parenthetical material, but “and” is used when multiple authors are
identified as part of the formal structure of the sentence. Also, if you refer to a work
more than once in a paper, give the author and date the first time you mention the
work, and then give only the author in subsequent mentions. We’ll show you how to
automatically generate these citations on the following section.
Quotations
When a direct quotation is used, always include the author, year, and page
number as part of the citation. Give the page number immediately after the quotation,
even in mid-sentence. The key is to remember that all 3 elements of the citation –
author, year, page number – must be given, whether in parentheses or as part of the
sentence. For example: In their 2007 article, Duncan and Sebastian claimed the results
of the university study were inconclusive due to the “unscientific method of data
collection” (p. 121).
If the quotation came from an electronic source such as an online article or web
page, give the paragraph number if no page number is available. You may use the
abbreviation para. or the paragraph symbol. You can find the paragraph symbol (¶) by
going to the Insert tab and clicking Symbol.
References
All sources included in the References section must be cited in the body of the
paper. The References section begins on a new page with the heading “References”
centered on the first line below the manuscript page header. The references (with
hanging indent – see below) begin on the line following the References heading. Entries
are organized by last names of first authors. Most Reference entries have three
components:
1. Author(s): Multiple authors are listed in the same order as specified in the source,
using last names and initials. Commas separate all authors. When there are
seven or more authors, list the first six and then use “et al.” to represent the
remaining authors. If no author is identified, the title of the document begins the
reference.
2. Year of Publication: Place the year in parentheses following the author(s), with a
period following the closing parenthesis. If no publication date is identified, use
“n.d.” in parentheses following the author(s).
3. Source Reference: For a journal article, this includes the article title, journal title,
volume (and sometimes issue) number, and page number(s); for a book, it
includes the title, city of publication, and publisher. In general, the source
reference for web documents includes author and date (if known) as well as
title, date of retrieval, and URL (web address). Italicize titles of journals, books,
and web pages, and periodical volume numbers.
If you’re writing a reference section for your paper, MS Word has a simple built-in
reference function at the References tab. Here you can manually enter references and
refer to them in the text and create a bibliography in the most common styles (APA,
Harvard, MLA, etc). The built-in function in Word is suitable if you have a limited number
of references and if you don't need to have access to your references from multiple
computers.
Please note that this option can be changed at any time and will automatically
update all citations and bibliography fields throughout the document to match the
selected style.
Create a source
Once the style has been established, you must add source information to be
used for generating the citations and bibliographic information included within the
manuscript. Depending on preference, you can create sources as a complete list of
references before developing your manuscript, or you can create sources as needed
within the document. Regardless, when a new source is created, it is added to a master
list of references for both the working document and the local computer. To add
sources to your document on a PC:
1. Place the insertion point in the document where the citation is needed
2. Click the Insert Citation button arrow.
3. Click the appropriate citation option from the list.
Creating a Bibliography
When all sources have been added to the document, a bibliography or works
cited page can be automatically generated. Before inserting the bibliography,
however, you should verify that you have cited all of the sources you will include in the
bibliography and to remove any unused sources from the reference list. To create a
bibliography:
EXPLAIN
Usually, when you are writing a long document or a research paper and you have to
do different formatting styles such as different page numbers (i, ii, iii and 1, 2, 3 ...) or
placing a header starting from page 1, the easiest way to do it is to open a new
document every time you have to change a format. Am I right? Fortunately, MS Word
has the capability to create a document with different page numbers and headers
using Page Breaks.
STEP 1: Move your cursor to the place where you want to put the page break. But if you
want to change a formatting style such as from a title page (no page number) to the
next page which is a Table of Contents with page i, then you might as well put it at the
end of your title page. This will tell MS Word to separate the title page from the TOC
page.
STEP 2: Do not forget to click the Link to Previous button in the design tab once you
have inserted a page number in the next page. Then change the format of your TOC
page.
After you have clicked the Link to Previous button this will tell MS Word that formatting
you will apply to the next page will not be applied to the previous page. For this
example, we will use the page number i for the TOC page. Go to the Insert Tab and
select the Page Number then choose Format Page Numbers.
Then select the format you want, in this example we will use i,ii,iii. Do not forget to select
page numbering at the lower part which is Start at i then click OK. Notice that initially
your page number is 2 but when you change the number format it will change to i.
If you want to delete or remove a page break or section break, you can simply click on
the symbol for Show/Hide.
Then click on the page break/section break you want to remove then press delete.
ELABORATE
In the professional world, sending out information to convey important
information is vital. Because of technology, things are sent much faster than the
traditional newsletters or postal mail. You can now use the internet to send out
information you need to share. What if we could still do things much faster, an
automated way of creating and sending uniform letters with different recipients? Would
that not be more convenient?
We will learn one of the most commonly used features of MS Word called “Mail
Merge”. As the name suggests, this feature allows you to create documents and
combine or merge them with another document or data file. It is commonly used when
sending out advertising materials to various recipients.
Mail merging basically requires two components: the document that contains
the message and the document or file that generally contains the list of names and
addresses.
1. Form document
Our sample above is what we call a form document- the first components of our
mail merged document. It is generally the document that contains the main
body of the message we want to send.
Also in the form you can see some symbols or mark with double-headed arrows (
<< >> ). These are what we call place holders or data fields/merge fields. This
marks the position on your form document where individual data or information
will be inserted.
The next component of our mail merged document is the list or data file. This is
where the individual data that needs to be merged to the form document is
placed and maintained. You can create the data file in MS Word or MS Excel or
other data formats. This way, fields that needed to be filled up on the form
document can be easily maintained without changing the form document. You
can easily add, remove or modify your data.
LABEL GENERATION
Included in the mail merge feature is the Label Generator. After you print out your form
letters, you will need to send it to individual recipients in an envelope with the matching
address printed directly on the envelope or on a mailing label to stick on. Doing the
same process as the standard mail merge, you can print individual labels.
1. Write the form document such as a letter, certificate or any document that you
want to merge.
2. On the Mailings Tab, choose Start Mail Merge then select Letters.
2. Still on the Mailings Tab, choose Select Recipients, then Type a New List.
3. Click on the Customize Columns button on the dialog box for the Address List.
Once you select that button a dialog box will appear.
If you want to delete a field, then just select it, then click the Delete button on
the right side of the dialog box. If you need to add another field just click the
Add button.
4. Type the individual data from your list corresponding to the Title, Name,
Company, Address. Press the Tab key each time you enter the next field. Click
New Entry to add another record.
5. Repeat step 4 until you enter all the records you want. Once you are done
typing your data, click the OK button on the Add New List dialog box to save
your data.
6. Insert the fields you need like First Name, Last Name, Company, Address Line 1
and City. Go to Insert Merge Field. Make sure that you place the cursor in the
place where you want it before selecting the field.
7. You can now preview the results and once you are done click Finish and Merge.
You can print the merge document or edit the individual documents.
For additional information about mail merge: watch the following videos
EVALUATE
Now that you have learned about the mail merge feature in MS Word do the GRADED
Activity #1 (M2.1) in MS Word.
GRADED Activity #1 (M2.1): Create a Calling Card using the Mail Merge of MS Word
INSTRUCTIONS:
True or False: Write T if the statement is True and F if the statement is False.
________1. When you want to insert a Table of Contents in MS Word you can simply go
to the References Tab and select the Automatic Table 1 found in the drop down list.
________ 2. You can create a Bibliography anytime after you have inserted one or more
sources into your document.
________ 3. Different heading styles can be used to create a Table of Contents in MS
Word.
________ 4. The form document contains the recipient’s information.
________ 5. The place holders or merge fields are denoted or marked by the text with
double-headed arrows (<< >>).
References:
Getting Started
When you open MS Excel for the first time, a blank spreadsheet will appear (shown
below). In more recent versions however, the Excel Start Screen will appear instead,
allowing you to create a new workbook, choose a template, and access your recently
edited workbooks.
MS Excel’s interface is divided into two sections, the Application Window, and
the Workbook Window.
Application Window
The Application Window provides the space for your worksheets and workbook
elements such as charts. The components of the Application Window are described
below.
● The Quick Access Toolbar: The Quick Access Toolbar lets you access common
commands no matter which tab is selected. By default, it includes the Save,
Undo, and Repeat commands.
● The Ribbon: MS Excel uses a tabbed Ribbon system instead of traditional menus.
The Ribbon contains multiple tabs, each with several groups of commands. You
will use these tabs to perform the most common tasks in Excel.
● The Formula Bar: In the formula bar, you can enter or edit data, a formula, or a
function that will appear in a specific cell. In the image below, cell C1 is selected
and 1984 is entered into the formula bar. Note how the data appears in both the
formula bar and in cell C1.
● The Name Box: The Name box displays the location, or "name" of a selected cell.
In the image below, cell B4 is selected. Note that cell B4 is where column B and
row 4 intersect.
The Worksheet
Depending on the version of your MS Excel, whenever you create a new Excel
workbook, it will contain one or three worksheet(s) named Sheet1 (Sheet2 and Sheet3 if
you have three). A worksheet is a grid of columns and rows where columns are
designated by letters running across the top of the worksheet and rows are designated
by numbers running down the left side of the worksheet.
When working with a large amount of data, you can create multiple worksheets
to help organize your workbook and make it easier to find content. You can also group
worksheets to quickly add information to multiple worksheets at the same time.
● Renaming a worksheet:
1. Right-click the worksheet you wish to rename, then select Rename from the
worksheet menu.
2. Type the desired name for the worksheet.
3. Click anywhere outside of the worksheet, or press Enter on your keyboard. The
worksheet will be renamed.
● To insert a new worksheet:
worksheet icon .
2. Hold and drag the mouse until a small black arrow appears above the desired
location.
3. Release the mouse. The worksheet will be moved.
Cell Addressing
Whenever you work with Excel, you'll enter information, or content, into cells.
Cells are the basic building blocks of a worksheet. You'll need to learn the basics of cells
and cell content to calculate, analyze, and organize data in Excel.
Cell Basics
Every worksheet is made up of thousands of rectangles, which are called cells. A
cell is the intersection of a row and a column. Columns are identified by letters (A, B, C),
while rows are identified by numbers (1, 2, 3).
Each cell has its own name, or cell address, based on its column and row. In this
example, the selected cell intersects column C and row 5, so the cell address is C5. The
cell address will also appear in the Name box. Note that a cell's column and row
headings are highlighted when the cell is selected.
You can also select multiple cells at the same time. A group of cells is known as a
cell range. Rather than a single cell address, you will refer to a cell range using the cell
addresses of the first and last cells in the cell range, separated by a colon. In the
images below, two different cell ranges are selected:
● Text: Cells can contain text, such as letters, numbers, and dates.
● Formatting Attributes: Cells can contain formatting attributes that change the
way letters, numbers, and dates are displayed. For example, percentages can
appear as 0.15 or 15%. You can even change a cell's background color.
● Formulas and Functions: Cells can contain formulas and functions that calculate
cell values (More on these later).
Deleting Cells
Take note that if you delete the entire cell, the cells below it will shift up and
replace the deleted cells.
1. Select the cell(s) containing the content you wish to use. The fill handle will
appear as a small square in the bottom-right corner of the selected cell(s).
2. Click, hold, and drag the fill handle until all of the cells you wish to fill are
selected.
3. Release the mouse to fill the selected cells.
Arithmetic Operations
Excel uses standard operators for formulas, such as a plus sign for addition (+), a
minus sign for subtraction (-), an asterisk for multiplication (*), a forward slash for division
(/), and a caret (^) for exponents.
Order of Operation
Excel calculates formulas based on the following order of operations:
1. Operations enclosed in parentheses.
2. Exponential calculations (3^2, for example).
3. Multiplication and division, whichever comes first.
4. Addition and subtraction, whichever comes first.
Cell References
While you can create simple formulas in Excel manually (for example, =2+2 or
=5*5), most of the time you will use cell addresses to create a formula. This is known as
making a cell reference. Using cell references will ensure that your formulas are always
accurate because you can change the value of referenced cells without having to
rewrite the formula.
$A$2 The column and the row do not change when copied
A$2 The row does not change when copied
$A2 The column does not change when copied
Note: When writing a formula, you can press the F4 key on your keyboard to
switch between relative and absolute cell references. This is an easy way to quickly
insert an absolute reference.
For more information on Cell References, watch Module 3 Excel_ Relative and Absolute
Cell References
Functions
A function is a predefined formula that performs calculations using specific
values in a particular order. Excel includes many common functions that can be useful
for quickly finding the sum, average, count, maximum value, and minimum value for a
range of cells. In order to use functions correctly, you'll need to understand the different
parts of a function and how to create arguments to calculate values and cell
references.
Parts of a Function
In order to work correctly, a function must be written a specific way, which is
called the syntax. The basic syntax for a function is an equal sign (=), the function name
(SUM, for example), and one or more arguments. Arguments contain the information
you want to calculate.
Arguments
Arguments can refer to both individual cells and cell ranges and must be
enclosed within parentheses. You can include one argument or multiple arguments,
depending on the syntax required for the function. For example, the function
=AVERAGE(B1:B9) would calculate the average of the values in the cell range B1:B9.
This function contains only one argument – that is, the cell range B1:B9.
TOTAL: 100%
This is a weighted average. One test is worth 10% of your grade while one quiz is
worth almost half of that.
Let’s look at what a grading policy might look like if nothing was weighted.
TOTAL: 100%
Each test, quiz, and homework assignment are all worth 6.25%. No one thing is
weighted as being more important than the rest.
2. Click on cell A1 then type “Test Scores (%) ” then on cell B1 “Weight %” and cell C1 “
“Weighted Scores (Test)”. Your initial worksheet should look like this;
3. Input the Test Scores as follows; 95, 85, 89 to cell A2,A3 and A4. Followed by the
individual weight % in column B. Note that each test is 10% of the grade.
The spreadsheet is split apart into two main sections. The first section which takes up
columns A, B, and C are the weighted averages. The second section, columns E and F,
are the non-weighted averages.
Column A shows all the student’s percentage scores he/she received on tests, quizzes,
homework assignments, and participation. Column B shows the percent that each test
or assignment was weighted. Column C will show the scores after they have been
weighted by the proper percentage.
Column F shows the percentage scores of the student’s grades without being
weighted. Column F is exactly the same as column A.
5. Make sure that the total weight % is equal to 100%. By using the SUM function, you
can easily compute for the total weight %. Because we are working with percentages,
we need to multiply the entire formula by 100. Note that you can also calculate it by
using the addition operator (=B1+B2+ … +B23) then multiply it with 100.
We used the SUM function, the syntax for this function is;
= SUM(number 1,[number2],{number3],...)
Note that the values can be numbers, cell references, cell range in any combination. In
our example above, we used a cell range (group of cells).
6. Move over to Column F. We need to get the average of the student’s scores in this
column. Click on cell F27.
The average function returns the average (arithmetic mean) of the arguments. For
example, if the range A1:A20 contains numbers, the formula =AVERAGE(A1:A20) returns
the average of those numbers.
SYNTAX:
● Number1 Required. The first number, cell reference, or range for which you
want the average.
● Number2, ... Optional. Additional numbers, cell references or ranges for which
you want the average, up to a maximum of 255.
7. On cell F27 enter the formula; =AVERAGE open parenthesis then click and drag from
cells F2 to F4 then enter a comma then click and drag from cells F7 to F11 then enter a
comma then click and drag from cells F14 to F20 then enter another comma. Click cell
F23 and end with parenthesis. It should look like this:
Hit enter. Cell F23 should now read an average score of about 91.31
8. Move over to Row C. We need to figure out what the weighted score is of each test
or assignment. Let’s compute for the product of Test Score % and Weight %. Click on
cell C2 then enter the formula, = (A2* B2). Note that in excel the asterisk(*) is the
operator used for multiplication.
9. With your mouse, move over the bottom right hand corner of cell C2 until a small
black plus sign appears. Click and drag down to cell C4. This will move the formula you
typed in for cell C2 down into the next two cells with the corresponding rows.
10. In cell C7, enter in the formula, =(A7*B7), then hit enter. Drag that formula down to
cell C11. In cell C14, enter in the formula, =(A14*B14), then hit enter. Drag that formula
down to cell C20. In cell C23, enter in the formula, =(A23*B23), then hit enter.
11. Click on cell C27 and enter in the formula, =SUM( then Click and drag from cells C2
to C4 then enter a comma. Then drag from cells C7 to C11 and enter a comma. Then
drag from cells C14 to C20 and enter a comma. Then click on cell C23 and end with
parenthesis. Hit enter.
The cell should now read a Weighted Grade of about 91.26.
Commonly Used Functions (MS Excel Demo.xlsx)
Text Functions
=LEFT(text, num_char)
You can use the Left function when you want to extract the leftmost characters from a
string. Similarly, you can also use the RIGHT function to extract the rightmost characters
from a string.
=PROPER (text)
Proper function in Excel capitalizes each word in the string that is, it converts the case
into proper case.
=TRIM(text)
Trim function in Excel removes the unnecessary spaces from a particular string.
=UPPER(Text )
Upper function in Excel converts the text into Upper case from lower case.
=CONCATENATE (text1, text2….)
Concatenate function in Excel helps to join the text of two or more cells.
Sorting Data
As you add more content to a worksheet, organizing that information becomes
especially important. You can quickly reorganize a worksheet by sorting your data. For
example, you could organize a list of contact information by last name. Content can
be sorted alphabetically, numerically, and in many other ways.
When sorting data, it's important to first decide if you would like the sort to apply
to the entire worksheet or just a cell range.
● Sort sheet organizes all of the data in your worksheet by one column.
● Sort range sorts the data in a range of cells, which can be helpful when working
with a sheet that contains several tables. Sorting a range will not affect other
content on the worksheet.
To sort a sheet:
Filtering Data
If your worksheet contains a lot of content, it can be difficult to find information
quickly. Filters can be used to narrow down the data in your worksheet, allowing you to
view only the information you need. To filter data
1. In order for filtering to work correctly, your worksheet should include a header
row, which is used to identify the name of each column.
2. Select the Data tab, then click the Filter command.
3. A drop-down arrow will appear in the header cell for each column.
4. Click the drop-down arrow for the column you wish to filter.
5. The Filter menu will appear.
6. Uncheck the box next to Select All to quickly deselect all data.
7. Check the boxes next to the data you wish to filter, then click OK.
8. To remove all filters from your worksheet, click the Filter command on the Data
tab.
To insert a chart:
1. Select the cells you want to chart, including the column titles and row labels.
These cells will be the source data for the chart.
2. From the Insert tab, click the desired Chart command.
3. Choose the desired chart type from the drop-down menu.
4. The selected chart will be inserted in the worksheet.
● Excel allows you to add chart elements—such as chart titles, legends, and data
labels—to make your chart easier to read. To add a chart element, click the Add
Chart Element command on the Design tab, then choose the desired element
from the drop-down menu.
● To edit a chart element, like a chart title, simply double-click the placeholder
and begin typing.
● Excel also includes several different chart styles, which allow you to quickly
modify the look and feel of your chart. To change the chart style, select the
desired style from the Chart styles group.
● Sometimes you may want to change the way charts group your data. From the
Design tab, select the Switch Row/Column command.
● If you find that your data isn't well suited to a certain chart, it's easy to switch to a
new chart type. From the Design tab, click the Change Chart Type command.
The Change Chart Type dialog box will appear, then select the desired chart
● Whenever you insert a new chart, it will appear as an object on the same
worksheet that contains its source data. Alternatively, you can move the chart to
a new worksheet to help keep your data organized.
1. Select the chart you wish to move.
2. Click the Design tab, then select the Move Chart command.
3. The Move Chart dialog box will appear. Select the desired location for the
chart.
4. Click OK.
INSTRUCTION: Open the Excel Payroll.xlsx file and perform the given instructions.
References:
COUNT Function
https://support.office.com/client/en-us/videoplayer/embed/RWeWqL?pid=ocpVideo0-innerdiv-oneplay
er&jsapi=true&postJsllMsg=true&maskLevel=20&market=en-us
IF Function
https://support.office.com/client/en-us/videoplayer/embed/RE285qJ?pid=ocpVideo0-innerdiv-oneplaye
r&jsapi=true&postJsllMsg=true&maskLevel=20&market=en-us
SUM Function
https://support.office.com/client/en-us/videoplayer/embed/RE25Ncp?pid=ocpVideo0-innerdiv-oneplaye
r&jsapi=true&postJsllMsg=true&maskLevel=20&market=en-us
SUMIF Function
https://support.office.com/client/en-us/videoplayer/embed/RWe8KX?pid=ocpVideo0-innerdiv-oneplaye
r&jsapi=true&postJsllMsg=true&maskLevel=20&market=en-us
Sorting Data
https://support.office.com/client/en-us/videoplayer/embed/RWfzt5?pid=ocpVideo0-innerdiv-oneplayer
&jsapi=true&postJsllMsg=true&maskLevel=20&market=en-us
A Brief History
● developed in early 1990s by James Gosling et. al. as the programming language
component of the Green Project at Sun Microsystems
● originally named Oak and intended for programming networked “smart”
consumer electronics
● launched in 1995 as a “programming language for the Internet”; quickly gained
popularity with the success of the World Wide Web
● currently used by around 5 million software developers and powers more than
2.5 billion devices worldwide, from computers to mobile phones
● Design Goals
o simple: derived from C/C++, but easier to learn
o secure: built-in support for compile-time and run-time security
o distributed: built to run over networks
o object-oriented: built with OO features from the start
o robust: featured memory management, exception handling, etc.
o portable: “write once, run anywhere''
o interpreted: “bytecodes” executed by the Java Virtual Machine
o multithreaded, dynamic, high-performance, architecture-neutral
o Bytecodes are the machine language understood by the Java virtual
machine
Java Platform
The following are video tutorials of some of the programming editors or Integrated
Development Environment (IDE) that can assist you in writing java programs. Follow the
steps in the installation of any of the following IDEs.
● Module 4: How to Install JDK and JCREATOR LE.mp4
● Module 4: How to Install Eclipse IDE w Java JDK 13 on Windows 10.mp4
● Module 4: How to Install NetBeans 11 IDE And Java JDK SE 14 on Windows 10 8
7.mp4
You may also choose to use some online java compilers enumerated below:
● https://replit.com/languages/java10
● https://www.jdoodle.com/online-java-compiler/
● https://www.onlinegdb.com/online_java_compiler
● https://www.w3schools.com/java/java_compiler.asp
● https://compiler.javatpoint.com/opr/online-java-compiler.jsp
● https://www.jgrasp.org/
Fundamental Concepts
Java Comments
● Comments are notes written to a code for documentation purposes. Those texts
are not part of the program and do not affect the flow of the program.
Two types of comment
o Single Line Comment
Example:
//This is an example of a single line comment
o Multi-line Comment
Example:
/* This is an example of a
multiline comment enclosed by two delimiters
that starts with a /* and ends with a */
*/
● A statement is any complete sentence that causes some action to occur. A valid
Java statement must end with a semicolon.
Examples:
System.out.println(“Hello world”);
int k; int j = 10;
double d1, d2, k, squareRootTwo;
k = a + b – 10;
boolean p = ( a >= b );
squareRootTwo = Math.sqrt(2);
● A block is one or more statements bounded by an opening and closing curly
braces that groups the statements as one unit. Block statements can be nested
indefinitely. Any amount of white space is allowed.
Example:
public static void main (String[] args)
{
System.out.println(“Hello”) ;
System.out.println(“World”) ;
}
● An expression is a value, a variable, a method, or one of their combinations that
can be evaluated to a value.
Examples:
int cadence = 0;
anArray[0] = 100;
8 >= x;
p || q ;
System.out.println("Element 1 at index 0: " + anArray[0]);
double squareRootTwo = Math.sqrt(2)
Java Identifiers
● Identifiers are tokens that represent names of variables, methods, classes, etc.
Examples of identifiers are: Hello, main, System, out.
● Java identifiers are case-sensitive. This means that the identifier: Hello is not the
same as hello.
Coding Standards
● There are certain rules for the naming of Java identifiers. Valid Java identifier
must be consistent with the following rules.
o An identifier cannot be a Java reserve word.
o An identifier must begin with an alphabetic letter, underscore (_), or a dollar
sign ($).
o If there are any characters subsequent to the first one, those characters must
be alphabetic letters, digits, underscores (_), or dollar signs ($).
o Whitespace cannot be used in a valid identifier.
o An identifier must not be longer than 65,535 characters.
● Also, there are certain styles that programmers widely used in naming variables,
classes and methods in Java. Here are some of them.
o Use lowercase letter for the first character of variables’ and methods’ names.
o Use pascal case for the class names (ex: LastnameResistor)
o Use camel case for the methods and variables (ex: subtractFunction,
radius1Ellipse)
o Compound words or short phrases are fine, but use uppercase letter for the
first character of the words subsequent to the first. Do not use underscore to
separate words.
o Use uppercase letter for all characters in a constant. Use underscore to
separate words.
o Apart from the mentioned cases, always use lowercase letter.
o Use verbs for methods’ names.
● Here are some examples for good Java identifiers.
o Variables: height, speed, filename, tempInCelcius, incomingMsg, textToShow.
o Constant: SOUND_SPEED, KM_PER_MILE, BLOCK_SIZE.
o Class names: Account, DictionaryItem, FileUtility, Article.
o Method names: locate, sortItem, findMinValue, checkForError.
● Based on Oracle Coding standard, there should be four spaces before
indentation.
● Not following these styles does not mean breaking the rules, but it is always good
to be in style!
Java Keywords
● Keywords are predefined identifiers reserved by java for specific purposes. You
cannot use keywords as names of variables, classes, methods, etc.
● The difference between the various numeric primitive types is their size, and
therefore the values they can store:
Size Range of values that can be
Type stored
byte 1 byte −128 to 127
short 2 bytes −32768 to 32767
int 4 bytes −2,147,483,648 to
Integer 2,147,483,647
long 8 bytes −9,223,372,036,854,775,808
to
9,223,372,036,854,755,807
Floating float 4 bytes −3.4e−038 to 3.4e+038
Point double 8 bytes −1.7e−308 to 1.7e+038
Characters
Uppercase letters A, B, C, …
Lowercase letters a, b, c, …
Punctuation period, semi-colon, comma, …
Digits 0, 1, 2, …
Special symbols &, |, \, …
Control characters carriage return, tab, …
Character Strings
● are symbols that indicate the division and arrangement of groups of code. The
structure and function of code is generally defined by the separators. The
separators used in Java are as follows:
o parentheses ( )
- Used to define precedence in expressions, to enclose parameters in
method definitions, and enclosing cast types
o braces { }
- Used to define a block of code and to hold the values of arrays.
o brackets [ ]
- Used to declare array types.
o semicolon ;
- Used to separate statements.
o comma ,
- Used to separate identifiers in a variable declaration and in
the for statement.
o period .
- Used to separate package names from classes and subclasses and to
separate a variable or a method from a reference variable.
Variables
int total;
Variable Initialization
● assigning a value to a variable for the first time
● a variable can be given an initial value in the declaration with an equal sign
Example:
int sum = 0;
int base = 32, max = 149;
● when a variable is referenced in a program, its current value is used
example:
int keys = 88;
System.out.println(“A piano has ”+ keys + “ keys”);
● prints as:
A piano has 88 keys
Assignment Statement
● an assignment statement changes the value of a variable
● the equals sign is also the assignment operator
Example:
● the expression on the right is evaluated and the result is stored as the value of the
variable on the left
● the value previously stored in total is overwritten
● you can only assign a value to a variable that is consistent with the variable's
declared type
Constants
● a constant is an identifier that is similar to a variable except that it holds the same
value during its entire existence
● as the name implies, it is constant, not variable
● in Java, we use the reserved word final in the declaration of a constant
example:
final int MIN_HEIGHT = 69;
● any subsequent assignment statement with MIN_HEIGHT on the left of the =
operator will be flagged as an error
Constants are useful for three important reasons
o first, they give meaning to otherwise unclear literal values
▪ for example, NUM_STATES means more than the literal 50
o second, they facilitate program maintenance
▪ if a constant is used in multiple places and you need to change its
value later, its value needs to be updated in only one place
o third, they formally show that a value should not change, avoiding
inadvertent errors by other programmers
String Concatenation
● the string concatenation operator (+) is used to append one string to the end of
another
"Peanut butter " + "and jelly"
● it can also be used to append a number to a string
● a string literal cannot be broken across two lines in a program so we must use
concatenation
System.out.println(“The following facts are for your ” + “extracurricular edification”);
● the + operator is also used for arithmetic addition
● the function that it performs depends on the type of the information on which it
operates
● if both operands are strings, or if one is a string and one is a number, it performs
string concatenation
● if both operands are numeric, it adds them
● the + operator is evaluated left to right, but parentheses can be used to force
the order
System.out.println(“24 and 45 concatenated: ” + 24 + 45);
prints as: 24 and 45 concatenated: 2445
● the + operator is evaluated left to right, but parentheses can be used to force
the order
System.out.println(“24 and 45 added: ” + (24 + 45));
Escape Sequences
● Example
System.out.println(“Roses are red,\n\tViolets are blue”);
Prints as:
Roses are red,
Violets are blue
● To put a specified Unicode character into a string using its code value, use the
escape sequence: \uhhhh where hhhh are the hexadecimal digits for the
Unicode value
Example: Create a string with a temperature value and the degree symbol:
double temp = 98.6;
System.out.println(“Body temperature is ” + temp + “ \u00b0F.”);
Prints as:
Body temperature is 98.6 ºF.
Note:
When evaluating the mod operator with negative integer operands, the answer
always takes the sign of the dividend.
Illustration:
-34 % 5 = -4
34 %-5 = 4
-34 %-5 = -4
34 % 5 = 4
Increment/Decrement Operators
● Aside from basic arithmetic operators, Java also includes a unary increment
operator and unary decrement operator.
o Increment Operator (++)
- increases the value of a variable by 1
Example:
int count = 3;
count = count + 1;
// the above statement may be written as the one
//shown below.
count++;
Relational Operators
● Relational operators compare two values and determine the relationship
between those values.
● The outputs of evaluation are the boolean values true or false.
Operator Description
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
== Equal to
!= Not equal to
Logical Operators
● Logical operators have Boolean operands that yield a Boolean result.
Operator Description Illustration
True && True = True
Logical AND
True && False = False
&& ● Returns True if all of its boolean
False && True = False
operands are True, False if otherwise.
False && False = False
Logical OR True||True = True
● Returns True if at least one of its True||False = True
||
Boolean operands are True, otherwise False||True = True
False False||False = False
Logical NOT !True = False
!
● Reverses the value of its operand. !False = True
Simple Calculation
1 to 10.
● In the above example, the statement in line 5 declares two variables that are
used to store floating point numbers. In line 6, the values from 1.0 to 10.0 are
summed together using the + operator and the resulting value is assigned to sum.
In line 7, the value of sum is divided by 10 which to obtain their average. The
statement in line 8 just prints the result on screen.
- Programmers do not sit down and start writing code right away when trying to make
a computer program. Instead, they follow an organized plan or methodology that
breaks the process into a series of tasks.
Here are the basic steps in trying to solve a problem on the computer:
1. Problem Definition
● A programmer is usually given a task in the form of a problem. Before a program
can be designed to solve a particular problem, the problem must be well and
clearly defined first in terms of its input and output requirements.
● A clearly defined problem is already half the solution. Computer programming
requires us to define the problem first before we even try to create a solution.
2. Problem Analysis
● After the problem has been adequately defined, the simplest and yet the most
efficient and effective approach to solve the problem must be formulated.
● Usually, this step involves breaking up the problem into smaller and simpler
sub-problems.
3. Algorithm Design and Representation (flowchart)
● Once our problem is clearly defined, we can set to finding a solution. In
computer programming, it is normally required to express our solution in a
step-by-step manner.
● An Algorithm is a clear and unambiguous specification of the steps needed to
solve a problem. It may be expressed in either Human Language (English,
Tagalog), through a graphical representation like flowchart.
● Now given that the problem is defined, how do we express our general solution
Connector Represents any entry from, or exit to, another part of the
Symbol flowchart. Also serves as an off-page connector.
● After constructing the program, it is now possible to create the source code.
Using the algorithm as basis, the source code can now be written using the
chosen programming language.
● Most of the time, after a programmer has written the program, the program isn’t
100% working right away. The programmer has to add some fixes to the program
in case of errors (also called bugs) that occurs in the program. This process is
called debugging.
● Compile-Time Error
- Occur if there is a syntax error in the code. The compiler will detect the
error and the program won’t even compile. At this point, the programmer
is unable to form an executable that a user can run until errors are fixed.
Forgetting a semi-colon at the end of a statement or misspelling a certain
command, for example, is a compile-time error.
● Runtime Error
- Compilers aren’t perfect and so can’t catch all errors at compile time. This
is especially true for logic errors such as infinite loops. This type of error is
called runtime error. For example, the actual syntax of the code looks
okay. But when you follow the code’s logic, the same piece of code
keeps executing over and over again infinitely so that it loops.
● To create a computer program that works, one need not only the knowledge
about the rules and syntaxes of a programming language but also a procedure
or a process that is used to accomplish the objectives of that program. Such a
procedure is called an algorithm. Usually, before creating a computer program,
an algorithm is developed based on the objective of the program before the
source code is written. An algorithm could be as simple as a single command.
More often than not, they are more complex.
● A flowchart needs a starting point of the program it represents and one or more
terminations. Steps or commands involved in the program are represented using
rectangles containing textual descriptions of the corresponding steps or
commands. These steps as well as the starting and terminating points are
connected together with line segments in which arrows are used for determining
the order of these steps. Shapes are typically placed from the top of the chart to
the bottom according to their orders. The starting and terminating points are
represented using oval shapes. Different shapes apart from the two shapes
already mentioned are defined so that they imply some specific meanings. The
following flowchart shows an algorithm of a computer program that prints out
the average of the integers from 1 to 10.
You can learn further about flowcharts by watching the Module 5 Flow Charting video.
Example: A java program that allows the user to input two numbers. The program
calculates the sum and displays it.
For additional information about the Scanner class: watch
1. Filename: PipeProblem_FamilyName
Create a flowchart and a java program
that will input the outside and the
inside diameter (outDia, inDia) of a
pipe. Calculate and print the thickness
(T) of the wall of the pipe.
(𝑜𝑢𝑡𝐷𝑖𝑎−𝑖𝑛𝐷𝑖𝑎)
Formula: 𝑇 = 2.0
2. Filename: TemperatureProblem_FamilyName
Create a java program that will read a
temperature in degrees Fahrenheit (F),
output in degrees Centigrade (C).
Formula to convert degrees Centigrade to
9
degrees Celcius: 𝐹 = 5 * (𝐶 + 32)
3. Filename: AngleToRadianProblem_FamilyName
Create a flowchart and a java program
that will read an angle expressed in
degrees (deg), minutes (min) and seconds
(sec), output in radians (rad).
( )
𝑚𝑖𝑛 𝑠𝑒𝑐
𝑑𝑒𝑔 + + 3600
Formula: 𝑟𝑎𝑑 = π * 60
180
4. Filename: PowerLossProblem_FamilyName
Create a java program that will read a
current (I_AMP) flowing through a cable
and the resistance (R_OHM) of the cable,
compute and output the power loss
(P_WATT) through the cable.
Formula:
2
𝑃_𝑊𝐴𝑇𝑇 = 𝑅_𝑂𝐻𝑀 * 𝐼_𝐴𝑀𝑃
Sample Output:
5. Filename: ChangeProblem_FamilyName
Create a flowchart and a java program that
will input the amount of purchase which is
less than P100.00. The program will
calculate the change of P100.00 given by
the customer with the following breakdown:
P 50.00 - _______________;
P 20.00 - _______________;
P 10.00 - _______________;
P 5.00 - _______________;
P 1.00 - _______________;
Note: Purchases are all in pesos. No centavos.
Formula Hint: Apply the concept of modulus operator
6. Filename: TriangleProblem_FamilyName
If a, b and c represent the three sides of a triangle, then the area of the triangle is:
𝑎+𝑏+𝑐
𝐴 = 𝑠 * (𝑠 − 𝑎) * (𝑠 − 𝑏) * (𝑠 − 𝑐) where: 𝑠 = 2.0
𝐴
Also the radius of the largest inscribed circle is given by: 𝑟_𝑖𝑛𝑠𝑐 = 𝑠
𝑎*𝑏*𝑐
and the radius of the smallest circumscribed circle is: 𝑟_𝑐𝑖𝑟𝑐 = 4*𝐴
Create a java program that will input the three sides of a triangle. Calculate and output
the area of the triangle, the area of the largest inscribed circle, and the area of the smallest
circumscribed circle given a value for a, b and c.
Sample Output:
Instruction:
If Statement
● The if statement is Java’s conditional branch statement. It can be used to route
program execution through two different paths. Here is the general form of the if
statement:
● Here, each statement may be a single statement or a compound statement
enclosed in curly braces (that is, a block). The condition is any expression that
returns a boolean value. The else clause is optional.
● The if works like this: If the condition is true, then statement1 is executed.
Otherwise, statement2 (if it exists) is executed. In no case will both statements be
executed. For example, consider the following:
int a, b;
if(a < b)
a = 0;
else
b = 0;
Nested ifs
● A nested if is an if statement that is the target of another if or else. Nested ifs are
very common in programming. When you nest ifs, the main thing to remember is
that an else statement always refers to the nearest if statement that is within the
same block as the else and that is not already associated with an else. Here is an
example:
if(i == 10) {
if(j < 20)
a = b;
if(k > 100)
c = d;
else
a = c;
}else
a = d; // this else refers to the if(i == 10)
● As the comments indicate, the final else is not associated with if(j<20) because it
is not in the same block (even
though it is the nearest if
without an else). Rather, the
final else is associated with
if(i==10). The inner else refers
to if(k>100) because it is the
closest if within the same
block.
For additional information about java’s selection statements: watch the following
videos
● Module 7: If Statement.mp4
● Module 7: If-else Statement.mp4
● Module 7: The If-Else-If Ladder.mp4
● Module 7: Nested IF Statements.mp4
Problems for Program Development: Solve using Decision Control Structure (if)
1. ThreeNumbersProblem_FamilyName
Create a flowchart and a java program that reads three distinct numbers (X,Y,Z). Determine
and output the following:
a) highest number (HN)
b) middle number (MN)
c) smallest number (SN)
d) the numbers in ascending order
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
2. YearProblem_FamilyName
A leap year is a year divisible by 4 unless it is a century year, in which case it must be
divisible by 100. Create a java program that reads a year and output a message whether the
year is a leap year, century year or ordinary year.
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
3. GradeProblem_FamilyName
A professor displays remarks for numeric grades in the following way:
Grade Remarks
93 – 99 Excellent
87 – 92 Very Good
80 – 86 Good
70 – 79 Fair
65 - 69 Poor
Using if, create a flowchart and a java program that reads a numeric grade and output the
equivalent remarks.
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
4. ParkingFeeProblem_FamilyName
Parking charge per hour at SMBC underground parking is as follows:
P 35.00 - minimum charge for 4 hours parking or less,
P 15.00/hr. - additional charge in excess of 4 hours parking,
P 250.00 - maximum charge.
Create a java program that reads the number of hours a vehicle was parked. Calculate and
output the parking charge.
(Note: Inputs should be integers only)
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
5. ElectricBillProblem_FamilyName
The ABC Electric Company bases its electricity charges on two rates. Customers are charged
P30.12 per kilowatt-hour (KWH) for the first 400 KWH used in a month, and P25.23 for all
KWH used thereafter. Create a flowchart and a java program that reads an electric
consumption and output the amount to be charged to the customer.
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
Instruction:
Switch
● The expression must be of type byte, short, int, or char; each of the values
specified in the case statements must be of a type compatible with the
expression. (An enumeration value can also be used to control a switch
statement. Each case value must be a unique literal (that is, it must be a
constant, not a variable). Duplicate case values are not allowed.
● The switch statement works like this: The value of the expression is compared with
each of the literal values in the case statements. If a match is found, the code
sequence following that case statement is executed. If none of the constants
matches the value of the expression, then the default statement is executed.
However, the default statement is optional. If no case matches and no default is
present, then no further action is taken.
● The break statement is used inside the switch to terminate a statement
sequence. When a break statement is encountered, execution branches to the
first line of code that follows the entire switch statement. This has the effect of
“jumping out” of the switch.
● The break statement is optional. If you omit the break, execution will continue on
into the next case. It is sometimes desirable to have multiple cases without break
statements between them.
● The following are java programs that uses a switch statement:
For additional information about the switch statement: watch
Module 7: The Switch Statement.mp4
1. GradeProblemUsingSwitch_FamilyName
A professor converts numeric grades to letter grades in the following way:
Grade Letter Grade
93 – 99 A
87 – 92 B
80 – 86 C
70 – 79 D
65 - 69 E
Using switch, create a java program that reads a numeric grade and output the equivalent
letter grade. There should be an error message if the grade entered is invalid.
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
2. CommodityCodeProblemUsingSwitch_FamilyName
A certain store has the following scheme:
Commodity Code:
1 - commodities are discounted by 15%
2 - commodities are taxed by 12%
3 - commodities are charged as priced
Using switch, create a program that reads a commodity code, quantity of the commodities
bought and the unit price and output the amount to be paid by the customer.
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are calculated
and outputted by the program):
Using switch for the choices, create a flowchart and a java program that will display a
menu and the user can choose which figure to compute.
The user decides whether 1. Trapezoid, 2. Ellipse, or 3. Equilateral Triangle. Compute the
area of the figure chosen and output the results.
Depicted below are sample outputs when the program is executed (the items in
bold characters are inputted by the user, while the items in bold italic characters are
calculated and/or outputted by the program):
Required: The flowchart, the .java file (FamilyName_Figure.java) containing the code
and 3 image files (Sample1, Sample2, and Sample3) containing different sample
input/output of the program.
For additional information about the for loop: watch Module 8: The FOR Loop.mp4
More For Loop Examples
FileName: Series3Problem_FamilyName
Create a java program that will output the numbers 1 4 7 ... between 1 and 150.
//no need to import the Scanner Class since there in no input in this program
public class Series3_CABS {
public static void main(String[] args) {
//initial value of x = 1
//this loop is terminated when the value of x is greater than 150
//value of the counter increases by 3
for(int x = 1; x<=150; x=x+3){
//output the value of x while x<=150
System.out.print(x+" ");
}
}
}
Create a java program that reads a number and calculate and output its
factorial.
Depicted below are sample outputs when the program is executed (the items in bold
characters are inputted by the user, while the items in bold italic characters are
calculated and outputted by the program):
}
}
Flowchart Diagram for Factorial Using For Loop
While Loop
● The while loop is Java’s most fundamental loop statement. It repeats a
statement or block while its controlling expression is true. Here is its general form:
while(condition) {
// body of loop/statements
}
● The condition can be any Boolean expression. The body of the loop will be
executed as long as the conditional expression is true. When condition becomes
false, control passes to the next line of code immediately following the loop. The
curly braces are unnecessary if only a single statement is being repeated.
Sample Program:
For additional information about the while loop: watch Module 8: The While Loop.mp4
Filename: Series2Problem_FamilyName
Output the set of numbers in the series 1 2 4 7 11 16 … until 211 is reached.
Depicted below is a sample output when the program is executed:
}
}
}
Flowchart Diagram of Series2 using While Loop
Filename: SphereProblem_FamilyName
Create a java program that will calculate and output the volume and area of spheres using the
formula:
V = (4PiR3)/3 A = 4PiR 2
where R is the radius of the sphere is from 1 to 20.
Depicted below is a sample output when the program is executed:
Do-while Loop
● If the conditional expression controlling a while loop is initially false, then the
body of the loop will not be executed at all. However, sometimes it is desirable to
execute the body of a loop at least once, even if the conditional expression is
false to begin with. In other words, there are times when you would like to test the
termination expression at the end of the loop rather than at the beginning.
Fortunately, Java supplies a loop that does just that: the do-while. The do-while
loop always executes its body at least once, because its conditional expression is
at the bottom of the loop. Its general form is
do {
// body of loop
} while (condition);
● Each iteration of the do-while loop first executes the body of the loop and then
evaluates the conditional expression. If this expression is true, the loop will repeat.
Otherwise, the loop terminates. As with all of Java’s loops, condition must be a
Boolean expression.
Sample Program
More Do While Loop Examples
Filename: ObjectProblem_FamilyName
An object falling from rest in a vacuum falls 16 feet on the first second, 48 feet on
the 2nd second, 80 feet on the third second, 112 feet the 4th second and so on.
Create a java program that will output the distance traveled by the object after
15 seconds.
Depicted below is a sample output when the program is executed:
//no need the import the Scanner Class since there is no input
public class Bounce_CABANILLA {
public static void main(String[] args) {
//in order to better understand this program, please try to solve is manually
double d = 50, dist = 50.0;
int b = 1;
do{
//the ball bounces 2/3 of the previous height
d = (2.0/3.0)*d;
//if the ball will bounce it goes up and down so distance travelled is doubled
dist = dist + 2*d;
//counter/number of bounce
b++;
}
//the loop is terminated after the 10th bounce
while(b<=10);
//the 1/2 of the distance on the 10th bounce is subtracted
dist = dist-d;
//output the total distance travelled
System.out.println("@ b = "+(b-1)+ "the distance travelled by the ball is "+dist);
}
}
Flowchart Diagram for Bounce using DoWhile
Problems for Program Development: Repetition Control Structure (while, do-while, for)
2. FileName:
EquationProblem_FamilyName (Use While Loop)
Using the equation Y=2+4X-X^2, create a java program that will compute and output
values of Y for values of X from 1 to 20, and in increment of 1.
The figure shown is a sample output when the program is executed:
3. FileName: Series1Problem_FamilyName (Use Do While Loop)
The value of S is computed from the formula:
S = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/N
Create a flowchart and a java program that will output the number of terms required and
the value of S before S exceeds 3.1.
Example:
1st term: S = 1;
2nd term: S = 1 + 1/2 = 1.5;
3rd term: S = 1 + 1/2 + 1/3 = 1.8333;
4th term: S = 1 + 1/2 + 1/3 + 1/4 = 2.08333;
5th term: S = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.2833;
...
nth term: S = ?
Depicted below is a sample output when the program is executed:
Instruction:
Create a flowchart and a java program that reads a positive, non-zero integer as input
and checks if the integer is deficient, perfect, or abundant.
A positive, non-zero integer, N, is said to be perfect if the sum of its positive proper
divisors (i.e., the positive integers, other than N itself, that divide N exactly) is equal to
the number itself. If this sum is less than N, the number is said to be deficient. If the sum
is greater than N, the number is said to be abundant.
The first few perfect numbers are 6, 28, 496, and 8128.
Illustrations:
Number Factors of the number less than Sum of Factors
itself
6 3, 2, 1 6
28 14, 7, 4, 2, 1 28
For example, the number 6 is perfect, since 6 = 1 + 2 + 3, the number 8 is deficient, since
8 > 1 + 2 + 4, while the number 12 is abundant, since 12 < 1 + 2 + 3 + 4 + 6.
Sample Input/Output:
Depicted below are sample outputs when the program is executed (the items in bold
characters are input from the user, while the items in bold italic are calculated and
printed by the program):
Required: The flowchart, the .java file (FamilyName_Perfect.java) containing the code
and 3 image files (Sample1, Sample2 and Sample3) containing different sample
input/output of the program.
Instruction:
A mathematician named Ulam proposed generating a sequence of numbers from any
positive integer N greater than 1 using the following procedure:
If N is 1, stop.
If N is even, replace it with N/2.
If N is odd, replace it with 3 * N + 1.
Here are some examples of the Ulam sequence for the first few integers.
2, 1
3, 10, 5, 16, 8, 4, 2, 1
4, 2, 1
5, 16, 8, 4, 2, 1
6, 3, 10, 5, 16, 8, 4, 2, 1
Create a java program using while/do-while that accepts as input an integer value N
(assume N > 1) and prints out the Ulam sequence that begins with the input value N.
Sample Input/Output:
Depicted below are sample outputs when the program is executed (the items in bold
characters are input from the user, while the items in bold italic are calculated and
printed by the program):
Required: The .java file (FamilyName_Ulam.java) containing the code and 2 image files
(Sample1 and Sample2) containing different sample input/output of the program.
Module 9: Java Arrays
Arrays
● An array is a collection of objects (consists of a collection of data) that holds a
fixed number of values of the same data type.
● Arrays of any type can be created and may have one or more dimensions. A
specific element in an array is accessed by its numerical index.
One-Dimensional Array
● A one-dimensional array is, essentially, a list of like-typed variables. To create an
array, you first must create an array variable of the desired type. The general
form of a one-dimensional array declaration is
type var-name[ ]; or type[]var-name;
● Here, type declares the base type of the array. The base type determines the
data type of each element that comprises the array. Thus, the base type for the
array determines what type of data the array will hold. For example, the
following declares an array named month_days with the type “array of int”:
int month_days[]; or int [] month_days;
● Although this declaration establishes the fact that month_days is an array
variable, no array actually exists. In fact, the value of month_days is set to null,
which represents an array with no value. To link month_days with an actual,
physical array of integers, you must allocate one using new and assign it to
month_days. new is a special operator that allocates memory. You will look more
closely at new later, but you need to use it now to allocate memory for arrays.
The general form of new as it applies to one-dimensional arrays appears as
follows:
array-var = new type[size];
● Here, type specifies the type of data being allocated, size specifies the number
of elements in the array, and array-var is the array variable that is linked to the
array. That is, to use new to allocate an array, you must specify the type and
number of elements to allocate. The elements in the array allocated by new will
automatically be initialized to zero. The following example allocates a
12-element array of integers and links them to month_days.
month_days = new int[12];
● After this statement executes, month_days will refer to an array of 12 integers.
Further, all elements in the array will be initialized to zero.
● Let’s review: Obtaining an array is a two-step process. First, you must declare a
variable of the desired array type. Second, you must allocate the memory that
will hold the array, using new, and assign it to the array variable. Thus, in Java all
arrays are dynamically allocated. Once you have allocated an array, you can
access a specific element in the array by specifying its index within square
brackets. All array indexes start at zero. For example, this statement assigns the
value 28 to the second element of month_days.
month_days[1] = 28;
● The next line displays the value stored at index 3.
System.out.println(month_days[3]);
● Putting together all the pieces, here is a program that creates an array of the
number of days in each month.
// Demonstrate a one-dimensional array.
public class Array {
public static void main(String args[]) {
int month_days[];
month_days = new int[12];
month_days[0] = 31;
month_days[1] = 28;
month_days[2] = 31;
month_days[3] = 30;
month_days[4] = 31;
month_days[5] = 30;
month_days[6] = 31;
month_days[7] = 31;
month_days[8] = 30;
month_days[9] = 31;
month_days[10] = 30;
month_days[11] = 31;
System.out.println("April has " + month_days[3] + " days.");
}}
● Arrays can be initialized when they are declared. The process is much the same
as that used to initialize the simple types. An array initializer is a list of
comma-separated expressions surrounded by curly braces. The commas
separate the values of the array elements. The array will automatically be
created large enough to hold the number of elements you specify in the array
initializer. There is no need to use new. For example, to store the number of days
in each month, the following code creates an initialized array of integers:
// An improved version of the previous program.
public class AutoArray {
public static void main(String args[]) {
int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
System.out.println("April has " + month_days[3] + " days.");
}
}
More examples of One Dimensional Array
1. A java program that determines and displays the average array of values.
public class Average {
public static void main(String args[]) {
double arrayKo[] = {10.1, 11.2, 12.3, 13.4, 14.5};
double sum = 0, ave;
int i;
for(i=0; i<5; i++)
{
sum = sum + arrayKo[i];
}
ave = sum/5.0;
System.out.println("Average is " + ave);
}
}
2. A java program that allows the user to manually input the array size and elements in the
memory then displays its elements.
import java.util.Scanner;
public class JavaArrays {
public static void main(String[] args) {
Scanner ram = new Scanner(System.in);
System.out.print("Enter the array elements: ");
int size = ram.nextInt();
//declaring the 1-Dimensional Array
int arrayKo[]= new int[size];
int i;
//accessing the indices in the array
//then allocating the elements manually
for(i=0; i<size; i++)
{
System.out.print("The element at index "+i+" is ");
arrayKo[i] = ram.nextInt();
}
System.out.print("The array elements: ");
//access each of the indices in the array then display the array elements
for(i=0; i<5; i++)
{
System.out.print(arrayKo[i] + " ");
}
}
}
For additional information about one-dimensional arrays: watch
Module 9: Declaring Arrays & Accessing Elements.mp4
For additional information about one-dimensional arrays and the for loop: watch
Module 9: Using a Loop to Access an Array.mp4
3. Create a flowchart and a java program that inputs N digits as the elements of a 1-dimensional
array. Accept a digit and search it in the array. Output the subscript of the element.
Depicted below is a sample output when the program is executed:
Multidimensional Arrays
● In Java, multidimensional arrays are actually array of arrays. These, as you might
expect, look and act like regular multidimensional arrays. However, as you will
see, there are a couple of subtle differences. To declare a multidimensional
array variable, specify each additional index using another set of square
brackets. For example, the following declares a two-dimensional array variable
called twoD.
int twoD[][] = new int[4][5];
● The above code allocates a 4 by 5 array and
assigns it to twoD. Internally this matrix is
implemented as an array of arrays of int.
● When you allocate memory for a multidimensional
array, you need only specify the memory for the
first (leftmost) dimension. You can allocate the
remaining dimensions separately. The figure shown
is a conceptual view of a 4 by 5, two-dimensional
array.
● The following program randomly assign numbers as elements in the array from
left to right, top to bottom, and then displays these values:
// Demonstrate a two-dimensional array using the Random Class.
//import the Random Class
import java.util.Random;
public class TwoDArray {
public static void main(String[] args) {
//set up the program to be ready to accept
//a random input
Random rand = new Random();
//declaring the 2-Dimensional Array (4x5)
int twoD[][]= new int[4][5];
int i, j, k = 0;
System.out.println("The array elements: ");
//allocating the elements of a 4 by 5 array using the random class
for(i=0; i<4; i++){
for(j=0; j<5; j++){
//random number from 0 to 9 will be store at index twoD[i][j]
twoD[i][j] = rand.nextInt(10);
}
}
//access each of the indices in the array then display the array elements
for(i=0; i<4; i++) {
for(j=0; j<5; j++){
System.out.print(twoD[i][j] + " ");
}
System.out.println();
}
}
}
Instruction:
There are two lists of numbers. Create a resultant list whose elements are the product of
the elements of the two lists.
Sample Input/Output:
Depicted below are sample outputs when the program is executed (the items in bold
characters are input from the user, while the items in bold italic are generated,
calculated and printed by the program):
Required: The .java file (FamilyName_List.java) containing the code and 2 image files
(Sample1 and Sample2) containing different sample input/output of the program.
Instruction:
Create a java program that generates elements (randomly from 10 – 75) of a 2-dimensional array
(5x5) using the Random Class then perform the following:
Depicted below are sample outputs when the program is executed (the items in bold
characters are input from the user, while the items in bold italic are generated,
calculated and printed by the program):
Required: The .java file (FamilyName_2Dim.java) containing the code and 2 image files
(Sample1 and Sample2) containing different sample input/output of the program.
Creating Methods
● Considering the following example to explain the syntax of a method:
public static int methodName(int a, int b) {
// body
}
● Here,
public static: modifier.
int: return type
methodName: name of the method
a, b: formal parameters
int a, int b: list of parameters
● Method definition consists of a method header and a method body. The same is
shown below:
modifier returnType nameOfMethod (Parameter List) {
// method body
}
● The syntax shown above includes:
modifier: It defines the access type of the method and it is optional to use.
returnType: Method may return a value.
nameOfMethod: This is the method name. The method signature consists
of the method name and the parameter list.
Parameter List: The list of parameters, it is the type, order, and number of
parameters of a method. These are optional, methods may contain zero
parameters.
method body: The method body defines what the method does with
statements.
● Example: Here is the source code of the above defined method called max. This
method takes two parameters num1 and num2 and returns the minimum
between the two:
/*
* the snippet returns the minimum between two numbers
*/
public static int minFunction(int n1, int n2) {
int min;
if (n1 > n2){
min = n2;
}
else{
min = n1;
}
return min;
}
Method Calling:
● For using a method, it should be called. There are two ways in which a method is
called i.e. method returns a value or returning nothing noreturnvalue. The
process of method calling is simple. When a program invokes a method, the
program control gets transferred to the called method. This called method then
returns control to the caller in two conditions, when:
o return statement is executed.
o reaches the method ending closing brace.
● The method returning void is considered as a call to a statement. Let is consider
an example:
System.out.println("Calling a method!");
● The method returning value can be understood by the following example:
int result = sum (6, 9);
Example:
● The following is an example which demonstrate how to define a method and
how to call it:
public class ExampleMinNumber_Method{
public static void main(String[] args) {
int a = 11;
int b = 6;
int c = minFunction(a, b);
System .out.println("Minimum Value = " + c);
}
//returns the minimum of two numbers Sample Output:
public static int minFunction(int n1, int n2) {
int min;
if (n1 > n2)
min = n2;
else
min = n1;
return min;
}
}
Example:
public class ExampleVoid_Method {
public static void main(String[] args) {
methodRankPoints(255.7);
}
public static void methodRankPoints(double points) {
if (points >= 202.5) {
System.out.println("Rank:A1");
}
else
if (points >= 122.4) {
System.out.println("Rank:A2");
}
else {
System.out.println("Rank:A3");
}
}
}
● Overloading methods makes the program readable. Here, two methods are
given the same name but with different parameters. The minimum number from
integer and double types is the result.
Instruction:
Create a flowchart and a java program of the problem stated as follows. Create
user-defined methods that will perform 4 functionalities of an Automated Teller
Machine(Withdraw, Deposit, Transfer, Balance Check)
1. Withdraw (method name: withdraw)
* Input the amount to be withdrawn. Compute for the remaining balance after
the operation (balance = balance - withdrawn)
2. Deposit (method name: deposit)
* Input the amount to be deposited. Compute for the updated balance after
the operation (balance = balance + deposit)
3. Transfer (method name: transfer)
*Input the account number and the amount to be transferred. Compute for the
updated balance after the operation (balance = balance – moneySent)
4. Balance Check (method name: balanceCheck)
* Display the remaining balance.
Sample Input/Output:
Depicted below are sample outputs when the program is executed (the items in bold
characters are input from the user, while the items in bold italic are calculated and
printed by the program):
*Note: The initial balance is 0. The user is given an option to check the balance or not.
The program will run until the exit option is chosen.
Required: The flowchart, the .java file (FamilyName_ATM.java) containing the code and
4 (or more) image files (Sample1, Sample2, Sample3, and Sample4) containing different
sample input/output of the program.
Module 11: Wrapper Classes and Strings
● Wrapper classes are used for converting primitive data types into objects, like int
to Integer.
● When working with Collection Objects, such as ArrayList and Vector, only objects
can be stored and not primitive types.
System.out.println(weight);
System.out.println(day);
System.out.println(initial);
}
or
● The general form for converting a primitive type to a wrapper object is:
WrapperClass objectName = WrapperClass.valueOf(primitiveDataTypeVariable);
or
● Since Java 5, we do not need to use the valueOf() method of wrapper classes to
convert the primitive into objects.
Unboxing
Automatically converting an object of a wrapper class to its corresponding
primitive type.
//using Unboxing
int unboxDay = obj;
● The general form of converting a wrapper object to primitive data type is:
primitiveDataType variableName = objectName.primitiveDataTypeValue();
or
● The following methods are used to get the value associated with the
corresponding wrapper object: intValue(), byteValue(), shortValue(),
longValue(), floatValue(), doubleValue(), charValue(), booleanValue().
● Since Java 5, we do not need to use the intValue() method of wrapper classes to
convert the wrapper type into primitives.
concat() method
● The java string concat() method combines specified string at the end of this
string. It returns combined string. It is like appending another string.
equals() method
● The string equals() method compares the two given strings based on the content of the
string. If any character is not matched, it returns false. If all characters are matched, it
returns true.
equalsIgnoreCase() method
● The string equalsIgnoreCase() method compares the two given strings on the
basis of content of the string irrespective of case of the string. It is like equals()
method but doesn't check case. If any character is not matched, it returns false
otherwise it returns true.
public static void main(String[] args) {
String str1="Hello World";
String str2="Hello World";
String str3="HELLO WORLD";
String str4="hello";
System.out.println(str1.equalsIgnoreCase(str2));
System.out.println(str1.equalsIgnoreCase(str3));
System.out.println(str2.equalsIgnoreCase(str3));
System.out.println(str3.equalsIgnoreCase(str4));
}
compareTo() method
● The string compareTo() method compares the given string with current string
lexicographically. It returns positive number, negative number or 0.
● It compares strings on the basis of Unicode value of each character in the strings.
● If first string is lexicographically greater than second string, it returns positive
number (difference of character value). If first string is less than second string
lexicographically, it returns negative number and if first string is lexicographically
equal to second string, it returns 0.
if string1 > string2, it returns positive number
if string1 < string2, it returns negative number
if string1 == string2, it returns 0
● If you compare string with blank or empty string, it returns length of the string. If second
string is empty, result would be positive. If first string is empty, result would be negative.
For additional information about java’s String methods: watch the following videos
Module 11: Changing a String to Lowercase or Uppercase
Module 11: Obtaining the Length of a String
Module 11: Combining Strings (Concatenation)
Module 11: Determining if Two Strings are Equal
Module 11: Comparing Two Strings
Module 11: Searching a String for a Substring
References:
DataFlair Team. 2018. How to Read Java Console Input | 3 Ways To Read Java Input.
https://data-flair.training/blogs/read-java-console-input/
https://www.sitepoint.com/beginning-java-data-types-variables-and-arrays/
Java Methods. http://www.tutorialspoint.com/java/java_methods.htm
JavatPoint. The Best Portal to Learn Technologies. https://www.javatpoint.com/java-for-loop
just.edu.jo. (n.d.). Windows 7. Retrieved from http://www.just.edu.jo/:
http://www.just.edu.jo/~mqais/CIS99/PDF/Ch.02_Windows7.pdf
Microsoft. (n.d.). Insert a table of contents. Retrieved from Office Support.
Mount Allison University. (n.d.). Microsoft Excel. Retrieved from mta.ca:
https://www.mta.ca/uploadedFiles/Community/Administrative_departments/Human_Resources/
Training_and_professional_development/Classroom/Excel%20Training%20-%20Level%201.pdf
Mwangi, I. (2017). Computer System - Lecture notes. Retrieved from StuDocu:
https://www.studocu.com/my/document/jomo-kenyatta-university-of-agriculture-and-technology
/introduction-to-computer-systems/lecture-notes/computer-system-lecture-notes-12/1992140/vie
w
nursing.ufl.edu. (n.d.). Microsoft Word - APA_Format_2007. Retrieved from
https://nursing.ufl.edu: https://nursing.ufl.edu/files/2011/05/APAFormattingwithWORD2007.pdf
Schmieder, E. (2017, November 18). Tech Tip: Managing academic reference sources in
Microsoft Word. Retrieved from extbook Academic Authors Association Blog:
https://blog.taaonline.net/2017/11/tech-tip-managing-academic-reference-sources-in-microsoft-w
ord/
Sisson, R. (n.d.). Word Basics Class Handout. Retrieved from pagosalibrary.org.
Sumathi, P. (n.d.). Introduction to Computers. Retrieved from http://sdngnet.com/:
http://sdngnet.com/Files/Lectures/UJ-ARC-171-Introduction%20to%20Computing%20in%20Ar
chitecture/Lecture%20Materials/Introduction%20to%20Computer%20Applications%20by%20S
umathi.pdf