Code Sketch


ai science buddy
By: Mhalsakant School
Category: Programming
import javax.swing._
import java.awt._
import java.awt.event._

// ============================================================
//                 AI SCIENCE BUDDY
//          CLASS 6 - 8 SCIENCE LEARNING APP
//                 KOJO / SCALA VERSION
// ============================================================
//
// Features:
// 1. Class 6, 7 and 8 selection
// 2. English, Hindi and Marathi
// 3. Large science question database
// 4. Multiple keywords for each topic
// 5. Step-by-step answers
// 6. Text-to-speech
// 7. Clear button
// 8. Example question buttons
// 9. Ctrl + Enter to ask
//
// NOTE:
// This is an offline rule-based science tutor.
// It does not connect to ChatGPT or the internet.
// ============================================================


// ============================================================
// COLORS
// ============================================================

val BLUE = new Color(0, 105, 180)
val DARK_BLUE = new Color(0, 65, 125)
val LIGHT_BLUE = new Color(235, 247, 255)

val GREEN = new Color(25, 135, 75)
val LIGHT_GREEN = new Color(235, 250, 240)

val ORANGE = new Color(235, 135, 30)
val LIGHT_ORANGE = new Color(255, 247, 230)

val RED = new Color(205, 65, 60)

val PURPLE = new Color(110, 75, 160)

val DARK_TEXT = new Color(35, 35, 35)
val GREY = new Color(100, 100, 100)


// ============================================================
// MAIN WINDOW
// ============================================================

val frame = new JFrame("AI Science Buddy - Class 6 to 8")

frame.setSize(1000, 800)

frame.setDefaultCloseOperation(
  WindowConstants.EXIT_ON_CLOSE
)

frame.setLayout(
  new BorderLayout(10, 10)
)


// ============================================================
// TITLE
// ============================================================

val titlePanel = new JPanel()

titlePanel.setLayout(
  new BorderLayout()
)

titlePanel.setBackground(
  new Color(220, 240, 255)
)

val title = new JLabel(
  "AI SCIENCE BUDDY",
  SwingConstants.CENTER
)

title.setFont(
  new Font("Arial", Font.BOLD, 30)
)

title.setForeground(
  DARK_BLUE
)

titlePanel.add(
  title,
  BorderLayout.CENTER
)

val subtitle = new JLabel(
  "Class 6 - 8 | Learn Science in Simple Words",
  SwingConstants.CENTER
)

subtitle.setFont(
  new Font("Arial", Font.PLAIN, 16)
)

subtitle.setForeground(
  DARK_TEXT
)

titlePanel.add(
  subtitle,
  BorderLayout.SOUTH
)

frame.add(
  titlePanel,
  BorderLayout.NORTH
)


// ============================================================
// MAIN PANEL
// ============================================================

val mainPanel = new JPanel()

mainPanel.setLayout(
  new BoxLayout(
    mainPanel,
    BoxLayout.Y_AXIS
  )
)

mainPanel.setBorder(
  BorderFactory.createEmptyBorder(
    12,
    18,
    12,
    18
  )
)


// ============================================================
// SETTINGS PANEL
// ============================================================

val settingsPanel = new JPanel(
  new FlowLayout(
    FlowLayout.LEFT,
    15,
    5
  )
)


// ---------------- CLASS ----------------

val classLabel = new JLabel(
  "Class:"
)

classLabel.setFont(
  new Font("Arial", Font.BOLD, 15)
)

settingsPanel.add(
  classLabel
)

val classBox = new JComboBox(
  Array(
    "Class 6",
    "Class 7",
    "Class 8"
  )
)

classBox.setFont(
  new Font("Arial", Font.PLAIN, 15)
)

settingsPanel.add(
  classBox
)


// ---------------- LANGUAGE ----------------

val languageLabel = new JLabel(
  "Language:"
)

languageLabel.setFont(
  new Font("Arial", Font.BOLD, 15)
)

settingsPanel.add(
  languageLabel
)

val languageBox = new JComboBox(
  Array(
    "English",
    "Hindi",
    "Marathi"
  )
)

languageBox.setFont(
  new Font("Arial", Font.PLAIN, 15)
)

settingsPanel.add(
  languageBox
)


// ---------------- SUBJECT ----------------

val subjectLabel = new JLabel(
  "Subject:"
)

subjectLabel.setFont(
  new Font("Arial", Font.BOLD, 15)
)

settingsPanel.add(
  subjectLabel
)

val subjectBox = new JComboBox(
  Array(
    "All Science",
    "Physics",
    "Chemistry",
    "Biology",
    "Environment",
    "Earth and Space"
  )
)

subjectBox.setFont(
  new Font("Arial", Font.PLAIN, 15)
)

settingsPanel.add(
  subjectBox
)

mainPanel.add(
  settingsPanel
)


// ============================================================
// QUESTION LABEL
// ============================================================

val questionLabel = new JLabel(
  "Ask any Class 6 - 8 Science question:"
)

questionLabel.setFont(
  new Font("Arial", Font.BOLD, 18)
)

questionLabel.setForeground(
  DARK_BLUE
)

mainPanel.add(
  questionLabel
)


// ============================================================
// QUESTION BOX
// ============================================================

val questionBox = new JTextArea(
  4,
  70
)

questionBox.setFont(
  new Font("Arial", Font.PLAIN, 17)
)

questionBox.setLineWrap(true)

questionBox.setWrapStyleWord(true)

questionBox.setBorder(
  BorderFactory.createCompoundBorder(
    BorderFactory.createLineBorder(
      new Color(150, 185, 210)
    ),
    BorderFactory.createEmptyBorder(
      7,
      7,
      7,
      7
    )
  )
)

val questionScroll = new JScrollPane(
  questionBox
)

mainPanel.add(
  questionScroll
)


// ============================================================
// EXAMPLES
// ============================================================

val exampleLabel = new JLabel(
  "<html><b>Try:</b> Why do we see lightning before thunder? &nbsp; " +
  "How do plants reproduce? &nbsp; " +
  "Why does ice float on water? &nbsp; " +
  "What is a food chain?</html>"
)

exampleLabel.setFont(
  new Font("Arial", Font.PLAIN, 13)
)

exampleLabel.setForeground(
  GREY
)

mainPanel.add(
  exampleLabel
)


// ============================================================
// BUTTON PANEL
// ============================================================

val buttonPanel = new JPanel(
  new FlowLayout(
    FlowLayout.CENTER,
    12,
    10
  )
)


// ASK BUTTON

val askButton = new JButton(
  "ASK SCIENCE BUDDY"
)

askButton.setFont(
  new Font("Arial", Font.BOLD, 15)
)

askButton.setBackground(
  BLUE
)

askButton.setForeground(
  Color.WHITE
)

buttonPanel.add(
  askButton
)


// SPEAK BUTTON

val speakButton = new JButton(
  "SPEAK ANSWER"
)

speakButton.setFont(
  new Font("Arial", Font.BOLD, 15)
)

speakButton.setBackground(
  GREEN
)

speakButton.setForeground(
  Color.WHITE
)

buttonPanel.add(
  speakButton
)


// EXAMPLE BUTTON

val exampleButton = new JButton(
  "RANDOM QUESTION"
)

exampleButton.setFont(
  new Font("Arial", Font.BOLD, 15)
)

exampleButton.setBackground(
  ORANGE
)

exampleButton.setForeground(
  Color.WHITE
)

buttonPanel.add(
  exampleButton
)


// CLEAR BUTTON

val clearButton = new JButton(
  "CLEAR"
)

clearButton.setFont(
  new Font("Arial", Font.BOLD, 15)
)

clearButton.setBackground(
  RED
)

clearButton.setForeground(
  Color.WHITE
)

buttonPanel.add(
  clearButton
)

mainPanel.add(
  buttonPanel
)


