SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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 StaticOXUS 20
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryOXUS 20
 
JAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIJAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIOXUS 20
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART IIOXUS 20
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART IOXUS 20
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART IIOXUS 20
 
Java Arrays
Java ArraysJava Arrays
Java ArraysOXUS 20
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesOXUS 20
 

Destacado (9)

Barroco español y americano
Barroco español y americano Barroco español y americano
Barroco español y americano
 
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
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
 
JAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIJAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART III
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
 

Más de OXUS 20

Java Methods
Java MethodsJava Methods
Java MethodsOXUS 20
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement OXUS 20
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and GraphicsOXUS 20
 
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 AnswersOXUS 20
 
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 StepOXUS 20
 
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 TechnologiesOXUS 20
 
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 ClassesOXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART IIIOXUS 20
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART IOXUS 20
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number TutorialOXUS 20
 

Más de OXUS 20 (10)

Java Methods
Java MethodsJava Methods
Java Methods
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
 
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
 
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
 
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 GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 

Último

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 

Quote of the Day Program 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