Skip to main content

Day 1: Student Management System (Basic Project)

Student Management System (Basic Project)

Project Description

We will create a simple Student Management System. This project will help you understand the core concepts of Java, including:

1. Classes and Objects
2. Variables and Data Types
3. Methods (Functions)
4. Input/Output (Scanner Class)
5. Loops and Conditionals

Step-by-Step Explanation

Step 1: Plan the Project

The system should do the following:

1. Add student details (name, age, marks).
2. Display student details.
3. Exit the program.

Step 2: Create the Blueprint (Class)

We’ll create a Student class to represent each student.

What is a class?
- A class is like a blueprint or template.

In our case, the blueprint is "Student," and each real student will be an object.

Code Example:

class Student {
    String name; // Variable to store the name
    int age;     // Variable to store the age
    double marks; // Variable to store the marks
}

Explanation:

1. String name: Stores the name of the student (text).
2. int age: Stores the age (whole number).
3. double marks: Stores the marks (decimal numbers).

Step 3: Write the Main Logic

The main method controls how the program runs.

What is the main method?
- It is the starting point of any Java program.


We will:

1. Use the Scanner class to take input from the user.
2. Use a loop to repeatedly show options (add student, display student, exit).

Full Code for Day 1 Project

import java.util.Scanner; // Import Scanner for user input

class Student {
    String name; // Student's name
    int age;     // Student's age
    double marks; // Student's marks
}

public class StudentManagementSystem {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in); // Create Scanner object
        Student student = new Student(); // Create a Student object

        while (true) {
            // Display menu
            System.out.println("\n--- Student Management System ---");
            System.out.println("1. Add Student Details");
            System.out.println("2. Display Student Details");
            System.out.println("3. Exit");
            System.out.print("Enter your choice: ");
            int choice = scanner.nextInt(); // Take user input

            // Process user's choice
            switch (choice) {
                case 1: // Add Student Details
                    System.out.print("Enter Student Name: ");
                    scanner.nextLine(); // Consume leftover newline
                    student.name = scanner.nextLine(); // Read name
                    System.out.print("Enter Student Age: ");
                    student.age = scanner.nextInt(); // Read age
                    System.out.print("Enter Student Marks: ");
                    student.marks = scanner.nextDouble(); // Read marks
                    System.out.println("Student details added successfully!");
                    break;

                case 2: // Display Student Details
                    System.out.println("\n--- Student Details ---");
                    System.out.println("Name: " + student.name);
                    System.out.println("Age: " + student.age);
                    System.out.println("Marks: " + student.marks);
                    break;

                case 3: // Exit
                    System.out.println("Exiting... Goodbye!");
                    System.exit(0); // End program
                    break;

                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }
}

Detailed Explanation

1. Import the Scanner Class:

import java.util.Scanner;
This allows us to take input from the user (e.g., name, age, marks).

2. Create a Class:

class Student: 
Blueprint to define what a "Student" is.

We define the student’s name, age, and marks inside this class.



3. Main Class and Method:

public class StudentManagementSystem: Main program class.

public static void main(String[] args): Entry point where the program starts.



4. Using Loops and Switch:

The while (true) loop keeps showing the menu until the user chooses to exit.

switch (choice) processes user choices:
Option 1: Add student details.
Option 2: Display stored details.
Option 3: Exit the program.




5. Taking User Input:

scanner.nextLine(), scanner.nextInt(), and scanner.nextDouble() are used to take different types of input.



6. Exit Command:

System.exit(0) stops the program when the user chooses to exit.

Tasks for You:

1. Run the Program:
Copy this code into any Java IDE (like IntelliJ IDEA, Eclipse, or VS Code) or online compiler and run it.


2. Experiment:
Try adding more students (you'll notice the code only works for one student; we’ll fix this in a future project).

Add new fields like "Class" or "Roll Number."



3. Think:
What if you want to store multiple students? Tomorrow, we’ll enhance this project with arrays or ArrayLists to handle multiple students!


Interview Questions Based on This Project

1. What is a Class in Java?

A class is a blueprint for creating objects. It defines the data and behavior of the object.



2. What is an Object in Java?

An object is an instance of a class. It is created using the new keyword.



3. What is the Scanner class used for?

It is used to take input from the user in Java.



4. What is the difference between int, double, and String in Java?

int: Stores whole numbers (e.g., 10).
double: Stores decimal numbers (e.g., 10.5).
String: Stores text (e.g., "Hello").


Comments

Popular posts from this blog

What is Java? A Complete Beginner Guide to Java as a Language and Platform || FSJD-01-24-05

☕ What is Java? A Beginner-Friendly Guide to Java as a Language and Platform Are you just stepping into the world of programming? Or preparing for that first tech interview and trying to make sense of Java? Don’t worry — you're in the right place. Java isn’t just a coding language; it’s a whole ecosystem. In this beginner-friendly post, we’ll break down what Java really is — in simple terms — so you can start your learning journey with clarity and confidence. 🧠 So… What Exactly is Java? Java is both a programming language AND a platform . Yes — it’s more than just lines of code. Java provides a complete environment that lets you build applications for almost any device — from laptops to smartphones to smart TVs and more. 💻 Java as a Programming Language Java was created by James Gosling and his team at Sun Microsystems (now owned by Oracle ) and officially released in 1995 . Let’s break down what makes Java special as a language: ✅ High-Level Easy to read and wr...

☕ Understanding the Structure of a Java Program – Documentation || FSJD-07-29-05

☕ Understanding the Structure of a Java Program – A Beginner to Pro Guide “An investment in knowledge pays the best interest.” — Benjamin Franklin If you’re starting your journey in Java, the structure of a Java program is one of the first and most important things you should understand. Whether you're preparing for interviews or writing your first piece of code, a strong foundation can set you up for success. In this blog, we’ll break down the complete anatomy of a Java program — from the documentation section to the main() method — and explain each component in simple yet professional terms. 📋 Step-by-Step: How to Prepare Your First Java Program Before writing a Java program, follow these key steps: Download & Install Java Software Install the Java Development Kit (JDK) Choose an editor or IDE (like VS Code , IntelliJ , or Eclipse ) Understand the Java Program Structure Learn Java naming conventions Understand different sections o...

🔰 Java Software Setup Guide for Beginners || FSJD-05-29-05

  🔰 Java Software Setup Guide for Beginners By: Tahir | For Interview Prep & Fresh Learning “An investment in knowledge pays the best interest.” – Benjamin Franklin Whether you’re starting out with Java or brushing up for interviews, setting up the right environment is your first and most important step. In this post, I’ll walk you through the essential tools and software needed to start coding in Java, using simple language and clear concepts. 🚀 What Do You Need to Start Java Programming? To begin Java development, you need three main things: 1. JDK (Java Development Kit) The JDK is the core software you need to write, compile, and run Java programs. ✅ What Is JDK? The Java Development Kit is a package of tools that allows developers to write Java programs. It includes: A compiler ( javac ) to convert Java code into bytecode The Java Runtime Environment (JRE) to run the bytecode Development tools and libraries 📌 Important JDK Versions: Java S...