π§ Day 5 β MoodPlay | #30Days30Projects

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
Concept | Description |
Enum | Used to represent fixed moods like HAPPY, SAD, ROMANTIC, etc. |
Switch | Handle different cases for each mood cleanly. |
ArrayList | Store song names under each mood. |
Random | Fetch random songs from the mood list each time for variety. |
ANSI Codes | Add 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
Subscribe to my newsletter
Read articles from Rushikesh Unge directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