// ============================================================
// STATUS
// ============================================================

val statusLabel = new JLabel(
  "Ready! Ask any Class 6 - 8 science question."
)

statusLabel.setFont(
  new Font("Arial", Font.BOLD, 14)
)

statusLabel.setForeground(
  BLUE
)

mainPanel.add(
  statusLabel
)


// ============================================================
// ANSWER TITLE
// ============================================================

val answerLabel = new JLabel(
  "Science Buddy Answer:"
)

answerLabel.setFont(
  new Font("Arial", Font.BOLD, 19)
)

answerLabel.setForeground(
  GREEN
)

mainPanel.add(
  answerLabel
)


// ============================================================
// ANSWER BOX
// ============================================================

val answerBox = new JTextArea(
  17,
  70
)

answerBox.setFont(
  new Font("Arial", Font.PLAIN, 16)
)

answerBox.setLineWrap(true)

answerBox.setWrapStyleWord(true)

answerBox.setEditable(false)

answerBox.setBackground(
  LIGHT_BLUE
)

answerBox.setForeground(
  DARK_TEXT
)

answerBox.setBorder(
  BorderFactory.createCompoundBorder(
    BorderFactory.createLineBorder(
      new Color(150, 195, 220)
    ),
    BorderFactory.createEmptyBorder(
      10,
      10,
      10,
      10
    )
  )
)

val answerScroll = new JScrollPane(
  answerBox
)

mainPanel.add(
  answerScroll
)


// ============================================================
// HOW TO USE
// ============================================================

val howToLabel = new JLabel(
  "<html>" +
  "<b>How to use:</b> Type your question in normal words. " +
  "The Buddy recognizes many Class 6-8 science topics including " +
  "motion, force, light, sound, electricity, magnets, matter, " +
  "atoms, acids, bases, plants, animals, cells, nutrition, " +
  "respiration, reproduction, environment, Earth and space." +
  "</html>"
)

howToLabel.setFont(
  new Font("Arial", Font.PLAIN, 13)
)

howToLabel.setOpaque(true)

howToLabel.setBackground(
  LIGHT_GREEN
)

howToLabel.setBorder(
  BorderFactory.createEmptyBorder(
    8,
    8,
    8,
    8
  )
)

mainPanel.add(
  howToLabel
)


// ============================================================
// ADD MAIN PANEL
// ============================================================

frame.add(
  mainPanel,
  BorderLayout.CENTER
)


// ============================================================
// TEXT NORMALIZATION
// ============================================================

def normalize(
  text: String
): String = {

  text
    .toLowerCase
    .replace("?", " ")
    .replace("!", " ")
    .replace(",", " ")
    .replace(".", " ")
    .replace(":", " ")
    .replace(";", " ")
    .replace("-", " ")
    .replace("(", " ")
    .replace(")", " ")
    .replaceAll("\\s+", " ")
    .trim
}


// ============================================================
// KEYWORD HELPER
// ============================================================

def hasAny(
  q: String,
  words: Array[String]
): Boolean = {

  words.exists(
    word => q.contains(word)
  )
}


// ============================================================
// SCIENCE ANSWER ENGINE
// ============================================================

def getScienceAnswer(
  question: String,
  language: String,
  schoolClass: String,
  subject: String
): String = {

  val q = normalize(question)


  // ==========================================================
  // EMPTY
  // ==========================================================

  if (q.length == 0) {

    return "Please type a science question."
  }


  // ==========================================================
  // GREETING
  // ==========================================================

  if (
    hasAny(
      q,
      Array(
        "hello",
        "hi",
        "hey",
        "namaste"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
??????!

??? Science Buddy ????

??? ????? 6 ?? 8 ?? ??????? ?? ???? ?? ???????? ??? ??? ?? ???? ????

?? ??? ???? ???:
? ?? ???? ???
? ???? ???? ???? ????? ????
? ?????? ???? ???
? ????? ???? ??????? ???? ???
? ???? ?? ????? ???? ????
? ????? ???????? ???? ???
? ????? ??? ???? ???? ???

???? ??????? ?????? ??????
"""
    }

    if (language == "Marathi") {

      return """
???????!

?? Science Buddy ???.

?? ?????? 6 ?? 8 ???? ???????????? ???? ?????????? ?????? ????? ?????? ??? ????.

??????:
? ?? ?????? ????
? ??????? ???? ??? ???? ??????
? ?????? ?????? ????
? ????? ??? ??????? ?????
? ???? ??? ??????? ?????? ????
? ????????? ?????? ????
? ??????? ?????? ????

????? ?????????? ?????? ??????.
"""
    }

    return """
Hello! I am Science Buddy.

I can help you learn many Class 6 to 8 Science topics.

You can ask me about:
? Force and motion
? Light and sound
? Electricity and magnets
? Matter and atoms
? Acids and bases
? Plants and animals
? Human body
? Food and nutrition
? Reproduction
? Environment
? Earth and space

Ask me any science question in simple words.
"""
  }


  // ==========================================================
  // GRAVITY
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "gravity",
        "gravitational force",
        "gravitation",
        "why objects fall",
        "why things fall"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
????????????? ???? ???

??? 1:
????????????? ?? ?????? ?? ???

??? 2:
?? ????????? ???? ??????? ?? ??-????? ?? ?? ?????? ???

??? 3:
?????? ?? ????????????? ???? ?? ??????? ?? ?????? ?? ?? ?????? ???

??? 4:
??? ???? ?? ?? ???? ?? ??? ?? ?????? ??? ?? ?? ???? ????? ???

??????:
???? ?? ?? ???? ????? ?? ??????? ?????? ?? ????????????? ??? ???? ?????? ???

??? ?????? ???:
????????????? ?? ?? ?? ?? ??????? ?? ??-????? ?? ?? ??????? ???? ???
"""
    }

    if (language == "Marathi") {

      return """
????????????? ?????? ????

????? 1:
????????????? ?? ????????? ?? ???.

????? 2:
?? ???????? ?????????? ??????? ????.

????? 3:
???????? ????????????? ???????? ??? ???????? ?????????? ?????? ????.

????? 4:
?????? ??? ????? ????? ?? ?? ??????? ????.

??????:
???????? ?? ???? ???? ???? ???????? ????????????? ?????? ???? ????.

?????? ???????:
????????????? ?????? ???????? ?????????? ?????? ??.
"""
    }

    return """
WHAT IS GRAVITY?

Step 1:
Gravity is an attractive force.

Step 2:
It pulls objects with mass toward one another.

Step 3:
Earth's gravity pulls objects toward Earth.

Step 4:
That is why a ball falls when we drop it.

Example:
A fruit falls from a tree because Earth's gravity pulls it downward.

In simple words:
Gravity is the force of attraction between objects with mass.
"""
  }


  // ==========================================================
  // FORCE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "force",
        "push",
        "pull",
        "push or pull"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
?? ???? ???

??? 1:
?? ???? ????? ?? ????? ??? ????? ?? ?????? ???

??? 2:
?? ???? ????? ?? ??? ??? ???? ???

??? 3:
?? ???? ????? ????? ?? ??? ???? ???

??? 4:
?? ???? ???? ????? ?? ??? ???? ???

??? 5:
?? ????? ?? ???? ?? ??? ???? ???

??????:
?????? ?? ????? ???? ?? ?? ????? ???

??? ?????? ???:
?? ????? ?? ?????? ???
"""
    }

    if (language == "Marathi") {

      return """
?? ?????? ????

????? 1:
?? ?????? ??????? ?????? ????? ????? ??.

????? 2:
??????? ??????? ??? ???? ????.

????? 3:
??????? ????? ????? ???? ????.

????? 4:
??????? ??????? ????? ????? ????.

????? 5:
??????? ??????? ???? ???? ????.

??????:
???????? ????????? ?? ?????.

?????? ???????:
?? ?????? ????? ????? ??.
"""
    }

    return """
WHAT IS FORCE?

Step 1:
Force is a push or a pull.

Step 2:
A force can change the motion of an object.

Step 3:
It can make a stationary object move.

Step 4:
It can stop a moving object.

Step 5:
It can change the direction of motion.

Example:
When you push a door, the door moves.

In simple words:
Force is a push or pull acting on an object.
"""
  }


  // ==========================================================
  // MOTION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "motion",
        "moving object",
        "what is motion",
        "distance",
        "speed"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
??? ???? ???

??? 1:
?? ??? ????? ??? ?? ??? ???? ?????? ????? ??, ?? ?? ???? ??? ?? ????? ??? ??? ???

??? 2:
???? ????? ?????? ?? ?? ?? ????? ?? ???? ???? ????

??? 3:
??? ????? ?? ?? ??? ????? ????? ???? ?? ???? ?? ???? ???

??? 4:
??? ?? ??????? ????? ??:

??? = ???? / ???

??????:
??? ??? ??? ?? ??? ??? ???? ???? ?? ???? ??, ?? ???? ??? ???? ???

??? ?????? ???:
?????? ??? ??? ?? ??? ???????? ?? ??? ???? ????
"""
    }

    if (language == "Marathi") {

      return """
??? ?????? ????

????? 1:
??????? ??????? ?????? ????????? ???? ???? ?? ?? ????? ???????? ??? ??? ???????.

????? 2:
??????? ??? ???????? ??????? ???? ???????.

????? 3:
??? ?????? ????? ???? ?????? ???? ??? ????.

????? 4:
?????? ?????:

??? = ???? / ???

??????:
????? ??? ??? ????? ????? ???? ??? ??? ???? ?? ???? ??? ????? ???.

?????? ???????:
????????? ????????? ??????? ?????? ??? ?????? ???.
"""
    }

    return """
WHAT IS MOTION?

Step 1:
An object is said to be in motion when its position changes with time.

Step 2:
The length of the path travelled by an object is called distance.

Step 3:
Speed tells us how quickly an object covers distance.

Step 4:
The basic formula is:

Speed = Distance / Time

Example:
If a car covers a large distance in a short time, it has a high speed.

In simple words:
Motion means a change in position with time.
"""
  }


  // ==========================================================
  // PHOTOSYNTHESIS
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "photosynthesis",
        "plant make food",
        "plants make food",
        "how plants make food",
        "food in plants"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
