SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
https://www.facebook.com/Oxus20

CONTENTS
Problem Statement .................................................... 3
Solution ............................................................. 3
Code Explanation ..................................................... 5
Package and Import ................................................. 5
Class .............................................................. 6
Method MAIN ........................................................ 6
Array .............................................................. 6
Loop ............................................................... 7
Calendar.DAY_OF_YEAR ............................................... 8
Conclusion ........................................................... 9

Page 1 of 9
https://www.facebook.com/Oxus20

RECOMMENDATION AND GUIDANCE
Programming is fun and easy if and only if you concentrate and
consider the Problem Solving process which consists of a sequence of
sections that fit together depending on the type of problem to be
solved. These are:


Understand the problem



Generating possible solutions



Refine the Solutions and select the best solution(s).



Implement and code the best selected solution



Test the code

The process is only a guide for problem solving. It is useful to have
a structure to follow to make sure that nothing is overlooked and
ignored.
Abdul Rahman Sherzad

Special Thanks goes to Nooria Esmaelzadeh for her support taking
minute of the session and drafting the idea together

Page 2 of 9
https://www.facebook.com/Oxus20

PROBLEM STATEMENT

Write a program to display a different quote each day of the year as
the quote of the day. The program should pick a random quote from an
array of quotes you provide based on day of the year; and it must show
that same picked and selected quote for the whole day and change to a
new one the next day.
NOTE: Remember and keep in mind the already picked and selected quotes
should not pick again until the next year.

SOLUTION

Do you think it is simple or complex?

REMEMBER "Every problem has a

solution, Tom Hanks" 
To be honest it is quite easy and simple. Followings ingredients are
required solving the problem efficiently:


Array: An array is needed to store the quotes



Loop: Using loop can help initialize the dummy quotes for the
demonstration and testing purpose inside the array.



Calenday.DAY_OF_YEAR: The constant DAY_OF_YEAR of the class
Calendar returns day of year ranges from 1 to 365 (366 for the
leap years).

Page 3 of 9
https://www.facebook.com/Oxus20

Following is the complete code of the "Quote of the Day" java
application program:
/*
* Copyright (c) 2013, OXUS20 and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*/
import java.util.Calendar;
/**
* Display Quote Of The Day
* This class picks a quote from an array of quotes based on day of the year.
*/
public class QuoteOfTheDay {
public static void main(String[] args) {
// Array quotes[] to store the quotes
String quotes[] = new String[366];
// Loop initialize dummy quotes inside array quotes[]
for (int i = 0; i < quotes.length; i++) {
quotes[i] = "Dummy quote of the day " + (i + 1);
}
// Construct Calendar object "c"
Calendar c = Calendar.getInstance();
// quote_index represent day of the year
int quote_index = c.get(Calendar.DAY_OF_YEAR);
// quotes[quote_index] returns day of the year quote
String quote_of_the_day = quotes[quote_index];
// Display the code the screen
System.out.println(quote_of_the_day);
}
}

Page 4 of 9
https://www.facebook.com/Oxus20

CODE EXPLANATION

Let's break down the above code of "Quote of the Day" application
program into pieces for the purpose of explanation as follow:
PACKAGE AND IMPORT

Package = directory: Java classes can be grouped together in packages.
A package name is the same as the directory (folder) name which
contains the .java files.
To import classes into the current file, put an import statement at
the beginning of the file before any type definitions but after
the package statement, if there is one. Here's how you would import
the Calendar class from the java.util package.
import java.util.Calendar;

From now on you can refer to the Calendar class by its simple name as
follow:
Calendar c = Calendar.getInstance();

Otherwise if you did not import the Calendar class you had to use
following method in order to access the Calendar class:
java.util.Calendar c = java.util.Calendar.getInstance();

Page 5 of 9
https://www.facebook.com/Oxus20

CLASS

Java class is nothing but a template for object you are going to
create or it is a blueprint. When we create class in java the first
step is keyword class and then name of the class or identifier we can
say i.e. "QuoteOfTheDay".
public class QuoteOfTheDay {

}

The curly braces symbols demonstrates the class body { }; and between
this all things related to the class i.e. property and method will
come here.
METHOD MAIN

In Java, you need to have a method named main () in at least one
class. The following is what must appear in a real Java program.
public static void main(String[] args) {

}

