SlideShare a Scribd company logo
Improve your App
As you probably have noticed, the code is absolutely
the same in each onClickListener except of the
sign operation between two variables.
The additional challenge in programming is to
decrease complexity and length of the code, and to
make as readable and concise as possible.
Mostly its done by swapping repeatable code with
functions, reusable piece of code.
The following function <calculate>, will:
1. Takes input <sign> (with type String).
2.Takes both calculator's input variables.
3. Through <if statements> defines the sign variable and
calculates result appropriately
4. Prints off result in <answer> TextField
private void calculate(String sign) {
firstVar = Integer.parseInt(firstInput.getText().toString());
secondVar = Integer.parseInt(secondInput.getText().toString());
if (sign == "+") result = firstVar + secondVar;
else if (sign == "-") result = firstVar - secondVar;
else if (sign == "/") result = firstVar / secondVar;
else if (sign == "*") result = firstVar * secondVar;
answer.setText(String.valueOf(result));
}
Now we can remove
previous code inside
onClick method with
function
calculate(<math sign
relatively to the button>)
plus.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
calculate("+");
}
});
minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
calculate("-");
}
});
mult.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
calculate("*");
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
calculate("/");
}
});
Program is shorter but result is the
same.
Thats what we aim for other apps you
are going to make as well.
Now try to fix bug when you make
calculation without assigning
variables yourself.
(hint: use if statements to illuminate null value of the variables)
Program is shorter but result is the
same.
Thats what we aim for other apps you
are going to make as well.
Now try to fix bug when you make
calculation without assigning
variables yourself.
(hint: use if statements to illuminate null value of the variables)

More Related Content

What's hot (20)

C chap02
C chap02C chap02
C chap02
Kamran
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
Effective Java - Always override toString() method
Effective Java - Always override toString() methodEffective Java - Always override toString() method
Effective Java - Always override toString() method
Ferdous Mahmud Shaon
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
fika sweety
 
Pseudocode
PseudocodePseudocode
Pseudocode
grahamwell
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
Jomel Penalba
 
C sharp_basic_ideas
C sharp_basic_ideasC sharp_basic_ideas
C sharp_basic_ideas
Ralph Weber
 
Data annotation validation (ASP.net)
Data annotation validation (ASP.net)Data annotation validation (ASP.net)
Data annotation validation (ASP.net)
Jyotasana Bharti
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
Raghu nath
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
Hock Leng PUAH
 
Bca2030 object oriented programming – c++
Bca2030  object oriented programming – c++Bca2030  object oriented programming – c++
Bca2030 object oriented programming – c++
smumbahelp
 
Unit 7: Built-In Functions
Unit 7: Built-In FunctionsUnit 7: Built-In Functions
Unit 7: Built-In Functions
Matthew Campbell, OCT
 
LISP: Errors In Lisp
LISP: Errors In LispLISP: Errors In Lisp
LISP: Errors In Lisp
DataminingTools Inc
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
fika sweety
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2
Ammara Javed
 
Ge6161 lab manual
Ge6161 lab manualGe6161 lab manual
Ge6161 lab manual
Mani Kandan
 
Basic c# cheat sheet
Basic c# cheat sheetBasic c# cheat sheet
Basic c# cheat sheet
Ahmed Elshal
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesBest Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 
Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
Tabsheer Hasan
 
New features in C# 6
New features in C# 6New features in C# 6
New features in C# 6
Software Associates
 
C chap02
C chap02C chap02
C chap02
Kamran
 
Effective Java - Always override toString() method
Effective Java - Always override toString() methodEffective Java - Always override toString() method
Effective Java - Always override toString() method
Ferdous Mahmud Shaon
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
fika sweety
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
Jomel Penalba
 
C sharp_basic_ideas
C sharp_basic_ideasC sharp_basic_ideas
C sharp_basic_ideas
Ralph Weber
 
Data annotation validation (ASP.net)
Data annotation validation (ASP.net)Data annotation validation (ASP.net)
Data annotation validation (ASP.net)
Jyotasana Bharti
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
Raghu nath
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
Hock Leng PUAH
 
Bca2030 object oriented programming – c++
Bca2030  object oriented programming – c++Bca2030  object oriented programming – c++
Bca2030 object oriented programming – c++
smumbahelp
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
fika sweety
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2
Ammara Javed
 
Ge6161 lab manual
Ge6161 lab manualGe6161 lab manual
Ge6161 lab manual
Mani Kandan
 
