SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
CIS 1403
Fundamentals of
Programming
Lab 1: The process of developing a
computer program
201810
1
This lab aims to develop students knowledge and skills needed to create a simple
programming code. It covers the process of developing computer programs starting
from simple analysis of problem, identify outputs, inputs, and design process/
algorithm, convert algorithm to code, testing, and documentation. The student will
be introduced to the Java program structure, numerical variable and high-level
introduction to data types. The lab does not go into depth explaining the data types
and memory storage. These will be discussed in the upcoming labs. Also, the student
will be introduced to the REPL cloud environment that will be used to create a simple
application.
Introduction
Skill-sets
By completing this lab, the student is expected to develop the following skills:
• Implement the process needed to create a simple computer code
• Identify the required inputs and outputs
• Develop a step by step process in human language explaining the solution. At this
stage, the solution does not include selections, control structure, and advanced
data types or complex arithmetic operation.
• Convert the solution from human language to Java programming language
• Use REPL.it to develop the solution
• Debug the code and fix any errors
• Create and use test data to ensure the program contains no logical errors
• Use appropriate comments to document the code
• Allow the user to enter data using the keyboard
How to use this lab?
To make the best of this lab, it is recommended to follow these steps:
• Watch the associated video (click or scan this QR code)
• Read this lab manual and follow every step
• Complete the last three exercises
• Modify these exercises to create a new solution
• Think of other problem that you can solve using the skills you accommodated in
this course.
2
The Programming Process
Analyzing a Problem Statement
Input Process Output
Developing a solution in plan English language or flow chart
Algorithm
Converting the solution from human language to specific high level
programming language
Coding
Testing
Documentation
When you are presented with a programming challenge, the first step that you need to take is to
analyze by asking three main questions.
• What are the required outputs? You should start by thinking about the outputs.
Understanding the required output will help to find what data you need and what is the
necessary process to solve the problem.
• The next step is answering this questions. What are the required data or in other words
what are the needed inputs to solve this problem?
• The next question what are the steps required to solve this challenge? If you can not write
the steps needed to solve a problem in plain human language, you will not be able to develop
a programming code to solve the same problem. The computer program will only automate
the solution that you designed.
Once you have the solutions in plain English, you need to start translating to a high-level
computer language using specific keywords/syntax.
The next step is to perform various tests to ensure the programming is producing the correct
solution. The simplest way to test your code is by entering different inputs and compare the
results with expected outputs. You have to make sure you cover all different possible scenarios.
The last step is to document your solution to help other developers to improve it. You also
required to write comments inside your code to improve its readability. Depending on the scale
of your program, You may need to create a user manual to guide users on how to use your
program.
3
Example 1:
Develop a computer program that calculates and displays the VAT, the total cost including
VAT withoriginal pricepurchased by a customer.
Original price: 1000
VAT: 50
Total: 1050
We need to know the original price. Let us call it original, which represent the total price of
all items.
The rate of VAT. In UAE VAT rate is 5%.
What are the steps required to solve this problem?
Here, you write the solution using plan human language. We will use English, but you can use
any language.
Before writing the steps, let us assume that you purchased items with original cost 1000 and
the VAT rate is 5%. What is the total cost including VAT? If you can calculate this, then you can
write the steps/solution.
The calculation is as follows:
VAT = original * 5/100 VAT = 1000 * 5/100 = 50
Total = original + VAT Total = 1000 + 50 = 1050
The step/solution to solve this problem are:
• Give/assign a value to the original price. We will give it the name original
• Calculate VAT as: VAT = original * 5/100
• Calculate Total as: Total = original + VAT
• Print original
• Print VAT
• Print Total
1. Problem statement:
We need to answer this question.
We need to detemine the output which is usally display on the screen, store in a file, print on paper. In the
given problem the output is to display the original amount, VAT amount, and totalcost. The output will look
like this:
2. Analysis:
2.2 What are the inputs required for this solution?
3. Algorithm:
4
2.1 What outputs are produced by the program?
4. Coding:
In this step, we need to translate the solution from human language to high-level computer
language. We will use Java. Here you find the solution in human language to the left in Java
code to the right:
3. Give/assign a value to the original price: original
4. Calculate VAT as: VAT = original * 5/100
5. Calculate Total as: Total = original + VAT
6. Print original
7. Print VAT
8. Print Total
For now, focus on lines 3 to 8. We will explain the rest later.
The line ” Give/assign a value to the original price: original”, which is written in the human
language is translated to line 3 in java:
The variable “original” is used to store the price of the purchased items. Variables are the
same as what you use in Math (,x, y, z, etc.). They are used to represent a value. Nothing is
new here. The variable name cannot start by a number or special character. But, what is
the word float?
In the most high-level programming language such as C/C++, C+, and Java, you need to
specify/declare the data type of every variable. For now, look at float as any number that
has a decimal point. The best data type for the price is a float. The data type float allows 7
decimal digits. So you can store a number such as 1.3333333. There is another similar data
type called double, which can store up to 16 decimal digits. With the price of items, you
need only two decimal digits. Therefore, the float is enough. We will discuss data types in
details in the next unit. For now, you need to know that the variable original is used to store
the original price as a float.
It is important that each line in Java end by a semicolon except the lines that start by if, else,
for, while, or a declaration of a function. We will discuss them later in this course.
Line 4: calculates VAT as follows:
Again, VAT is declared as float. To calculated VAT value, you need to multiple the original
price with 5/100.
Line 5: calculates the total by multiplying original with VAT.
Line 6 to 8 display the results.
To display data on the computer screen/console you need to use the line:
Text to be
displayed on
the screen.
+
sign
Variable
to be
displayed 5
It is important to note that Java is a case-sensitive language. That means Total with T
Uppercase is entirely different from total with t lowercase.
What is about the rest of the code (line 1 to 2 and 9 to 10)?
Start of
the class
End of
the class
Start of the
function
End of the
function
Every program in Java should start by the word class. Later in your study program, you will
study object-oriented programming, where classes are discussed in details. At this stage,
you can look at the class as a container that includes your codes. Of course, you can have
multiple classes in your program, and you can build a relationship between two or more
classes. For now, your code should start by the word class in lower case, followed by a
space, then a name. In this example, we are using the class name Main with M uppercase.
If you change it to be with m lowercase, then you need to change the file name to main.java
with m lower case. The rule is that class name and file name must match each other.
After the class name you need to use an open brace type of bracket. {
The file should end by closed brace. } See line 10.
Line 2: The main class of your Java program must have a function. A function is a group
of one and more line of code. All lines of code in a function can be executed or called
using one name. Your main Java class must have this main function:
6
The main function:
The main function in Java should meet the following conditions
1. Start by the word public. A public function can be called from everywhere in
your code.
2. The second keyword is static. A static function can be called without the
need to create a copy (object) of your class.
3. The third keyword is void. It means this function will not return a value. We
will discuss this in more details when we get to functions.
4. The name of the function must be main with m lowercase.
5. The name of the function should be followed by (String[] args)
6. You may replace args with another variable if needed.
7. The line must end with an opened brace { type of bracket.
8. One blank space is required between the keywords.
Space
Line 9 closes the main function.
Start of
the class
End of
the class
Start of the
function
End of the
function
7
Using REPL.it
You may be asking this question. What software do I need to install on my computer to
start programming in Java?
The simplest method to programming in Java without the need to install Java
Development Kits (JDKs) on your computer is to use REPL.it cloud solution. You need to
register at
https://repl.it/classroom/invite/YO4IQaw
Please make sure that you use a correct email address. You will receive an email with a
link to confirm your registration. After you confirm your registration, you need to revisit
this address, again https://repl.it/classroom/invite/YO4IQaw
You will be asked to update your profile by entering your first, last email, and university.
Then, you will get a window that looks like this.
1. Here you will
find future
course
assignments.
2. By click here
you can start
writing a
program
Click on “My repls” menu to create a new program. As this is may be your first time
building a program, you have an empty window. Click on
Type Java in the provided text box, then select Java from the list.
Click on this line.
8
Components of REPL Development Environment
REPL.it is a cloud based development environment. You can develop and test your
programs online. The following image illustrates the key components of REPL.
Files window. All
your files will be
listed here.
The codes of the
opened file will
appear here.
The inputs and
outputs of your code
will appear here
Click run
to run the
code
To add a
new file
To
rename
the file
To view previous
versions of your
code
We may refer to this
windows as
“terminal”
Completing your code:
Type the following code inside the main function.
To avoid having many errors in your code, please make sure you follow these rules:
• Most lines should end by a semicolon ;. The compiler will tell you which line is
missing a semicolon.
• Make sure you use the same name of the variable with the same case in all your
code. In Java, VAT is different from Vat or vat.
• Make sure you have no space in the variable name. For example original price is
not allowed, but original_price or originalprice are allowed.
• Make sure to close all open brackets. The number of opened brackets should
match number of closed brackets.
• The key word float is in lowercase
9
Completing your code:
You need first to run your code to ensure it contains no errors. Click the icon
If there are no errors, your program will produce these results in the terminal window.
The following image illustrates where these results are coming from.
To change the original price and recalculate the VAT and total, you need only to change the
value in line 3. for example, you make it, float original = 2000;
Debugging
In programming debugging is a term that used to fix errors in a computer code.
Let us make some syntax errors (typo errors) and see how Java compiler will
present these errors to us. We will start by deleting the semicolon in line 3.
The error
saying ; is
expected.
10
We will fix the ; and create another error in line 5.
Instead of VAT we will use vat. Remember Java is case sensitive. VAT is different from
the vat. In the previous line (4) we declared VAT and not vat. While compiling the line 5
the compiler will not find a value or data type for the variable vat and will produce this
error.
The error is saying “error: cannot find symbol.” When you get such error, check the
variable name and make sure you are calling it using the correct case that you used to
declare it.
We can fix this in two way:
• The first option is to change the vat in line 5 to VAT. This will match how you declared
in line 4.
• The second option is to change VAT in line 4 to vat. In this case, you also need to change line 7
to have vat instead of the VAT.
The first option is preferred as it does not require changing other lines of code.
Let us now delete one bracket. In line 8, we will change this line
to We simply remove the closing bracket ) which is located before
the semicolon. Here is the error that will be generated.
You can fix this simple error by adding the required bracket and run the code.
11
The error is very clear. I think you have noticed that Java compiler produces clear error
messages, which easy to find and fix mistakes. However, the following error will
generate a misleading message.
Assume we removed + from line 8.
The generated error did not mention the + sign. But, it refers to a missing bracket.
When you are dealing with System.out.println, then you may check the missing + sign.
Please note that Java uses + in the println function. If you have experience with
programming in other languages, you may notice that some use comma or period.
Debugging logical errors:
All the above errors are syntax errors. There are resulted from making typo mistakes
while typing the code. Examples, wrong spelling of variable, function, or data types.
Also, possible missing a semicolon, bracket, or other signs.
The Java compiler will find these errors.
However, if you make a logical error while the syntax is correct, the compiler will not
be able to find such error. A simple example of a logical error is making a wrong
calculation. Other errors are related to using wrong conditions in your if statement.
We will discuss if statement later in the course.
Let us make a wrong VAT calculation in line 4.
We will write it without dividing by 100 as
Running this code will generate no errors, but the results will be wrong.
The VAT value is
more than the
original price!
12
Debugging the logical errors require using a test data with correct results. The
accurate results are usually obtained from a manual calculation. You need to run your
program, enter the data, and check the result against the expected correct result. You
test data should cover all possible scenarios.
Documentation
Now you have tested your program and found it working well. It is time to document
your code.
Comments:
The first type of documentation should be done while you are writing the code. We
did not explain from the beginning to avoid distracting you from the primary process.
This type of documentation is called comments. Comments are added to the actual
code to improve its readability. So, when someone else or yourself read the code, it
will be easy to understand its logic and the reason why it is written this way.
Java compiler ignores the comment lines when checking for errors.
There are two types of comments.
• Single line comment. Single line comments start by //. It allows the programmer
to write a short explanation of one line of code
• A Multi line (paragraph type of) comment. It begins with/* and ends by */. This type of
comments is usually added at the beginning of the code or functions.
Let us add single and multiple line of comments to our code.
Line 1 to 6: Multiple lines comments to explain the problem that this program is
attempting to solve.
Line 9: A single comment clarifying that the original variable store the total of all
purchase items without VAT
Line 11: A single line comment to explain the purpose of VAT variable
Line 13: A single line comment to inform the reader that the reaming lines will
display the results.
Start of
multiple lines
comments
End of
multiple lines
comments
13
Other Documentations
For large programs, you required to produce documents that covers, analysis, design,
coding, testing, limitations of the solution, suggested future development, and user
manual that explains how to use the program.
Accepting user inputs
One limitation of our current program is that it always calculates VAT for an
original fixed price. Every time when we need to change the value of the variable
original we need to change the code. This is not an ideal solution. We need to
be able to change the value of the original variable during the runtime.
To this, we need to use an addition Java package, which is java.util.Scanner. A package
is a collection of code to perform a specific task. The Scanner package allows the user
to enter data through the keyboard. In Java to use an additional package, you need
to use the keyword imports at the beginning of your code. Now, line 1 will be:
When you import any package, you need to create an object, which will perform the
required task for you. The object becomes the representative of the package. Line 11
will create the object and give it the name scan.
This line will be used in almost every program that you are going to write from now
and on.
The next thing that we need to do is to tell the user that he/she needs to enter a value
for the original price. In this case, we will use System.out.println to display the
message. See line 13.
Now, we need to change the line float original = 1000; to
When the above line is executed, the user will be able to enter a value for the original
price. The rest of the code will stay with no changes.
14
When you run this code, you will be prompted to enter the total of the purchased item
then hit enter as follows:
The results will be:
Lab activities
Exercises 1:
Develop a Java program that prompt the user to enter three numbers,
calculates and display the total and the average of the three numbers.
The Outputs:
Give an example of what out is required.
The Inputs:
What are required inputs and their data types?
The Process:
Write a step by step solution using plan English language
15
Coding:
Convert your solution into Java programming code using REPL.it
Debugging:
What errors did you find in your code and how did you solve them?
Testing:
What data did you use to test your code and explain the results?
16
Lab activities
Exercises 2:
Develop a Java program that prompt the user to enter the price of a car and the
car insurance rate, then calculates and display the cost of insurance.
The Outputs:
Give an example of what out is required.
The Inputs:
What are required inputs and their data types?
The Process:
Write a step by step solution using plan English language
17
Coding:
Convert your solution into Java programming code using REPL.it
Debugging:
What errors did you find in your code and how did you solve them?
Testing:
What data did you use to test your code and explain the results?
18
Lab activities
Exercises 3:
Develop a Java program that allows the user to enter the name of the
students and his/her marks for three assessments, then calculate and display
the total scores in the course.
The Outputs:
Give an example of what out is required.
The Inputs:
What are required inputs and their data types?
The Process:
Write a step by step solution using plan English language
19
Coding:
Convert your solution into Java programming code using REPL.it. To allow entering the
student name, you need to use the line
Debugging:
What errors did you find in your code and how did you solve them?
Testing:
What data did you use to test your code and explain the results?
20