?????? ???????? ???? ???

??? 1:
??? ????? ?? ????? ?? ?????? ????? ???

??? 2:
????? ?????? ?? ???? ?? ???? ???? ????

??? 3:
???????? ???????? ?? ?????? ?????????? ???? ????

??? 4:
???????? ??? ????? ????????? ????? ?? ?????? ?? ??????? ???? ???

??? 5:
????? ?? ?????? ?? ????? ?? ????? ???? ???? ???? ????? ???

??? 6:
?? ????????? ??? ??????? ???? ?????? ???

??? ?????? ???:
?????? ???????? ?? ????????? ?? ?????? ??? ???? ????? ?? ??????, ???? ?? ?????? ?????????? ?? ?????? ?? ???? ???? ????? ????
"""
    }

    if (language == "Marathi") {

      return """
?????????????? ?????? ????

????? 1:
??????? ?????????? ??????????? ?????.

????? 2:
???? ???????? ???? ??? ????? ?????.

????? 3:
???? ?????? ?????? ?????????? ?????.

????? 4:
????????? ?????????? ??????????? ????? ????.

????? 5:
???????????????? ??????? ???? ???? ??????? ???? ???? ????.

????? 6:
?? ?????????? ??????? ????? ????? ????.

?????? ???????:
???????????, ???? ??? ?????? ?????????? ?????? ??????? ??????? ???? ???? ?????. ?? ??????????? ?????????????? ???????.
"""
    }

    return """
WHAT IS PHOTOSYNTHESIS?

Step 1:
Green plants receive sunlight.

Step 2:
Roots absorb water and minerals from the soil.

Step 3:
Leaves take carbon dioxide from the air.

Step 4:
Chlorophyll in the leaves absorbs sunlight.

Step 5:
Plants use light energy to make food.

Step 6:
Oxygen is released during the process.