Basic c# cheat sheet
Basic c# cheat sheetBasic c# cheat sheet
Basic c# cheat sheet
Ahmed Elshal
 
Best Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing TechniquesBest Techniques To Design Programs - Program Designing Techniques
Best Techniques To Design Programs - Program Designing Techniques
Tech
 

Viewers also liked (20)

Android tutorials7 calculator_intro
Android tutorials7 calculator_introAndroid tutorials7 calculator_intro
Android tutorials7 calculator_intro
Vlad Kolesnyk
 
Help your scrum team strike oil!
Help your scrum team strike oil!Help your scrum team strike oil!
Help your scrum team strike oil!
Michael O'Reilly
 
Android tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirerAndroid tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirer
Vlad Kolesnyk
 
видеоэкскурсия в красный берег(полная)
видеоэкскурсия в красный берег(полная)видеоэкскурсия в красный берег(полная)
видеоэкскурсия в красный берег(полная)
svetopusha
 
ER hypertensive crisis-respiratory distress
ER hypertensive  crisis-respiratory distressER hypertensive  crisis-respiratory distress
ER hypertensive crisis-respiratory distress
Gamal ElDin Soliman
 
Услуги стадиона «Динамо»
Услуги стадиона «Динамо»Услуги стадиона «Динамо»
Услуги стадиона «Динамо»
Andrey Pantiukhov
 
Android tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipseAndroid tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipse
Vlad Kolesnyk
 
Patient safety program scd
Patient safety program scdPatient safety program scd
Patient safety program scd
Gamal ElDin Soliman
 
Imbracaminte copii
Imbracaminte copiiImbracaminte copii
Imbracaminte copii
Hainute copii Johnny Prodcomimpex
 
Ray Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL AppropriateRay Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL Appropriate
Chris Evans
 
Android tutorials1 install_ide
Android tutorials1 install_ideAndroid tutorials1 install_ide
Android tutorials1 install_ide
Vlad Kolesnyk
 
Github tutorial1
Github tutorial1Github tutorial1
Github tutorial1
Vlad Kolesnyk
 
Wasicunwitkotko
WasicunwitkotkoWasicunwitkotko
Wasicunwitkotko
ales fiala
 
Preventing the spread of infection
Preventing the spread of infectionPreventing the spread of infection
Preventing the spread of infection
Gamal ElDin Soliman
 
Construction Risk Management ABC's
Construction Risk Management ABC'sConstruction Risk Management ABC's
Construction Risk Management ABC's
Jerry Whitaker CIC,CRIS
 
Year 2015
Year 2015Year 2015
Year 2015
AddWeb Solution Pvt. Ltd.
 
HAINUTE BOTEZ
HAINUTE BOTEZHAINUTE BOTEZ
HAINUTE BOTEZ
Hainute copii Johnny Prodcomimpex
 
уголовная ответственность
уголовная ответственностьуголовная ответственность
уголовная ответственность
svetopusha
 
электронные физминутки
электронные физминуткиэлектронные физминутки
электронные физминутки
svetopusha
 
Android tutorials7 calculator_intro
Android tutorials7 calculator_introAndroid tutorials7 calculator_intro
Android tutorials7 calculator_intro
Vlad Kolesnyk
 
Help your scrum team strike oil!
Help your scrum team strike oil!Help your scrum team strike oil!
Help your scrum team strike oil!
Michael O'Reilly
 
Android tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirerAndroid tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirer
Vlad Kolesnyk
 
видеоэкскурсия в красный берег(полная)
видеоэкскурсия в красный берег(полная)видеоэкскурсия в красный берег(полная)
видеоэкскурсия в красный берег(полная)
svetopusha
 
ER hypertensive crisis-respiratory distress
ER hypertensive  crisis-respiratory distressER hypertensive  crisis-respiratory distress
ER hypertensive crisis-respiratory distress
Gamal ElDin Soliman
 
Услуги стадиона «Динамо»
Услуги стадиона «Динамо»Услуги стадиона «Динамо»
Услуги стадиона «Динамо»
Andrey Pantiukhov
 
Android tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipseAndroid tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipse
Vlad Kolesnyk
 
Ray Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL AppropriateRay Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL Appropriate
Chris Evans
 
Android tutorials1 install_ide
Android tutorials1 install_ideAndroid tutorials1 install_ide
Android tutorials1 install_ide
Vlad Kolesnyk
 
Wasicunwitkotko
WasicunwitkotkoWasicunwitkotko
Wasicunwitkotko
ales fiala
 