Mais conteúdo relacionado

Mais procurados

AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2Dan D'Urso
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1guest38bf
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction TechniquesKelly Bauer
 
Solutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchSolutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchAlbern9271
 
What is programming what are its benefits
What is programming  what are its benefits What is programming  what are its benefits
What is programming what are its benefits Vijay Singh Khatri
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answersAdenKheire
 
9781439035665 ppt ch07_passing_primitivetypeasobjects
9781439035665 ppt ch07_passing_primitivetypeasobjects9781439035665 ppt ch07_passing_primitivetypeasobjects
9781439035665 ppt ch07_passing_primitivetypeasobjectsTerry Yoast
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using JavaMahmoud Alfarra
 
Commenting Best Practices
Commenting Best PracticesCommenting Best Practices
Commenting Best Practicesmh_azad
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011Mahmoud Alfarra
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptOsama Ghandour Geris
 

Mais procurados (18)

AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
The OptimJ Manual
The OptimJ ManualThe OptimJ Manual
The OptimJ Manual
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
 
Solutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchSolutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitch
 
How c/c++ works
How c/c++ worksHow c/c++ works
How c/c++ works
 
What is programming what are its benefits
What is programming  what are its benefits What is programming  what are its benefits
What is programming what are its benefits
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
 
9781439035665 ppt ch07_passing_primitivetypeasobjects
9781439035665 ppt ch07_passing_primitivetypeasobjects9781439035665 ppt ch07_passing_primitivetypeasobjects
9781439035665 ppt ch07_passing_primitivetypeasobjects
 
ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using Java
 
