🎧 Day 5 β€” MoodPlay | #30Days30Projects

Rushikesh UngeRushikesh Unge
3 min read

On Day 5 of my #30DaysJavaCLI challenge, I wanted to combine something fun and personal with my learning: music and mood. So I built MoodPlay, a Java CLI app that recommends Hindi and Marathi songs based on the user’s current mood.

This project helped me strengthen my knowledge of:

  • Enums

  • Switch statements

  • ArrayLists

  • Randomization

  • Console styling for better UX

Let’s dive into it.


🧠 Project Idea

The idea is simple but meaningful:

Ask the user about their mood (like happy, sad, energetic, romantic), and suggest a list of 3 random songs from a preset list tailored to that emotion.


πŸ“š Concepts Covered

ConceptDescription
EnumUsed to represent fixed moods like HAPPY, SAD, ROMANTIC, etc.
SwitchHandle different cases for each mood cleanly.
ArrayListStore song names under each mood.
RandomFetch random songs from the mood list each time for variety.
ANSI CodesAdd colorful styling to CLI output for better aesthetics.

πŸ“‚ Folder Structure

MoodPlay/
β”‚
β”œβ”€β”€ src/
β”‚   └── MoodPlay.java
└── README.md

You can run this directly using any Java IDE or from CLI.


🧩 Code: MoodPlay.java

package src;

import java.util.*;

public class MoodPlay {

    enum Mood {
        HAPPY, SAD, ENERGETIC, ROMANTIC
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        printBanner();

        System.out.println("\u001B[34mWhat's your current mood?\u001B[0m");
        System.out.println("Options: Happy, Sad, Energetic, Romantic");

        String userInput = sc.nextLine().trim().toUpperCase();

        try {
            Mood mood = Mood.valueOf(userInput);
            suggestSongs(mood);
        } catch (IllegalArgumentException e) {
            System.out.println("\u001B[31mOops! Invalid mood entered. Please try again.\u001B[0m");
        }

        sc.close();
    }

    private static void suggestSongs(Mood mood) {
        Map<Mood, List<String>> moodSongs = new HashMap<>();

        moodSongs.put(Mood.HAPPY, Arrays.asList(
                "Zhingaat – Sairat",
                "Gallan Goodiyan – Dil Dhadakne Do",
                "Kar Gayi Chull – Kapoor & Sons",
                "Apsara Aali – Natarang",
                "Zinda – Bhaag Milkha Bhaag",
                "Senorita – Zindagi Na Milegi Dobara"
        ));

        moodSongs.put(Mood.SAD, Arrays.asList(
                "Channa Mereya – Ae Dil Hai Mushkil",
                "Agar Tum Saath Ho – Tamasha",
                "Kadhi Tu – Timepass",
                "Tadap Tadap – Hum Dil De Chuke Sanam",
                "Apna Time Aayega (Slow version)",
                "Mala Ved Lagale Premache – Timepass"
        ));

        moodSongs.put(Mood.ROMANTIC, Arrays.asList(
                "Tum Hi Ho – Aashiqui 2",
                "Tujh Mein Rab Dikhta Hai – Rab Ne Bana Di Jodi",
                "Satrangi Re – Dil Se",
                "Pehli Nazar – Race",
                "Jeene Laga Hoon – Ramaiya Vastavaiya",
                "Man Udhaan Varyache – Agga Bai Arrecha!"
        ));

        moodSongs.put(Mood.ENERGETIC, Arrays.asList(
                "Bhaag DK Bose – Delhi Belly",
                "Zinda – Bhaag Milkha Bhaag",
                "Malhari – Bajirao Mastani",
                "Aala Holicha San – Jatra",
                "Apna Time Aayega – Gully Boy",
                "Sher Aaya Sher – Gully Boy"
        ));

        List<String> songs = moodSongs.get(mood);
        Collections.shuffle(songs);

        System.out.println("\n\u001B[32m🎡 Here are some " + mood.name().toLowerCase() + " songs for you:\u001B[0m");

        for (int i = 0; i < 3; i++) {
            System.out.println("  ➀ " + songs.get(i));
        }

        System.out.println("\n\u001B[35mEnjoy your vibe! 🎧\u001B[0m");
    }

    private static void printBanner() {
        System.out.println("\u001B[36m===============================");
        System.out.println("       Welcome to MoodPlay       ");
        System.out.println("===============================\u001B[0m");
    }
}

πŸ’» Sample Output

Case 1: Happy Mood

===============================
       Welcome to MoodPlay       
===============================
What's your current mood?
Options: Happy, Sad, Energetic, Romantic
happy

🎡 Here are some happy songs for you:
  ➀ Gallan Goodiyan – Dil Dhadakne Do
  ➀ Senorita – Zindagi Na Milegi Dobara
  ➀ Apsara Aali – Natarang

Enjoy your vibe! 🎧

Case 2: Invalid Input

What's your current mood?
Options: Happy, Sad, Energetic, Romantic
bored

Oops! Invalid mood entered. Please try again.

πŸ” What I Learned

  • How Enum makes handling predefined categories like moods clean and error-proof.

  • Mapping moods to songs using HashMap.

  • Styling terminal output with ANSI escape codes to make Java CLI more visually appealing.

  • Using Collections.shuffle() to randomize recommendations for freshness.


βœ… What's Next?

For future improvements, I might:

  • Integrate an actual API like Spotify or YouTube to play the songs.

  • Add a GUI using Java Swing.

  • Let users save their favorite tracks to a local file.

Github Repo - https://github.com/Rushi-Unge/30Days30Projects

0
Subscribe to my newsletter

Read articles from Rushikesh Unge directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rushikesh Unge
Rushikesh Unge