In simple words:
Photosynthesis is the process by which green plants make food using sunlight, water and carbon dioxide.
"""
  }


  // ==========================================================
  // CELL
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "cell",
        "what is a cell",
        "basic unit of life",
        "basic unit of living"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
?????? ???? ???

??? 1:
?????? ????? ?? ??? ?????????? ?? ?????????? ???? ???

??? 2:
??????, ???? ?? ??????? ??? ???????? ?? ??? ???? ????

??? 3:
????? ?? ?????? ?? ???????? ??? ??? ???? ?? ??? ??? ??? ???? ????

??? 4:
?????? ??? ?????? ??????, ???????????? ?? ???????? ?????? ???? ?????????? ??? ???? ????

??? ?????? ???:
?????? ????? ???? ?? ?? ???? ???? ??? ???? ???
"""
    }

    if (language == "Marathi") {

      return """
???? ?????? ????

????? 1:
???? ?? ???????? ?????? ?????????? ??? ?????????? ??? ???.

????? 2:
????, ??????? ??? ???? ???? ??????? ?????? ????.

????? 3:
??????? ??? ????????????? ?????????? ???? ???? ?? ???? ????? ??? ?????.

????? 4:
????????? ???????, ?????????? ??? ???????? ?????? ???????? ?????????? ??? ?????.

?????? ???????:
???? ?? ???? ??????? ????? ???? ?????? ??? ???.
"""
    }

    return """
WHAT IS A CELL?

Step 1:
A cell is the basic structural and functional unit of life.

Step 2:
Humans, plants and many other organisms are made of cells.

Step 3:
Plant and animal cells have some common and some different structures.

Step 4:
Important cell parts include the cell membrane, cytoplasm and genetic material.

In simple words:
A cell is a tiny basic unit that makes up a living organism.
"""
  }


  // ==========================================================
  // HUMAN BODY
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "human body",
        "body system",
        "organ system",
        "organs in human body"
      )
    )
  ) {

    return """
WHAT IS THE HUMAN BODY?

The human body is made of many levels of organization.

1. Cells are the basic units.
2. Similar cells can form tissues.
3. Tissues form organs.
4. Organs work together in organ systems.
5. Organ systems work together to keep the body alive.

Important systems include:

? Digestive system - helps digest food.
? Respiratory system - helps us breathe.
? Circulatory system - transports blood and substances.
? Nervous system - controls and coordinates many activities.
? Excretory system - removes certain wastes.
? Skeletal system - supports and protects the body.

In simple words:
Different organs and systems work together to keep our body functioning.
"""
  }


  // ==========================================================
  // DIGESTION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "digestion",
        "digest food",
        "digestive system",
        "how food is digested"
      )
    )
  ) {

    if (language == "Hindi") {

      return """
???? ???? ???

???? ?? ????????? ?? ?????? ???? ?? ???? ?? ??? ???????? ??? ???? ???? ?? ???? ???? ?????? ??????? ?? ????

????? ???:

1. ???? ???? ??? ????? ???? ???
2. ??? ???? ?? ???? ???? ?? ?? ???? ?? ?????? ???? ???
3. ???? ???? ??? ?? ??? ??? ???? ???
4. ??? ??? ???? ?? ???? ?? ??? ???? ????
5. ???? ??? ??? ???? ???? ???? ?? ?? ???? ???????? ?? ?????? ???? ???
6. ???? ??? ????? ??? ?? ???? ?? ?????? ??? ??? ???? ???

??? ?????? ???:
???? ???? ?? ??? ???? ???????? ??? ????? ?? ??????? ???? ????? ?? ????
"""
    }

    if (language == "Marathi") {

      return """
??? ?????? ????

??? ?? ??? ????????? ??? ????????? ??????? ??????? ????? ???? ????? ??? ???? ??? ?????? ????????????? ??????? ????.

????? ?????:

1. ???? ?????? ????? ????.
2. ??? ???? ??? ???? ??? ?????? ??????? ????.
3. ???? ???????????? ????? ????.
4. ??????? ???? ?? ??????? ????? ?????.
5. ???? ??????? ??? ????? ???? ??? ???? ?????????? ???? ????.
6. ???? ???? ??????? ?????????? ?????? ??? ????.

?????? ???????:
???????? ??????? ??????? ????? ???? ????? ??? ????????????? ??????? ????.
"""
    }

    return """
WHAT IS DIGESTION?

Digestion is the process of breaking food into smaller and simpler substances that the body can absorb and use.

Main steps:

1. Food is chewed in the mouth.
2. Saliva moistens food and starts digestion.
3. Food passes through the food pipe into the stomach.
4. Digestive juices act on food in the stomach.
5. Digestion is completed mainly in the small intestine, where nutrients are absorbed.
6. The large intestine helps absorb water.

In simple words:
Digestion changes food into substances that the body can absorb and use.
"""
  }


  // ==========================================================
  // RESPIRATION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "respiration",
        "breathing",
        "respiratory system",
        "why do we breathe"
      )
    )
  ) {

    return """
WHAT IS RESPIRATION?

Step 1:
Our cells need energy to perform their activities.

Step 2:
Food contains chemical energy.

Step 3:
During cellular respiration, cells release usable energy from food.

Step 4:
In aerobic respiration, oxygen is used and carbon dioxide is produced.

Step 5:
We breathe to take in oxygen and remove carbon dioxide.

Important:
Breathing and cellular respiration are related, but they are not exactly the same process.

In simple words:
Respiration is a process by which cells release usable energy from food.
"""
  }


  // ==========================================================
  // FOOD AND NUTRITION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "nutrition",
        "nutrients",
        "food nutrients",
        "balanced diet",
        "components of food",
        "types of nutrients"
      )
    )
  ) {

    return """
WHAT ARE NUTRIENTS?

Nutrients are substances in food that our body needs for energy, growth, repair and proper functioning.

Important nutrients include:

1. Carbohydrates
   - Main source of energy.

2. Proteins
   - Help growth and repair of body tissues.

3. Fats
   - Provide concentrated energy and help with some body functions.

4. Vitamins
   - Needed in small amounts for normal body functions.

5. Minerals
   - Important for bones, blood and many body processes.

6. Water
   - Essential for many body functions.

7. Roughage
   - Helps proper movement of food through the digestive system.

A balanced diet contains different nutrients in suitable amounts.

In simple words:
Healthy food should provide the body with a variety of nutrients.
"""
  }


  // ==========================================================
  // INFECTIOUS DISEASE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "infectious disease",
        "infectious diseases",
        "contagious disease",
        "communicable disease",
        "disease caused by germs"
      )
    )
  ) {

    return """
WHAT ARE INFECTIOUS DISEASES?

Step 1:
An infectious disease is caused by a disease-causing microorganism or other infectious agent.

Step 2:
Examples of microorganisms include certain bacteria, viruses, fungi and parasites.

Step 3:
Some infectious diseases can spread from one person to another.

Step 4:
Spread can occur in different ways, such as through air droplets, contaminated food or water, direct contact, or vectors such as mosquitoes.

Examples:
? Common cold
? Influenza
? Measles
? Some intestinal infections

Prevention:
? Wash hands regularly.
? Drink safe water.
? Eat properly prepared food.
? Maintain cleanliness.
? Follow recommended vaccinations.

In simple words:
Infectious diseases are illnesses caused by infectious agents, and some can spread between people.
"""
  }


  // ==========================================================
  // PLANT REPRODUCTION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "plant reproduction",
        "reproduction in plants",
        "how plants reproduce",
        "vegetative propagation",
        "pollination",
        "fertilization in plants"
      )
    )
  ) {

    return """
REPRODUCTION IN PLANTS

Plants can reproduce in different ways.

1. Sexual reproduction

In flowering plants, flowers contain reproductive structures.

Pollination:
Pollen is transferred from the anther to the stigma.

Fertilization:
The male reproductive cell joins with the female reproductive cell.

After fertilization, seeds can develop.

2. Asexual reproduction

A new plant can sometimes grow from parts of the parent plant.

Examples:
? Potato - stem tuber
? Onion - bulb
? Ginger - underground stem
? Bryophyllum - leaves

In simple words:
Plants can reproduce through seeds or, in some plants, through vegetative parts.
"""
  }


  // ==========================================================
  // ANIMAL REPRODUCTION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "animal reproduction",
        "reproduction in animals",
        "how animals reproduce",
        "sexual reproduction in animals"
      )
    )
  ) {

    return """
REPRODUCTION IN ANIMALS

Reproduction is the process by which organisms produce new individuals.

Two broad patterns are:

1. Sexual reproduction
   - Usually involves male and female reproductive cells.
   - Their fusion is called fertilization.

2. Asexual reproduction
   - In some organisms, new individuals can form without fusion of male and female reproductive cells.

In many animals, fertilization may be internal or external.

Examples:
? Humans have internal fertilization.
? Some aquatic animals can have external fertilization.

In simple words:
Reproduction allows living organisms to produce new individuals of their kind.
"""
  }


  // ==========================================================
  // ATOM
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "atom",
        "what is atom",
        "structure of atom",
        "proton neutron electron"
      )
    )
  ) {

    return """
WHAT IS AN ATOM?

Step 1:
An atom is a very small unit of an element.

Step 2:
An atom contains a central nucleus.

Step 3:
The nucleus contains protons and neutrons.

Step 4:
Electrons occupy regions around the nucleus.

Proton:
- Has positive electric charge.

Neutron:
- Has no electric charge.

Electron:
- Has negative electric charge.

In simple words:
An atom is a tiny unit of an element made of a nucleus and electrons.
"""
  }


  // ==========================================================
  // MATTER
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "matter",
        "states of matter",
        "solid liquid gas",
        "solid liquid and gas"
      )
    )
  ) {

    return """
WHAT IS MATTER?

Matter is anything that has mass and occupies space.

Three familiar states of matter are:

1. SOLID
   - Has a definite shape and volume.
   - Particles are closely packed.

2. LIQUID
   - Has a definite volume but takes the shape of its container.
   - Particles can move past one another.

3. GAS
   - Has no fixed shape or volume.
   - Particles are much farther apart and move freely.

Heating and cooling can change the state of matter.

Examples:
Ice -> water -> water vapour

In simple words:
Matter is made of particles and can exist in different states.
"""
  }


  // ==========================================================
  // ACID BASE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "acid",
        "acids",
        "base",
        "bases",
        "acid and base",
        "acids and bases",
        "indicator",
        "litmus"
      )
    )
  ) {

    return """
ACIDS, BASES AND INDICATORS

Acids:
Many acidic substances have a sour taste, but chemicals should never be tasted to identify them.

Examples:
? Lemon juice contains citric acid.
? Vinegar contains acetic acid.

Bases:
Many bases feel slippery and can react with acids.

Examples:
? Soap solutions are generally basic.
? Some cleaning substances are basic.

Indicators:
Indicators help us identify whether a solution is acidic or basic.

Examples:
? Litmus
? Turmeric
? Some natural indicators

Litmus:
? Blue litmus can turn red in an acidic solution.
? Red litmus can turn blue in a basic solution.

Neutralization:
An acid and a base can react to form salt and water, depending on the substances involved.

In simple words:
Indicators help us test whether a substance is acidic or basic.
"""
  }


  // ==========================================================
  // PHYSICAL AND CHEMICAL CHANGE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "physical change",
        "chemical change",
        "physical and chemical change",
        "difference between physical and chemical change"
      )
    )
  ) {

    return """
PHYSICAL AND CHEMICAL CHANGES

PHYSICAL CHANGE:

A physical change changes the appearance, state or form of a substance without forming a new substance.

Examples:
? Melting ice
? Cutting paper
? Dissolving some substances in water

CHEMICAL CHANGE:

A chemical change produces one or more new substances with different properties.

Examples:
? Rusting of iron
? Burning wood
? Cooking many foods

A useful clue:
If a new substance is formed, the change is generally considered chemical.

In simple words:
Physical change mainly changes form or state, while chemical change forms new substance(s).
"""
  }


  // ==========================================================
  // SEPARATION OF MIXTURES
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "mixture",
        "separation of mixtures",
        "separate mixture",
        "filtration",
        "evaporation",
        "distillation",
        "decantation",
        "handpicking",
        "winnowing"
      )
    )
  ) {

    return """
SEPARATION OF MIXTURES

Different methods are used depending on the properties of the substances.

1. Handpicking
   - Used when unwanted solid particles are large enough to pick out.

2. Sieving
   - Separates particles of different sizes.

3. Filtration
   - Separates an insoluble solid from a liquid.

4. Evaporation
   - Can be used to recover a dissolved solid from a solution.

5. Decantation
   - A liquid can be carefully poured away from a settled solid.

6. Magnetic separation
   - A magnet can separate magnetic materials such as iron from some mixtures.

In simple words:
We choose a separation method according to the properties of the substances in the mixture.
"""
  }


  // ==========================================================
  // HEAT
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "heat",
        "temperature",
        "hot and cold",
        "transfer of heat",
        "conduction",
        "convection",
        "radiation"
      )
    )
  ) {

    return """
HEAT AND TEMPERATURE

Temperature tells us how hot or cold something is.

Heat is energy transferred because of a temperature difference.

Heat can be transferred in three important ways:

1. Conduction
   - Heat transfer through direct contact.
   - Common in solids.

2. Convection
   - Heat transfer through the movement of fluids such as liquids and gases.

3. Radiation
   - Heat can travel by electromagnetic radiation and does not require direct contact.

Example:
The Sun warms Earth mainly through radiation.

In simple words:
Temperature measures hotness or coldness, while heat is energy transferred due to temperature difference.
"""
  }


  // ==========================================================
  // LIGHT
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "light",
        "reflection",
        "refraction",
        "mirror",
        "shadow",
        "transparent",
        "translucent",
        "opaque"
      )
    )
  ) {

    return """
WHAT IS LIGHT?

Light is a form of electromagnetic radiation that can be detected by our eyes.

Important ideas:

1. Reflection
   - Light bounces back from a surface.

2. Refraction
   - Light changes direction when it passes from one transparent medium to another because its speed changes.

3. Shadow
   - A shadow can form when an opaque object blocks light.

4. Transparent material
   - Allows most light to pass through.

5. Translucent material
   - Allows some light to pass through.

6. Opaque material
   - Blocks light.

Example:
We can see our face in a mirror because light from our face is reflected into our eyes.

In simple words:
Light allows us to see and can be reflected, refracted or blocked.
"""
  }


  // ==========================================================
  // SOUND
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "sound",
        "sound produced",
        "how sound is produced",
        "vibration",
        "pitch",
        "loudness"
      )
    )
  ) {

    return """
WHAT IS SOUND?

Step 1:
Sound is produced by vibrating objects.

Step 2:
The vibration creates disturbances in a medium.

Step 3:
Sound can travel through solids, liquids and gases.

Step 4:
Sound needs a material medium to travel through.

Pitch:
Pitch is related to the frequency of vibration.

Loudness:
Loudness is related to the strength or amplitude of the vibration and how our ears perceive the sound.

Example:
A vibrating guitar string produces sound.

In simple words:
Sound is produced by vibrations and travels through a material medium.
"""
  }


  // ==========================================================
  // ELECTRICITY
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "electricity",
        "electric circuit",
        "circuit",
        "electric current",
        "current",
        "battery",
        "bulb",
        "switch"
      )
    )
  ) {

    return """
ELECTRICITY AND SIMPLE CIRCUITS

An electric circuit is a complete path through which electric current can flow.

Main parts:

1. Cell or battery
   - Provides electrical energy.

2. Wires
   - Provide conducting paths.

3. Switch
   - Opens or closes the circuit.

4. Bulb or other device
   - Uses electrical energy.

Open circuit:
The path is broken, so current cannot flow through the complete circuit.

Closed circuit:
The path is complete, so current can flow.

Conductors:
Materials such as many metals allow electric current to pass relatively easily.

Insulators:
Materials such as rubber and dry plastic resist the flow of electric current.

In simple words:
A working circuit needs a suitable complete conducting path.
"""
  }


  // ==========================================================
  // MAGNET
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "magnet",
        "magnetic",
        "magnetic field",
        "north pole",
        "south pole",
        "magnetic poles"
      )
    )
  ) {

    return """
WHAT IS A MAGNET?

A magnet is an object that produces a magnetic field.

Important facts:

1. Magnets have two poles:
   - North pole
   - South pole

2. Like poles repel each other.

3. Unlike poles attract each other.

4. Magnetic force can act without direct contact.

5. Iron and some other materials can be attracted strongly by magnets.

Earth itself behaves approximately like a giant magnet.

In simple words:
A magnet produces a magnetic field and has north and south poles.
"""
  }


  // ==========================================================
  // OXYGEN
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "oxygen",
        "importance of oxygen",
        "why oxygen is important"
      )
    )
  ) {

    return """
WHAT IS OXYGEN?

Oxygen is a chemical element.

Symbol:
O

Oxygen is important because:

1. Humans need oxygen for aerobic respiration.
2. Many animals need oxygen.
3. Oxygen supports combustion, although oxygen itself is not a fuel.
4. Plants also use oxygen for respiration.

Oxygen is present in Earth's atmosphere mainly as O2 molecules.

In simple words:
Oxygen is an important element used by many organisms in respiration.
"""
  }


  // ==========================================================
  // WATER
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "water cycle",
        "water cycle",
        "evaporation",
        "condensation",
        "precipitation",
        "water boil",
        "boiling water",
        "why water boils"
      )
    )
  ) {

    return """
WATER AND THE WATER CYCLE

Important processes:

1. Evaporation
   - Liquid water changes into water vapour.

2. Condensation
   - Water vapour changes into liquid water.

3. Precipitation
   - Water falls from clouds as rain, snow, sleet or hail depending on conditions.

4. Collection
   - Water collects in rivers, lakes, oceans, soil and other places.

Water is continuously moving through these processes.

WHY DOES WATER BOIL?

At normal atmospheric pressure, pure water boils at about 100 �C.

When water is heated:
? Its particles gain energy.
? They move more vigorously.
? At the boiling point, bubbles of water vapour form throughout the liquid.

In simple words:
The water cycle moves water between Earth's surface, atmosphere and other reservoirs.
"""
  }


  // ==========================================================
  // AIR
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "air",
        "atmosphere",
        "components of air",
        "composition of air"
      )
    )
  ) {

    return """
WHAT IS AIR?

Air is a mixture of gases surrounding Earth.

Major components include:

? Nitrogen
? Oxygen
? Argon
? Carbon dioxide
? Variable amounts of water vapour

Air also contains very small amounts of other gases and particles.

Importance of air:

1. Oxygen supports respiration.
2. Carbon dioxide is used by plants in photosynthesis.
3. Air helps weather processes.
4. The atmosphere protects Earth and helps regulate temperature.

In simple words:
Air is a mixture of gases that surrounds Earth and is essential for life and many natural processes.
"""
  }


  // ==========================================================
  // POLLUTION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "pollution",
        "air pollution",
        "water pollution",
        "soil pollution",
        "noise pollution"
      )
    )
  ) {

    return """
WHAT IS POLLUTION?

Pollution is the introduction of harmful substances or energy into the environment in ways that can cause undesirable effects.

Types:

1. Air pollution
   - Harmful gases and particles enter the air.

2. Water pollution
   - Harmful substances contaminate water bodies.

3. Soil pollution
   - Harmful chemicals or waste contaminate soil.

4. Noise pollution
   - Excessive or unwanted sound can disturb people and animals.

Ways to reduce pollution:

? Use resources carefully.
? Reduce unnecessary waste.
? Reuse and recycle suitable materials.
? Use cleaner energy where practical.
? Avoid littering.
? Treat waste properly.
? Protect trees, water bodies and habitats.

In simple words:
Pollution harms the environment and can affect living organisms.
"""
  }


  // ==========================================================
  // FOOD CHAIN
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "food chain",
        "food web",
        "producer",
        "consumer",
        "decomposer"
      )
    )
  ) {

    return """
WHAT IS A FOOD CHAIN?

A food chain shows how energy and nutrients are transferred through feeding relationships.

Example:

Grass -> Grasshopper -> Frog -> Snake -> Eagle

Producer:
Plants are producers because they make their own food.

Consumer:
Animals obtain energy by eating plants or other animals.

Decomposer:
Organisms such as many fungi and bacteria break down dead organic matter and help return nutrients to the environment.

A food web is made from many interconnected food chains.

In simple words:
A food chain shows who eats whom and how energy moves through an ecosystem.
"""
  }


  // ==========================================================
  // ECOSYSTEM
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "ecosystem",
        "ecosystems",
        "biotic",
        "abiotic",
        "environment"
      )
    )
  ) {

    return """
WHAT IS AN ECOSYSTEM?

An ecosystem includes living organisms and the non-living parts of their environment interacting with one another.

Biotic components:
? Plants
? Animals
? Microorganisms

Abiotic components:
? Air
? Water
? Soil
? Sunlight
? Temperature

Examples:
? Pond ecosystem
? Forest ecosystem
? Grassland ecosystem

In simple words:
An ecosystem is a system in which living organisms interact with one another and with their physical environment.
"""
  }


  // ==========================================================
  // ADAPTATION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "adaptation",
        "adaptations",
        "how animals survive",
        "desert adaptation",
        "polar adaptation"
      )
    )
  ) {

    return """
WHAT IS ADAPTATION?

An adaptation is a characteristic that helps an organism survive and reproduce in its environment.

Examples:

Camel:
? Can survive for long periods with little water.
? Has features that help it live in desert conditions.

Polar bear:
? Thick fur and body fat help reduce heat loss.
? Its white appearance can help camouflage it in snowy environments.

Fish:
? Streamlined bodies help many fish move through water.
? Gills allow them to obtain oxygen from water.

Plants also have adaptations.

In simple words:
Adaptations are features or behaviors that help organisms live in their environments.
"""
  }


  // ==========================================================
  // SOLAR SYSTEM
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "solar system",
        "planets",
        "planet",
        "sun",
        "earth",
        "solar system planets"
      )
    )
  ) {

    return """
WHAT IS THE SOLAR SYSTEM?

The Solar System is made up of the Sun and the objects that are gravitationally bound to it.

The eight planets, in order from the Sun, are:

1. Mercury
2. Venus
3. Earth
4. Mars
5. Jupiter
6. Saturn
7. Uranus
8. Neptune

Other objects include:

? Moons
? Asteroids
? Comets
? Dwarf planets

The Sun is a star and contains most of the Solar System's mass.

Earth is the planet where we live.

In simple words:
The Solar System is the Sun and the many objects that orbit it.
"""
  }


  // ==========================================================
  // MOON
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "moon",
        "phases of moon",
        "moon phases",
        "why moon shines"
      )
    )
  ) {

    return """
WHAT IS THE MOON?

Step 1:
The Moon is Earth's natural satellite.

Step 2:
It orbits Earth.

Step 3:
The Moon does not produce its own visible light.

Step 4:
We see sunlight reflected from its surface.

MOON PHASES:

As the Moon orbits Earth, the portion of its sunlit side visible from Earth changes.

The main phases include:

? New Moon
? First Quarter
? Full Moon
? Last Quarter

The phases are not caused by Earth's shadow except during a lunar eclipse.

In simple words:
The Moon shines by reflecting sunlight, and its appearance changes as it orbits Earth.
"""
  }


  // ==========================================================
  // DAY AND NIGHT
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "day and night",
        "why day and night",
        "rotation of earth",
        "earth rotation"
      )
    )
  ) {

    return """
WHY DO WE HAVE DAY AND NIGHT?

Step 1:
Earth rotates around its own axis.

Step 2:
The side facing the Sun receives sunlight.

Step 3:
That side experiences daytime.

Step 4:
The side facing away from the Sun experiences nighttime.

Earth takes about 24 hours to complete one rotation relative to the Sun's daily cycle.

In simple words:
Day and night happen because Earth rotates on its axis.
"""
  }


  // ==========================================================
  // SEASONS
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "seasons",
        "season",
        "why seasons occur",
        "summer winter",
        "winter summer"
      )
    )
  ) {

    return """
WHY DO WE HAVE SEASONS?

Seasons mainly occur because:

1. Earth's axis is tilted.
2. Earth revolves around the Sun.
3. The tilt causes different parts of Earth to receive sunlight at different angles and for different lengths of time during the year.

When a hemisphere is tilted toward the Sun:
? It receives more direct sunlight.
? Days are generally longer.
? It experiences warmer conditions.

When it is tilted away:
? Sunlight is less direct.
? Days are generally shorter.
? It experiences cooler conditions.

In simple words:
Earth's tilted axis and its revolution around the Sun cause the seasons.
"""
  }


  // ==========================================================
  // SKY BLUE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "why sky is blue",
        "sky blue",
        "blue sky"
      )
    )
  ) {

    return """
WHY IS THE SKY BLUE?

Step 1:
Sunlight contains many wavelengths of visible light.

Step 2:
Sunlight enters Earth's atmosphere.

Step 3:
Gas molecules in the atmosphere scatter shorter wavelengths of visible light more strongly than longer wavelengths.

Step 4:
Much of the scattered light reaching our eyes from different directions appears blue.

At sunrise and sunset, light travels through a longer path in the atmosphere, so other colors can become more prominent.

In simple words:
The sky appears blue mainly because shorter-wavelength visible light is scattered strongly by Earth's atmosphere.
"""
  }


  // ==========================================================
  // WEATHER
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "weather",
        "climate",
        "humidity",
        "wind",
        "rain",
        "cloud"
      )
    )
  ) {

    return """
WEATHER AND CLIMATE

Weather:
The short-term condition of the atmosphere at a particular place and time.

Weather can include:
? Temperature
? Wind
? Humidity
? Cloud cover
? Rainfall
? Air pressure

Climate:
The long-term pattern of weather conditions in a region.

Humidity:
The amount of water vapour present in the air.

Wind:
Moving air.

Clouds:
They form when water vapour cools and condenses into tiny droplets or ice crystals.

In simple words:
Weather describes short-term atmospheric conditions, while climate describes long-term patterns.
"""
  }


  // ==========================================================
  // RUSTING
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "rusting",
        "rust",
        "why iron rusts",
        "iron rust"
      )
    )
  ) {

    return """
WHY DOES IRON RUST?

Rusting is a chemical process involving iron, oxygen and water or moisture.

Step 1:
Iron is exposed to oxygen.

Step 2:
Water or moisture helps the reaction occur.

Step 3:
Iron slowly changes into hydrated iron oxides, commonly called rust.

Conditions:
Both oxygen and moisture are important for ordinary rusting.

Prevention:
? Painting
? Oiling or greasing
? Coating
? Galvanizing
? Using suitable alloys

In simple words:
Iron rusts when it reacts with oxygen in the presence of moisture.
"""
  }


  // ==========================================================
  // BURNING / COMBUSTION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "combustion",
        "burning",
        "why things burn",
        "fire",
        "fuel"
      )
    )
  ) {

    return """
WHAT IS COMBUSTION?

Combustion is a chemical reaction in which a substance reacts rapidly with oxygen and releases energy, often as heat and sometimes light.

For combustion to continue, three important requirements are commonly represented by the fire triangle:

1. Fuel
2. Oxygen
3. Sufficient heat

Examples:
? Burning wood
? Burning natural gas
? Burning petrol

In simple words:
Combustion is a chemical reaction that releases energy, usually involving oxygen.
"""
  }


  // ==========================================================
  // MICROORGANISMS
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "microorganism",
        "microorganisms",
        "microbe",
        "microbes",
        "bacteria",
        "fungi",
        "protozoa",
        "virus"
      )
    )
  ) {

    return """
WHAT ARE MICROORGANISMS?

Microorganisms are organisms or biological agents that are too small to be seen clearly with the unaided eye.

Examples include:

? Bacteria
? Many fungi
? Protozoa
? Microscopic algae

Viruses are much smaller infectious agents and are not generally classified as cellular organisms.

Microorganisms can be:

Useful:
? Some help make foods such as curd and bread.
? Some help decompose organic matter.
? Some are used in medicine and biotechnology.

Harmful:
? Some cause infectious diseases.
? Some spoil food.

In simple words:
The microscopic world includes many tiny organisms and biological agents, some useful and some harmful.
"""
  }


  // ==========================================================
  // ELECTROMAGNET / ELECTRIC MAGNET
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "electromagnet",
        "electromagnetism",
        "electric magnet"
      )
    )
  ) {

    return """
WHAT IS AN ELECTROMAGNET?

An electromagnet is a magnet produced by electric current.

A simple electromagnet can be made using:

1. A coil of insulated wire.
2. A source of electric current.
3. An iron core placed inside the coil.

When current flows through the coil, it produces a magnetic field.

When the current is switched off, the magnetic effect can greatly decrease for a simple iron-core electromagnet.

Uses include:
? Electric bells
? Relays
? Lifting magnetic materials
? Some electrical devices

In simple words:
An electromagnet is a temporary magnet produced using electric current.
"""
  }


  // ==========================================================
  // PRESSURE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "pressure",
        "air pressure",
        "atmospheric pressure"
      )
    )
  ) {

    return """
WHAT IS PRESSURE?

Pressure describes how much force acts on a given area.

A simple relationship is:

Pressure = Force / Area

This means that for the same force:

? Smaller area -> greater pressure
? Larger area -> smaller pressure

Example:
A sharp needle has a very small tip area, so the force produces high pressure at the tip.

Air also exerts pressure on surfaces around us.

In simple words:
Pressure depends on force and the area over which the force acts.
"""
  }


  // ==========================================================
  // FLOATING / SINKING
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "float",
        "floats",
        "sinks",
        "sink",
        "why ice floats",
        "floating"
      )
    )
  ) {

    return """
WHY DO SOME OBJECTS FLOAT AND OTHERS SINK?

An object in a fluid experiences an upward buoyant force.

Whether it floats or sinks depends on the relationship between:

? The object's weight
? The buoyant force
? The density of the object compared with the fluid

An object with an average density lower than the fluid can float.

An object with an average density greater than the fluid tends to sink.

WHY DOES ICE FLOAT?

Ice is less dense than liquid water, so ice floats on water.

In simple words:
Floating and sinking depend on buoyancy and density.
"""
  }


  // ==========================================================
  // SIMPLE MACHINES
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "simple machine",
        "simple machines",
        "lever",
        "pulley",
        "inclined plane",
        "wheel and axle"
      )
    )
  ) {

    return """
WHAT ARE SIMPLE MACHINES?

Simple machines are devices that help us perform tasks by changing the size or direction of a force.

Examples:

1. Lever
   - A rigid bar that turns around a pivot.

2. Pulley
   - A wheel with a groove used with a rope or similar flexible element.

3. Inclined plane
   - A sloping surface that helps move objects between heights.

4. Wheel and axle
   - A wheel connected to a smaller axle.

5. Screw
   - An inclined plane wrapped around a cylinder.

6. Wedge
   - A moving inclined plane often used for cutting or splitting.

In simple words:
Simple machines make many tasks easier by changing how forces are applied.
"""
  }


  // ==========================================================
  // PLANT PARTS
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "parts of plant",
        "plant parts",
        "root stem leaf",
        "root function",
        "stem function",
        "leaf function"
      )
    )
  ) {

    return """
MAIN PARTS OF A PLANT

1. Roots
   - Anchor the plant.
   - Absorb water and minerals.

2. Stem
   - Supports leaves and other parts.
   - Helps transport water and dissolved substances.

3. Leaves
   - Main sites of photosynthesis in many plants.
   - Exchange gases through stomata.

4. Flowers
   - Reproductive structures in flowering plants.

5. Fruits
   - Develop from the ovary in flowering plants and can help protect seeds.

6. Seeds
   - Contain the embryo and can develop into new plants under suitable conditions.

In simple words:
Different plant parts have different jobs, but they work together to keep the plant alive and help it reproduce.
"""
  }


  // ==========================================================
  // ANIMAL CLASSIFICATION
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "classification of animals",
        "animal classification",
        "vertebrates",
        "invertebrates",
        "vertebrate",
        "invertebrate"
      )
    )
  ) {

    return """
ANIMAL CLASSIFICATION

Animals can be grouped in many ways.

A common school-level grouping is:

VERTEBRATES:
Animals with a backbone.

Major groups include:
? Fish
? Amphibians
? Reptiles
? Birds
? Mammals

INVERTEBRATES:
Animals without a backbone.

Examples include:
? Insects
? Earthworms
? Snails
? Jellyfish

In simple words:
Classification helps us group animals according to shared characteristics.
"""
  }


  // ==========================================================
  // ECLIPSE
  // ==========================================================

  else if (
    hasAny(
      q,
      Array(
        "solar eclipse",
        "lunar eclipse",
        "eclipse"
      )
    )
  ) {

    return """
WHAT IS AN ECLIPSE?

A solar eclipse:
The Moon passes between the Sun and Earth, and the Moon blocks some or all of the Sun's light for observers in certain locations.

A lunar eclipse:
Earth passes between the Sun and Moon, and Earth's shadow falls on the Moon.

Important:
Eclipses do not happen every month because the Moon's orbit is tilted relative to Earth's orbit around the Sun.

In simple words:
An eclipse happens when the Sun, Earth and Moon line up closely enough for one object to block sunlight reaching another.
"""
  }


  // ==========================================================
  // DEFAULT ANSWER
  // ==========================================================

  else {

    if (language == "Hindi") {

      return """
???? ?? ?????? ?? ????? ????? ??? ???? ?????

????? ?? ???? ?????? ????? ??? ?????? ??? ??? ???? ????

????? 6 ?? 8 ?? ??? ?? ?? ?????? ?? ???? ??? ??? ???? ???:

? ?? ?? ???
? ?????????????
? ??????
? ?????
? ???????
? ?????
? ?????
? ??????
? ??????
? ???? ?? ?????
? ??????
? ????
? ??????
? ???? ????
? ????
? ????
? ?????
? ??????
? ??????????
? ???
? ????????
? ????? ????????
? ???????
? ?? ????
? ????
? ??????
? ???????
? ??? ????

??????:
"????? ??? ?????? ???????? ???? ???? ???"
"????? ???? ??????? ???? ???"
"???? ??? ??? ????? ???? ???"

???? ?????? ??? ?? ??? ?????? ??? ??????
"""
    }

    if (language == "Marathi") {

      return """
??? ?? ????????? ???? ????? ???? ???????? ????.

?????? ?????? ??????? ?????? ??????? ?????? ????.

?????? 6 ?? 8 ???? ?????? ?? ??????????? ?????? ????:

? ?? ??? ???
? ?????????????
? ??????
? ?????
? ???????
? ?????
? ??????
? ??????
? ???
? ???? ??? ???????
? ???????
? ???????
? ????
? ????? ????
? ????
? ???
? ?????
? ??????
? ??????????
? ???
? ????????
? ?????????
? ???????
? ??????
? ??????
? ??????
? ?????
? ???????

??????:
"??????? ?????????????? ??? ??????"
"????? ??? ??????? ?????"
"???????? ??? ?? ?????"

????? ?????? ?????? ?????? ??????? ??????.
"""
    }

    return """
I DON'T HAVE A PREPARED ANSWER FOR THAT QUESTION YET.

Try asking your question using simple words.

I can answer many Class 6-8 topics such as:

PHYSICS
? Force
? Motion
? Gravity
? Pressure
? Heat
? Light
? Sound
? Electricity
? Magnets
? Simple machines

CHEMISTRY
? Matter
? Atoms
? Acids and bases
? Mixtures
? Separation methods
? Physical and chemical changes
? Combustion
? Rusting

BIOLOGY
? Cells
? Plants
? Photosynthesis
? Nutrition
? Digestion
? Respiration
? Human body
? Reproduction
? Microorganisms
? Animal classification

ENVIRONMENT
? Ecosystems
? Food chains
? Pollution
? Adaptations
? Water cycle
? Air

EARTH AND SPACE
? Earth
? Moon
? Solar System
? Planets
? Day and night
? Seasons
? Weather
? Eclipses

Try asking:
"Why does ice float on water?"
"How does sound travel?"
"Why does iron rust?"
"How do plants make food?"
"Why do we have day and night?"
"""
  }
}


