Java Programming Day 8

β¨ Java Day 8 β Slot Machine Game π° + Car Class π + Real OOP Stuff π οΈ
Hey guys! So today was honestly one of the most fun + productive Java days so far. I played around with three different programs β and guess what? Each one taught me something completely different while still connecting the dots around OOP, game logic, and real-life implementation.
Let me walk you through everything I coded today β trust me, youβll relate if youβre just starting out like me.
π° 1. SLOT MACHINE GAME β My First Java Game!
Okay so this one? Pure fun. I built a slot machine game using basic Java concepts, and wow, it was so satisfying watching it work.
πΉ What it does:
You basically start with βΉ100, and you place bets. Then 3 random symbols (emojis) pop up.
If two or three of them match, you win! If not⦠well, you lose that round's bet. But the game keeps going until your balance is gone or you decide to quit.
π§ What I used:
Random
for generating the symbolsScanner
for user input (bet, continue/stop)Basic loops and if-else conditions
And of courseβ¦ emojis for β¨aestheticβ¨
π₯οΈ Code:
javaCopyEditimport java.util.*;
public class SlotMachine {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random rand = new Random();
String[] symbols = {"π", "π", "π", "π", "π"};
int balance = 100;
System.out.println("π° Welcome to JAVA Slot Machine!");
System.out.println("Symbols: πππππ");
while (balance > 0) {
System.out.println("π° Current Balance: βΉ" + balance);
System.out.print("Place your bet: ");
int bet = scanner.nextInt();
if (bet > balance || bet <= 0) {
System.out.println("β Invalid bet amount!");
continue;
}
String sym1 = symbols[rand.nextInt(symbols.length)];
String sym2 = symbols[rand.nextInt(symbols.length)];
String sym3 = symbols[rand.nextInt(symbols.length)];
System.out.println("Spinning...");
System.out.println(sym1 + " | " + sym2 + " | " + sym3);
if (sym1.equals(sym2) && sym2.equals(sym3)) {
int winnings = bet * 5;
balance += winnings;
System.out.println("π Jackpot! You won βΉ" + winnings);
} else if (sym1.equals(sym2) || sym2.equals(sym3)) {
int winnings = bet * 2;
balance += winnings;
System.out.println("π Nice! You won βΉ" + winnings);
} else {
balance -= bet;
System.out.println("π You lost this round.");
}
System.out.print("Play again? (yes/no): ");
String choice = scanner.next();
if (!choice.equalsIgnoreCase("yes")) {
break;
}
}
System.out.println("Game over! Final balance: βΉ" + balance);
}
}
π What I learned:
This helped me practice loops, input/output, and conditions in a real-world game format.
Also, the logic for checking symbol matches made me think through the steps properly. π
π 2. CAR CLASS β Understanding OOP Better
I know Iβve done basic classes before, but today I made my first meaningful class for a real-world object: a Car.
πΉ What this class does:
Has 4 main attributes:
make
,model
,year
,price
Uses 4 methods:
start()
,stop()
,drive()
,brake()
Uses a boolean variable
isRunning
to track car status
It literally feels like I made my own car in Java β I can start it, drive it, and even brake it ππ
π₯οΈ Car Class Code:
javaCopyEditpublic class Car {
String make = "Toyota";
String model = "Corolla";
int year = 2020;
double price = 1500000.0;
boolean isRunning = false;
void start() {
isRunning = true;
System.out.println("π Car started.");
}
void stop() {
isRunning = false;
System.out.println("π Car stopped.");
}
void drive() {
if (isRunning) {
System.out.println("π Car is driving.");
} else {
System.out.println("β οΈ Start the car first!");
}
}
void brake() {
System.out.println("π¦ Car is braking.");
}
}
π What I learned:
How to design a class like an actual real-world entity
Importance of
boolean
flags (likeisRunning
) to maintain statesIt helped me get more comfortable with method calling + object behavior
π οΈ 3. MAIN CLASS β Connecting the Car with the Main Program
This one is short, but so important.
I used this Main
class to create an object of the Car
class and call all its methods in a sequence. This gave me full confidence in how classes and objects interact in Java.
π₯οΈ Main Class Code:
javaCopyEditpublic class Main {
public static void main(String[] args) {
Car car = new Car();
System.out.println("π Car Details:");
System.out.println("Make: " + car.make);
System.out.println("Model: " + car.model);
System.out.println("Year: " + car.year);
System.out.println("Price: βΉ" + car.price);
System.out.println("Running Status: " + car.isRunning);
car.start();
System.out.println("Running Status: " + car.isRunning);
car.drive();
car.brake();
car.stop();
System.out.println("Running Status: " + car.isRunning);
}
}
π What I learned:
How to use the Car object inside another file
Got super clear on how data and behavior travel with objects
Also practiced the use of dot operator to access variables/methods
π Summary: What Java Day 8 Gave Me
Concept | My Takeaway |
Game Logic | Loops, Random, Conditions β all came together in a fun way! |
OOP Basics | I finally feel confident creating and using my own custom class β¨ |
Real-life Mapping | Whether itβs a car or a slot machine, Java is powerful for simulations |
π«Ά Final Thoughts
I feel really proud of Day 8, not because I did something super complex β but because I actually enjoyed it, saw the output, and understood everything I wrote.
I also realized how Java is not just theory, it's literally a way to build small cool things from imagination. From today onwards, Iβll try to blend creativity + code every day π‘π»
Subscribe to my newsletter
Read articles from Himanshi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Himanshi
Himanshi
Hi! I'm a curious and self-driven programmer currently pursuing my BCA π and diving deep into the world of Java β from Day 1. I already have a foundation in programming, and now I'm expanding my skills one concept, one blog, and one project at a time. Iβm learning Java through Bro Codeβs YouTube tutorials, experimenting with code, and documenting everything I understand β from basic syntax to real-world applications β to help others who are just starting out too. I believe in learning in public, progress over perfection, and growing with community support. Youβll find beginner-friendly Java breakdowns, hands-on code snippets, and insights from my daily coding grind right here. π‘ Interests: Java, Web Dev, Frontend Experiments, AI-curiosity, Writing & Sharing Knowledge π οΈ Tools: Java β’ HTML/CSS β’ JavaScript β’ Python (basics) β’ SQL π― Goal: To become a confident Full Stack Developer & AI Explorer π Based in India | Blogging my dev journey #JavaJourney #100DaysOfCode #CodeNewbie #LearnWithMe