In the Java language, when you execute a class with the Java
interpreter, the runtime system starts by calling the class's main
() method. The main () method then calls all the other methods
required to run your application.

ARRAY

An array is a container object
that holds a fixed number of
values of a single type. Array
length is fixed after creation.

Page 6 of 9
https://www.facebook.com/Oxus20

In simple words it is a programming construct which helps replacing
following:
String
String
String
String

quote1
quote2
quote3
quote4

=
=
=
=

"Dummy
"Dummy
"Dummy
"Dummy

quote
quote
quote
quote

of
of
of
of

the
the
the
the

day
day
day
day

1";
2";
3";
4";

String quote5 = "Dummy quote of the day 5";

With following:
String quotes[] = new String[366];
quotes[0] = "Dummy quote of the day
quotes[1] = "Dummy quote of the day
quotes[2] = "Dummy quote of the day
quotes[3] = "Dummy quote of the day

1";
2";
3";
4";

quotes[4] = "Dummy quote of the day 5";
LOOP

There may be a situation when we need to execute a block of code
several number of times, and is often referred to as a loop.
In simple words it is a programming construct which helps replacing
following:
String quotes[] = new String[366];
quotes[0] = "Dummy quote of the day
quotes[1] = "Dummy quote of the day
quotes[2] = "Dummy quote of the day
quotes[3] = "Dummy quote of the day

1";
2";
3";
4";

quotes[4]
quotes[5]
quotes[6]
quotes[7]
quotes[8]

5";
6";
7";
8";
9";

=
=
=
=
=

"Dummy
"Dummy
"Dummy
"Dummy
"Dummy

quote
quote
quote
quote
quote

of
of
of
of
of

the
the
the
the
the

day
day
day
day
day

quotes[365] = "Dummy quote of the day 365";

With following:
String quotes[] = new String[366];
for (int i = 0; i < quotes.length; i++) {
quotes[i] = "Dummy quote of the day " + (i + 1);
}

Page 7 of 9
https://www.facebook.com/Oxus20

CALENDAR.DAY_OF_YEAR

As it is already mentioned the DAY_OF_YEAR is a constant of the
Calendar class and returns the day of the year ranges from 0 to 365
(for the leap years 366). Therefore, we can use this as index of the
array quotes [] in order to display the quote for the current day of
the year. Next day the next quote will be displayed.
// Construct Calendar object "c"
Calendar c = Calendar.getInstance();
// quote_index represent day of the year
int quote_index = c.get(Calendar.DAY_OF_YEAR);
// quotes[quote_index] returns day of the year quote
String quote_of_the_day = quotes[quote_index];
// Display the code the screen
System.out.println(quote_of_the_day);

Page 8 of 9
https://www.facebook.com/Oxus20

CONCLUSION

Good programmers don't have to be geniuses but they should be smart,
inventive and creative and a flare in problem solving. In addition,
good programmers passionate about technology, programs as a hobby and
learn new technologies on his/her own.
The concept of "Quote of the Day" for the year can be customized to be
used as follow:


Monthly Quote of the Day: To display the quote according the day
of the month.



Weekly Quote of the Day: To display the quote based on day of the
week and reset back next week.



Hourly Quote of the Day: To display the quote each hour



Minutely Quote of the Day: To display different quote each minute

Even can be used with different concept accomplishing different tasks
and idea; for example, the same concept can be customized to be used
for the banner advertisement, different themes and backgrounds
monthly, weekly, daily, hourly, minutely and/or even secondly.

Page 9 of 9

Weitere ähnliche Inhalte

Mehr von Abdul Rahman Sherzad

Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and AwarenessAbdul Rahman Sherzad
 
Database Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event SchedulersDatabase Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event SchedulersAbdul Rahman Sherzad
 
Evaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan UniversitiesEvaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan UniversitiesAbdul Rahman Sherzad
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationAbdul Rahman Sherzad
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersAbdul Rahman Sherzad
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsAbdul Rahman Sherzad
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepAbdul Rahman Sherzad
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaAbdul Rahman Sherzad
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesAbdul Rahman Sherzad
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesAbdul Rahman Sherzad
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesAbdul Rahman Sherzad
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented ProgrammingAbdul Rahman Sherzad
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticAbdul Rahman Sherzad
 