// ============================================================
// SPEAK FUNCTION
// ============================================================

def speakAnswer(
  text: String
): Unit = {

  try {

    val cleanText =
      text
        .replace("\n", " ")
        .replace("\"", "")
        .replace("'", "")

    val operatingSystem =
      System
        .getProperty("os.name")
        .toLowerCase


    // --------------------------------------------------------
    // WINDOWS
    // --------------------------------------------------------

    if (
      operatingSystem.contains("win")
    ) {

      val safeText =
        cleanText.replace(
          "'",
          "''"
        )

      val command =
        "PowerShell -Command " +
        "\"Add-Type -AssemblyName System.Speech; " +
        "$s = New-Object System.Speech.Synthesis.SpeechSynthesizer; " +
        "$s.Speak('" +
        safeText +
        "')\""

      Runtime
        .getRuntime
        .exec(command)

      statusLabel.setText(
        "Speaking answer..."
      )
    }


    // --------------------------------------------------------
    // MAC
    // --------------------------------------------------------

    else if (
      operatingSystem.contains("mac")
    ) {

      Runtime
        .getRuntime
        .exec(
          Array(
            "say",
            cleanText
          )
        )

      statusLabel.setText(
        "Speaking answer..."
      )
    }


    // --------------------------------------------------------
    // LINUX
    // --------------------------------------------------------

    else {

      Runtime
        .getRuntime
        .exec(
          Array(
            "espeak",
            cleanText
          )
        )

      statusLabel.setText(
        "Speaking answer..."
      )
    }

  }

  catch {

    case error: Exception =>

      JOptionPane.showMessageDialog(
        frame,
        "Voice is not available on this computer.\n\n" +
        "The written answer is still available.",
        "Voice Information",
        JOptionPane.INFORMATION_MESSAGE
      )
  }
}