Commenting Best Practices
Commenting Best PracticesCommenting Best Practices
Commenting Best Practices
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
 
java token
java tokenjava token
java token
 
Quiz5
Quiz5Quiz5
Quiz5
 

Semelhante a Cis 1403 lab1- the process of programming

classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxssusere336f4
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGERathnaM16
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbookHARUN PEHLIVAN
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 
Javascript breakdown-workbook
Javascript breakdown-workbookJavascript breakdown-workbook
Javascript breakdown-workbookHARUN PEHLIVAN
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
Basics of Programming - A Review Guide
Basics of Programming - A Review GuideBasics of Programming - A Review Guide
Basics of Programming - A Review GuideBenjamin Kissinger
 
Car removal gold coast
Car removal gold coastCar removal gold coast
Car removal gold coastanaferral
 
Programming of c++
Programming of c++Programming of c++
Programming of c++Ateeq Sindhu
 
Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...
Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...
Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...Lucky Gods
 
Final requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary ClemenceFinal requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary Clemenceclemencebonifacio
 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answersvithyanila
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
Software Design
Software DesignSoftware Design
Software DesignSpy Seat
 
Algorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfMaryJacob24
 
10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechzShahbaz Ahmad
 

Semelhante a Cis 1403 lab1- the process of programming (20)

classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbook
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
Javascript breakdown-workbook
Javascript breakdown-workbookJavascript breakdown-workbook
Javascript breakdown-workbook
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Basics of Programming - A Review Guide
Basics of Programming - A Review GuideBasics of Programming - A Review Guide
Basics of Programming - A Review Guide
 
Car removal gold coast
Car removal gold coastCar removal gold coast
Car removal gold coast
 
Programming of c++
Programming of c++Programming of c++
Programming of c++
 
Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...
Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...
Mastering Python : 100+ Solved and Commented Exercises to Accelerate Your Lea...
 
Final requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary ClemenceFinal requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary Clemence
 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answers
 
01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx01 Programming Fundamentals.pptx
01 Programming Fundamentals.pptx
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Software Design
Software DesignSoftware Design
Software Design
 
Algorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdf
 
10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz
 

Último

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Cis 1403 lab1- the process of programming

  • 1. CIS 1403 Fundamentals of Programming Lab 1: The process of developing a computer program 201810 1
  • 2. This lab aims to develop students knowledge and skills needed to create a simple programming code. It covers the process of developing computer programs starting from simple analysis of problem, identify outputs, inputs, and design process/ algorithm, convert algorithm to code, testing, and documentation. The student will be introduced to the Java program structure, numerical variable and high-level introduction to data types. The lab does not go into depth explaining the data types and memory storage. These will be discussed in the upcoming labs. Also, the student will be introduced to the REPL cloud environment that will be used to create a simple application. Introduction Skill-sets By completing this lab, the student is expected to develop the following skills: • Implement the process needed to create a simple computer code • Identify the required inputs and outputs • Develop a step by step process in human language explaining the solution. At this stage, the solution does not include selections, control structure, and advanced data types or complex arithmetic operation. • Convert the solution from human language to Java programming language • Use REPL.it to develop the solution • Debug the code and fix any errors • Create and use test data to ensure the program contains no logical errors • Use appropriate comments to document the code • Allow the user to enter data using the keyboard How to use this lab? To make the best of this lab, it is recommended to follow these steps: • Watch the associated video (click or scan this QR code) • Read this lab manual and follow every step • Complete the last three exercises • Modify these exercises to create a new solution • Think of other problem that you can solve using the skills you accommodated in this course. 2
  • 3. The Programming Process Analyzing a Problem Statement Input Process Output Developing a solution in plan English language or flow chart Algorithm Converting the solution from human language to specific high level programming language Coding Testing Documentation When you are presented with a programming challenge, the first step that you need to take is to analyze by asking three main questions. • What are the required outputs? You should start by thinking about the outputs. Understanding the required output will help to find what data you need and what is the necessary process to solve the problem. • The next step is answering this questions. What are the required data or in other words what are the needed inputs to solve this problem? • The next question what are the steps required to solve this challenge? If you can not write the steps needed to solve a problem in plain human language, you will not be able to develop a programming code to solve the same problem. The computer program will only automate the solution that you designed. Once you have the solutions in plain English, you need to start translating to a high-level computer language using specific keywords/syntax. The next step is to perform various tests to ensure the programming is producing the correct solution. The simplest way to test your code is by entering different inputs and compare the results with expected outputs. You have to make sure you cover all different possible scenarios. The last step is to document your solution to help other developers to improve it. You also required to write comments inside your code to improve its readability. Depending on the scale of your program, You may need to create a user manual to guide users on how to use your program. 3
  • 4. Example 1: Develop a computer program that calculates and displays the VAT, the total cost including VAT withoriginal pricepurchased by a customer. Original price: 1000 VAT: 50 Total: 1050 We need to know the original price. Let us call it original, which represent the total price of all items. The rate of VAT. In UAE VAT rate is 5%. What are the steps required to solve this problem? Here, you write the solution using plan human language. We will use English, but you can use any language. Before writing the steps, let us assume that you purchased items with original cost 1000 and the VAT rate is 5%. What is the total cost including VAT? If you can calculate this, then you can write the steps/solution. The calculation is as follows: VAT = original * 5/100 VAT = 1000 * 5/100 = 50 Total = original + VAT Total = 1000 + 50 = 1050 The step/solution to solve this problem are: • Give/assign a value to the original price. We will give it the name original • Calculate VAT as: VAT = original * 5/100 • Calculate Total as: Total = original + VAT • Print original • Print VAT • Print Total 1. Problem statement: We need to answer this question. We need to detemine the output which is usally display on the screen, store in a file, print on paper. In the given problem the output is to display the original amount, VAT amount, and totalcost. The output will look like this: 2. Analysis: 2.2 What are the inputs required for this solution? 3. Algorithm: 4 2.1 What outputs are produced by the program?
  • 5. 4. Coding: In this step, we need to translate the solution from human language to high-level computer language. We will use Java. Here you find the solution in human language to the left in Java code to the right: 3. Give/assign a value to the original price: original 4. Calculate VAT as: VAT = original * 5/100 5. Calculate Total as: Total = original + VAT 6. Print original 7. Print VAT 8. Print Total For now, focus on lines 3 to 8. We will explain the rest later. The line ” Give/assign a value to the original price: original”, which is written in the human language is translated to line 3 in java: The variable “original” is used to store the price of the purchased items. Variables are the same as what you use in Math (,x, y, z, etc.). They are used to represent a value. Nothing is new here. The variable name cannot start by a number or special character. But, what is the word float? In the most high-level programming language such as C/C++, C+, and Java, you need to specify/declare the data type of every variable. For now, look at float as any number that has a decimal point. The best data type for the price is a float. The data type float allows 7 decimal digits. So you can store a number such as 1.3333333. There is another similar data type called double, which can store up to 16 decimal digits. With the price of items, you need only two decimal digits. Therefore, the float is enough. We will discuss data types in details in the next unit. For now, you need to know that the variable original is used to store the original price as a float. It is important that each line in Java end by a semicolon except the lines that start by if, else, for, while, or a declaration of a function. We will discuss them later in this course. Line 4: calculates VAT as follows: Again, VAT is declared as float. To calculated VAT value, you need to multiple the original price with 5/100. Line 5: calculates the total by multiplying original with VAT. Line 6 to 8 display the results. To display data on the computer screen/console you need to use the line: Text to be displayed on the screen. + sign Variable to be displayed 5
  • 6. It is important to note that Java is a case-sensitive language. That means Total with T Uppercase is entirely different from total with t lowercase. What is about the rest of the code (line 1 to 2 and 9 to 10)? Start of the class End of the class Start of the function End of the function Every program in Java should start by the word class. Later in your study program, you will study object-oriented programming, where classes are discussed in details. At this stage, you can look at the class as a container that includes your codes. Of course, you can have multiple classes in your program, and you can build a relationship between two or more classes. For now, your code should start by the word class in lower case, followed by a space, then a name. In this example, we are using the class name Main with M uppercase. If you change it to be with m lowercase, then you need to change the file name to main.java with m lower case. The rule is that class name and file name must match each other. After the class name you need to use an open brace type of bracket. { The file should end by closed brace. } See line 10. Line 2: The main class of your Java program must have a function. A function is a group of one and more line of code. All lines of code in a function can be executed or called using one name. Your main Java class must have this main function: 6
  • 7. The main function: The main function in Java should meet the following conditions 1. Start by the word public. A public function can be called from everywhere in your code. 2. The second keyword is static. A static function can be called without the need to create a copy (object) of your class. 3. The third keyword is void. It means this function will not return a value. We will discuss this in more details when we get to functions. 4. The name of the function must be main with m lowercase. 5. The name of the function should be followed by (String[] args) 6. You may replace args with another variable if needed. 7. The line must end with an opened brace { type of bracket. 8. One blank space is required between the keywords. Space Line 9 closes the main function. Start of the class End of the class Start of the function End of the function 7
  • 8. Using REPL.it You may be asking this question. What software do I need to install on my computer to start programming in Java? The simplest method to programming in Java without the need to install Java Development Kits (JDKs) on your computer is to use REPL.it cloud solution. You need to register at https://repl.it/classroom/invite/YO4IQaw Please make sure that you use a correct email address. You will receive an email with a link to confirm your registration. After you confirm your registration, you need to revisit this address, again https://repl.it/classroom/invite/YO4IQaw You will be asked to update your profile by entering your first, last email, and university. Then, you will get a window that looks like this. 1. Here you will find future course assignments. 2. By click here you can start writing a program Click on “My repls” menu to create a new program. As this is may be your first time building a program, you have an empty window. Click on Type Java in the provided text box, then select Java from the list. Click on this line. 8
  • 9. Components of REPL Development Environment REPL.it is a cloud based development environment. You can develop and test your programs online. The following image illustrates the key components of REPL. Files window. All your files will be listed here. The codes of the opened file will appear here. The inputs and outputs of your code will appear here Click run to run the code To add a new file To rename the file To view previous versions of your code We may refer to this windows as “terminal” Completing your code: Type the following code inside the main function. To avoid having many errors in your code, please make sure you follow these rules: • Most lines should end by a semicolon ;. The compiler will tell you which line is missing a semicolon. • Make sure you use the same name of the variable with the same case in all your code. In Java, VAT is different from Vat or vat. • Make sure you have no space in the variable name. For example original price is not allowed, but original_price or originalprice are allowed. • Make sure to close all open brackets. The number of opened brackets should match number of closed brackets. • The key word float is in lowercase 9
  • 10. Completing your code: You need first to run your code to ensure it contains no errors. Click the icon If there are no errors, your program will produce these results in the terminal window. The following image illustrates where these results are coming from. To change the original price and recalculate the VAT and total, you need only to change the value in line 3. for example, you make it, float original = 2000; Debugging In programming debugging is a term that used to fix errors in a computer code. Let us make some syntax errors (typo errors) and see how Java compiler will present these errors to us. We will start by deleting the semicolon in line 3. The error saying ; is expected. 10
  • 11. We will fix the ; and create another error in line 5. Instead of VAT we will use vat. Remember Java is case sensitive. VAT is different from the vat. In the previous line (4) we declared VAT and not vat. While compiling the line 5 the compiler will not find a value or data type for the variable vat and will produce this error. The error is saying “error: cannot find symbol.” When you get such error, check the variable name and make sure you are calling it using the correct case that you used to declare it. We can fix this in two way: • The first option is to change the vat in line 5 to VAT. This will match how you declared in line 4. • The second option is to change VAT in line 4 to vat. In this case, you also need to change line 7 to have vat instead of the VAT. The first option is preferred as it does not require changing other lines of code. Let us now delete one bracket. In line 8, we will change this line to We simply remove the closing bracket ) which is located before the semicolon. Here is the error that will be generated. You can fix this simple error by adding the required bracket and run the code. 11
  • 12. The error is very clear. I think you have noticed that Java compiler produces clear error messages, which easy to find and fix mistakes. However, the following error will generate a misleading message. Assume we removed + from line 8. The generated error did not mention the + sign. But, it refers to a missing bracket. When you are dealing with System.out.println, then you may check the missing + sign. Please note that Java uses + in the println function. If you have experience with programming in other languages, you may notice that some use comma or period. Debugging logical errors: All the above errors are syntax errors. There are resulted from making typo mistakes while typing the code. Examples, wrong spelling of variable, function, or data types. Also, possible missing a semicolon, bracket, or other signs. The Java compiler will find these errors. However, if you make a logical error while the syntax is correct, the compiler will not be able to find such error. A simple example of a logical error is making a wrong calculation. Other errors are related to using wrong conditions in your if statement. We will discuss if statement later in the course. Let us make a wrong VAT calculation in line 4. We will write it without dividing by 100 as Running this code will generate no errors, but the results will be wrong. The VAT value is more than the original price! 12
  • 13. Debugging the logical errors require using a test data with correct results. The accurate results are usually obtained from a manual calculation. You need to run your program, enter the data, and check the result against the expected correct result. You test data should cover all possible scenarios. Documentation Now you have tested your program and found it working well. It is time to document your code. Comments: The first type of documentation should be done while you are writing the code. We did not explain from the beginning to avoid distracting you from the primary process. This type of documentation is called comments. Comments are added to the actual code to improve its readability. So, when someone else or yourself read the code, it will be easy to understand its logic and the reason why it is written this way. Java compiler ignores the comment lines when checking for errors. There are two types of comments. • Single line comment. Single line comments start by //. It allows the programmer to write a short explanation of one line of code • A Multi line (paragraph type of) comment. It begins with/* and ends by */. This type of comments is usually added at the beginning of the code or functions. Let us add single and multiple line of comments to our code. Line 1 to 6: Multiple lines comments to explain the problem that this program is attempting to solve. Line 9: A single comment clarifying that the original variable store the total of all purchase items without VAT Line 11: A single line comment to explain the purpose of VAT variable Line 13: A single line comment to inform the reader that the reaming lines will display the results. Start of multiple lines comments End of multiple lines comments 13
  • 14. Other Documentations For large programs, you required to produce documents that covers, analysis, design, coding, testing, limitations of the solution, suggested future development, and user manual that explains how to use the program. Accepting user inputs One limitation of our current program is that it always calculates VAT for an original fixed price. Every time when we need to change the value of the variable original we need to change the code. This is not an ideal solution. We need to be able to change the value of the original variable during the runtime. To this, we need to use an addition Java package, which is java.util.Scanner. A package is a collection of code to perform a specific task. The Scanner package allows the user to enter data through the keyboard. In Java to use an additional package, you need to use the keyword imports at the beginning of your code. Now, line 1 will be: When you import any package, you need to create an object, which will perform the required task for you. The object becomes the representative of the package. Line 11 will create the object and give it the name scan. This line will be used in almost every program that you are going to write from now and on. The next thing that we need to do is to tell the user that he/she needs to enter a value for the original price. In this case, we will use System.out.println to display the message. See line 13. Now, we need to change the line float original = 1000; to When the above line is executed, the user will be able to enter a value for the original price. The rest of the code will stay with no changes. 14
  • 15. When you run this code, you will be prompted to enter the total of the purchased item then hit enter as follows: The results will be: Lab activities Exercises 1: Develop a Java program that prompt the user to enter three numbers, calculates and display the total and the average of the three numbers. The Outputs: Give an example of what out is required. The Inputs: What are required inputs and their data types? The Process: Write a step by step solution using plan English language 15
  • 16. Coding: Convert your solution into Java programming code using REPL.it Debugging: What errors did you find in your code and how did you solve them? Testing: What data did you use to test your code and explain the results? 16
  • 17. Lab activities Exercises 2: Develop a Java program that prompt the user to enter the price of a car and the car insurance rate, then calculates and display the cost of insurance. The Outputs: Give an example of what out is required. The Inputs: What are required inputs and their data types? The Process: Write a step by step solution using plan English language 17
  • 18. Coding: Convert your solution into Java programming code using REPL.it Debugging: What errors did you find in your code and how did you solve them? Testing: What data did you use to test your code and explain the results? 18
  • 19. Lab activities Exercises 3: Develop a Java program that allows the user to enter the name of the students and his/her marks for three assessments, then calculate and display the total scores in the course. The Outputs: Give an example of what out is required. The Inputs: What are required inputs and their data types? The Process: Write a step by step solution using plan English language 19
  • 20. Coding: Convert your solution into Java programming code using REPL.it. To allow entering the student name, you need to use the line Debugging: What errors did you find in your code and how did you solve them? Testing: What data did you use to test your code and explain the results? 20