SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
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

Contenu connexe

Plus de 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
 

Plus de 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
 

Dernier

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Dernier (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

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