// ============================================================
// ASK BUTTON
// ============================================================

askButton.addActionListener(
  new ActionListener {

    def actionPerformed(
      event: ActionEvent
    ): Unit = {

      val question =
        questionBox
          .getText
          .trim

      if (
        question.length == 0
      ) {

        JOptionPane.showMessageDialog(
          frame,
          "Please type a science question.",
          "Science Buddy",
          JOptionPane.WARNING_MESSAGE
        )

        questionBox.requestFocus()

      }

      else {

        statusLabel.setText(
          "Science Buddy is thinking..."
        )

        val language =
          languageBox
            .getSelectedItem
            .toString

        val schoolClass =
          classBox
            .getSelectedItem
            .toString

        val subject =
          subjectBox
            .getSelectedItem
            .toString

        val answer =
          getScienceAnswer(
            question,
            language,
            schoolClass,
            subject
          )

        answerBox.setText(
          answer
        )

        answerBox.setCaretPosition(
          0
        )

        statusLabel.setText(
          "Answer ready!"
        )
      }
    }
  }
)


// ============================================================
// SPEAK BUTTON
// ============================================================

speakButton.addActionListener(
  new ActionListener {

    def actionPerformed(
      event: ActionEvent
    ): Unit = {

      val answer =
        answerBox
          .getText
          .trim

      if (
        answer.length == 0
      ) {

        JOptionPane.showMessageDialog(
          frame,
          "Please ask a question first.",
          "Science Buddy",
          JOptionPane.WARNING_MESSAGE
        )

      }

      else {

        speakAnswer(
          answer
        )
      }
    }
  }
)