Top Down and Bottom Up Design Model
Top Down and Bottom Up Design ModelTop Down and Bottom Up Design Model
Top Down and Bottom Up Design ModelAbdul Rahman Sherzad
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IAbdul Rahman Sherzad
 

Mehr von Abdul Rahman Sherzad (20)

Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
 
Database Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event SchedulersDatabase Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event Schedulers
 
Mobile Score Notification System
Mobile Score Notification SystemMobile Score Notification System
Mobile Score Notification System
 
Herat Innovation Lab 2015
Herat Innovation Lab 2015Herat Innovation Lab 2015
Herat Innovation Lab 2015
 
Evaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan UniversitiesEvaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan Universities
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
 
Top Down and Bottom Up Design Model
Top Down and Bottom Up Design ModelTop Down and Bottom Up Design Model
Top Down and Bottom Up Design Model
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 

Kürzlich hochgeladen

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxAneriPatwari
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 

Kürzlich hochgeladen (20)

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptx
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 

JAVA Quote of the Day Tutorial Step By Step

  • 1. https://www.facebook.com/Oxus20 CONTENTS Problem Statement .................................................... 3 Solution ............................................................. 3 Code Explanation ..................................................... 5 Package and Import ................................................. 5 Class .............................................................. 6 Method MAIN ........................................................ 6 Array .............................................................. 6 Loop ............................................................... 7 Calendar.DAY_OF_YEAR ............................................... 8 Conclusion ........................................................... 9 Page 1 of 9
  • 2. https://www.facebook.com/Oxus20 RECOMMENDATION AND GUIDANCE Programming is fun and easy if and only if you concentrate and consider the Problem Solving process which consists of a sequence of sections that fit together depending on the type of problem to be solved. These are:  Understand the problem  Generating possible solutions  Refine the Solutions and select the best solution(s).  Implement and code the best selected solution  Test the code The process is only a guide for problem solving. It is useful to have a structure to follow to make sure that nothing is overlooked and ignored. Abdul Rahman Sherzad Special Thanks goes to Nooria Esmaelzadeh for her support taking minute of the session and drafting the idea together Page 2 of 9
  • 3. https://www.facebook.com/Oxus20 PROBLEM STATEMENT Write a program to display a different quote each day of the year as the quote of the day. The program should pick a random quote from an array of quotes you provide based on day of the year; and it must show that same picked and selected quote for the whole day and change to a new one the next day. NOTE: Remember and keep in mind the already picked and selected quotes should not pick again until the next year. SOLUTION Do you think it is simple or complex? REMEMBER "Every problem has a solution, Tom Hanks"  To be honest it is quite easy and simple. Followings ingredients are required solving the problem efficiently:  Array: An array is needed to store the quotes  Loop: Using loop can help initialize the dummy quotes for the demonstration and testing purpose inside the array.  Calenday.DAY_OF_YEAR: The constant DAY_OF_YEAR of the class Calendar returns day of year ranges from 1 to 365 (366 for the leap years). Page 3 of 9
  • 4. https://www.facebook.com/Oxus20 Following is the complete code of the "Quote of the Day" java application program: /* * Copyright (c) 2013, OXUS20 and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ import java.util.Calendar; /** * Display Quote Of The Day * This class picks a quote from an array of quotes based on day of the year. */ public class QuoteOfTheDay { public static void main(String[] args) { // Array quotes[] to store the quotes String quotes[] = new String[366]; // Loop initialize dummy quotes inside array quotes[] for (int i = 0; i < quotes.length; i++) { quotes[i] = "Dummy quote of the day " + (i + 1); } // Construct Calendar object "c" Calendar c = Calendar.getInstance(); // quote_index represent day of the year int quote_index = c.get(Calendar.DAY_OF_YEAR); // quotes[quote_index] returns day of the year quote String quote_of_the_day = quotes[quote_index]; // Display the code the screen System.out.println(quote_of_the_day); } } Page 4 of 9
  • 5. https://www.facebook.com/Oxus20 CODE EXPLANATION Let's break down the above code of "Quote of the Day" application program into pieces for the purpose of explanation as follow: PACKAGE AND IMPORT Package = directory: Java classes can be grouped together in packages. A package name is the same as the directory (folder) name which contains the .java files. To import classes into the current file, put an import statement at the beginning of the file before any type definitions but after the package statement, if there is one. Here's how you would import the Calendar class from the java.util package. import java.util.Calendar; From now on you can refer to the Calendar class by its simple name as follow: Calendar c = Calendar.getInstance(); Otherwise if you did not import the Calendar class you had to use following method in order to access the Calendar class: java.util.Calendar c = java.util.Calendar.getInstance(); Page 5 of 9
  • 6. https://www.facebook.com/Oxus20 CLASS Java class is nothing but a template for object you are going to create or it is a blueprint. When we create class in java the first step is keyword class and then name of the class or identifier we can say i.e. "QuoteOfTheDay". public class QuoteOfTheDay { } The curly braces symbols demonstrates the class body { }; and between this all things related to the class i.e. property and method will come here. METHOD MAIN In Java, you need to have a method named main () in at least one class. The following is what must appear in a real Java program. public static void main(String[] args) { } In the Java language, when you execute a class with the Java interpreter, the runtime system starts by calling the class's main () method. The main () method then calls all the other methods required to run your application. ARRAY An array is a container object that holds a fixed number of values of a single type. Array length is fixed after creation. Page 6 of 9
  • 7. https://www.facebook.com/Oxus20 In simple words it is a programming construct which helps replacing following: String String String String quote1 quote2 quote3 quote4 = = = = "Dummy "Dummy "Dummy "Dummy quote quote quote quote of of of of the the the the day day day day 1"; 2"; 3"; 4"; String quote5 = "Dummy quote of the day 5"; With following: String quotes[] = new String[366]; quotes[0] = "Dummy quote of the day quotes[1] = "Dummy quote of the day quotes[2] = "Dummy quote of the day quotes[3] = "Dummy quote of the day 1"; 2"; 3"; 4"; quotes[4] = "Dummy quote of the day 5"; LOOP There may be a situation when we need to execute a block of code several number of times, and is often referred to as a loop. In simple words it is a programming construct which helps replacing following: String quotes[] = new String[366]; quotes[0] = "Dummy quote of the day quotes[1] = "Dummy quote of the day quotes[2] = "Dummy quote of the day quotes[3] = "Dummy quote of the day 1"; 2"; 3"; 4"; quotes[4] quotes[5] quotes[6] quotes[7] quotes[8] 5"; 6"; 7"; 8"; 9"; = = = = = "Dummy "Dummy "Dummy "Dummy "Dummy quote quote quote quote quote of of of of of the the the the the day day day day day quotes[365] = "Dummy quote of the day 365"; With following: String quotes[] = new String[366]; for (int i = 0; i < quotes.length; i++) { quotes[i] = "Dummy quote of the day " + (i + 1); } Page 7 of 9
  • 8. https://www.facebook.com/Oxus20 CALENDAR.DAY_OF_YEAR As it is already mentioned the DAY_OF_YEAR is a constant of the Calendar class and returns the day of the year ranges from 0 to 365 (for the leap years 366). Therefore, we can use this as index of the array quotes [] in order to display the quote for the current day of the year. Next day the next quote will be displayed. // Construct Calendar object "c" Calendar c = Calendar.getInstance(); // quote_index represent day of the year int quote_index = c.get(Calendar.DAY_OF_YEAR); // quotes[quote_index] returns day of the year quote String quote_of_the_day = quotes[quote_index]; // Display the code the screen System.out.println(quote_of_the_day); Page 8 of 9
  • 9. https://www.facebook.com/Oxus20 CONCLUSION Good programmers don't have to be geniuses but they should be smart, inventive and creative and a flare in problem solving. In addition, good programmers passionate about technology, programs as a hobby and learn new technologies on his/her own. The concept of "Quote of the Day" for the year can be customized to be used as follow:  Monthly Quote of the Day: To display the quote according the day of the month.  Weekly Quote of the Day: To display the quote based on day of the week and reset back next week.  Hourly Quote of the Day: To display the quote each hour  Minutely Quote of the Day: To display different quote each minute Even can be used with different concept accomplishing different tasks and idea; for example, the same concept can be customized to be used for the banner advertisement, different themes and backgrounds monthly, weekly, daily, hourly, minutely and/or even secondly. Page 9 of 9