Preventing the spread of infection
Preventing the spread of infectionPreventing the spread of infection
Preventing the spread of infection
Gamal ElDin Soliman
 
уголовная ответственность
уголовная ответственностьуголовная ответственность
уголовная ответственность
svetopusha
 
электронные физминутки
электронные физминуткиэлектронные физминутки
электронные физминутки
svetopusha
 

Similar to Android tutorials7 calulator_improve (20)

Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
Max Kleiner
 
keyword
keywordkeyword
keyword
teach4uin
 
keyword
keywordkeyword
keyword
teach4uin
 
L03vars
L03varsL03vars
L03vars
Ramasamyvelambaal Acadamy
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
HNDE Labuduwa Galle
 
C++ functions
C++ functionsC++ functions
C++ functions
Dawood Jutt
 
C++ functions
C++ functionsC++ functions
C++ functions
Dawood Jutt
 
Python Lecture 2
Python Lecture 2Python Lecture 2
Python Lecture 2
Inzamam Baig
 
C++
C++C++
C++
Prakash Sharma
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
Ch03
Ch03Ch03
Ch03
Arriz San Juan
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
SemsemSameer1
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Andrey Karpov
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
David Halliday
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
David Halliday
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
Aarti P
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
kelleyc3
 
Building blocks 2
Building blocks 2Building blocks 2
Building blocks 2
NAZIRGUJJAR
 
C and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptxC and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptx
renuvprajapati
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
SemsemSameer1
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Andrey Karpov
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
David Halliday
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
David Halliday
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
Aarti P
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
kelleyc3
 
Building blocks 2
Building blocks 2Building blocks 2
Building blocks 2
NAZIRGUJJAR
 
C and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptxC and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptx
renuvprajapati
 

More from Vlad Kolesnyk (8)

Mobile andwebapps
Mobile andwebappsMobile andwebapps
Mobile andwebapps
Vlad Kolesnyk
 
Mech eng presentation
Mech eng presentationMech eng presentation
Mech eng presentation
Vlad Kolesnyk
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
Android tutorials6 run_your_app
Android tutorials6 run_your_appAndroid tutorials6 run_your_app
Android tutorials6 run_your_app
Vlad Kolesnyk
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculator
Vlad Kolesnyk
 
Android tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayoutAndroid tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayout
Vlad Kolesnyk
 
Android tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingAndroid tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogramming
Vlad Kolesnyk
 
Mech eng presentation
Mech eng presentationMech eng presentation
Mech eng presentation
Vlad Kolesnyk
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
Android tutorials6 run_your_app
Android tutorials6 run_your_appAndroid tutorials6 run_your_app
Android tutorials6 run_your_app
Vlad Kolesnyk
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculator
Vlad Kolesnyk
 
Android tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayoutAndroid tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayout
Vlad Kolesnyk
 
Android tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingAndroid tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogramming
Vlad Kolesnyk
 

Recently uploaded (20)

2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 

Android tutorials7 calulator_improve

  • 2. As you probably have noticed, the code is absolutely the same in each onClickListener except of the sign operation between two variables. The additional challenge in programming is to decrease complexity and length of the code, and to make as readable and concise as possible. Mostly its done by swapping repeatable code with functions, reusable piece of code.
  • 3. The following function <calculate>, will: 1. Takes input <sign> (with type String). 2.Takes both calculator's input variables. 3. Through <if statements> defines the sign variable and calculates result appropriately 4. Prints off result in <answer> TextField private void calculate(String sign) { firstVar = Integer.parseInt(firstInput.getText().toString()); secondVar = Integer.parseInt(secondInput.getText().toString()); if (sign == "+") result = firstVar + secondVar; else if (sign == "-") result = firstVar - secondVar; else if (sign == "/") result = firstVar / secondVar; else if (sign == "*") result = firstVar * secondVar; answer.setText(String.valueOf(result)); }
  • 4. Now we can remove previous code inside onClick method with function calculate(<math sign relatively to the button>) plus.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub calculate("+"); } }); minus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub calculate("-"); } }); mult.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub calculate("*"); } }); div.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub calculate("/"); } });
  • 5. Program is shorter but result is the same. Thats what we aim for other apps you are going to make as well. Now try to fix bug when you make calculation without assigning variables yourself. (hint: use if statements to illuminate null value of the variables)
  • 6. Program is shorter but result is the same. Thats what we aim for other apps you are going to make as well. Now try to fix bug when you make calculation without assigning variables yourself. (hint: use if statements to illuminate null value of the variables)