// ============================================================
// CLEAR BUTTON
// ============================================================

clearButton.addActionListener(
  new ActionListener {

    def actionPerformed(
      event: ActionEvent
    ): Unit = {

      questionBox.setText(
        ""
      )

      answerBox.setText(
        ""
      )

      statusLabel.setText(
        "Ready! Ask any Class 6 - 8 science question."
      )

      questionBox.requestFocus()
    }
  }
)


// ============================================================
// RANDOM QUESTION BUTTON
// ============================================================

exampleButton.addActionListener(
  new ActionListener {

    def actionPerformed(
      event: ActionEvent
    ): Unit = {

      val questions =
        Array(
          "Why do objects fall towards Earth?",
          "How do plants make their food?",
          "What is a cell?",
          "Why does ice float on water?",
          "How is sound produced?",
          "What is an electric circuit?",
          "Why does iron rust?",
          "What is a food chain?",
          "Why is the sky blue?",
          "What are acids and bases?",
          "What is the water cycle?",
          "Why do we have day and night?",
          "What is an atom?",
          "What is photosynthesis?",
          "How does digestion happen?"
        )

      val index =
        (Math.random * questions.length)
          .toInt

      questionBox.setText(
        questions(index)
      )

      statusLabel.setText(
        "Example question loaded. Press ASK."
      )

      questionBox.requestFocus()
    }
  }
)


// ============================================================
// CTRL + ENTER = ASK
// ============================================================

questionBox.addKeyListener(
  new KeyAdapter {

    override def keyPressed(
      event: KeyEvent
    ): Unit = {

      if (
        event.getKeyCode == KeyEvent.VK_ENTER &&
        event.isControlDown
      ) {

        askButton.doClick()
      }
    }
  }
)


// ============================================================
// ENTER KEY ON COMBO BOXES
// ============================================================

classBox.addActionListener(
  new ActionListener {

    def actionPerformed(
      event: ActionEvent
    ): Unit = {

      statusLabel.setText(
        "Selected " +
        classBox.getSelectedItem.toString +
        ". Ask your question."
      )
    }
  }
)


// ============================================================
// WINDOW
// ============================================================

frame.setLocationRelativeTo(
  null
)

frame.setVisible(
  true
)

questionBox.requestFocus()