DEV Community

Vigneshwaralingam
Vigneshwaralingam

Posted on

🧠 Day 5 — Programming With Stories & Logic

Java Programming Session


Day 5 Java Programming Session

  • 📜 Story format for every problem
  • 🧠 Real-world inspiration
  • 📚 Bonus facts (Shakuntala Devi, Python versions, Arvind Gupta)

🌟 1. Printing the First N Numbers — "The Birthday Party Story"

Ravi wanted to invite his 10 friends to his birthday party.

He wrote each of their invitation numbers on cards using his robot — one by one.

public class PartyInviter { public static void main(String[] args) { int i = 1; int n = 10; while (i <= n) { System.out.println("Invitation sent to Friend #" + i); i++; } } } 
Enter fullscreen mode Exit fullscreen mode

📌 Moral: Simple repetitions can solve daily problems smartly.


🐸 2. The Frog Wheel Theory — "The Frog in the Well"

A frog was stuck inside a 20-meter well.

Each day it jumps up 3 meters, but by the next morning, it’s back 2 meters lower.

Let’s simulate its daily journey.

public class FrogInWell { public static void main(String[] args) { int height = 20; int pos = 0; int day = 0; while (pos < height) { day = day + 1; pos = pos + 3; pos = pos - 2; } System.out.println("Frog escapes in " + day + " days."); } } 
Enter fullscreen mode Exit fullscreen mode

🧠 Realization: Progress is still progress, even if slow!


👑 3. Raja Manthiri & Magical Paddy Story — "The Grain Doubling Tale"

The minister asked King Manghiri for 1 grain on Day 1, doubling it each day.

The king agreed for 10 days, unaware of the magic of doubling.

public class GrainDoubling { public static void main(String[] args) { int day = 1; int totalDays = 10; long grain = 1; long total = 0; while (day <= totalDays) { total = total + grain; grain = grain * 2; day = day + 1; } System.out.println("Total grains after 10 days: " + total); } } 
Enter fullscreen mode Exit fullscreen mode

📌 Moral: Even the smallest request, when doubled, becomes massive!


🕵️ 4. Shakuntala Devi Puzzle — "The Thief & Police Story"

A thief runs at 2 m/s, and a police officer at 5 m/s, starting 40 meters apart.

Let’s track the seconds until the police catches up.

public class ThiefPolice { public static void main(String[] args) { int thief = 0; int police = -40; int time = 0; while (police < thief) { thief = thief + 2; police = police + 5; time = time + 1; } System.out.println("Police catches thief in " + time + " seconds."); } } 
Enter fullscreen mode Exit fullscreen mode

📌 Moral: Speed difference matters more than distance.


🔍 Extra Learnings

🎯 Shakuntala Devi – “The Human Computer”

  • Born: November 4, 1929 (India)
  • Solved 13-digit math in just 28 seconds
  • Guinness World Record holder
  • Book: Figuring: The Joy of Numbers

“Numbers have life; they’re not just symbols on paper.”


🐍 Python on Linux – What’s Fabricated?

  • Linux often includes Python 2 and Python 3
  • You may need to install Python 3 manually:
 sudo apt install python3 
Enter fullscreen mode Exit fullscreen mode
  • Fabricated = artificially constructed or created.

👨‍🔧 Who is Arvind Gupta?

  • Indian scientist, teacher & toy inventor
  • Builds science toys from trash ♻️
  • TED Speaker, inspires learning through fun
  • Website: arvindguptatoys.com

“Children learn by doing, not by mugging.”


Top comments (0)