forked from Sbiswas001/Basic-java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentUtilityApp.java
More file actions
146 lines (129 loc) · 5.66 KB
/
StudentUtilityApp.java
File metadata and controls
146 lines (129 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ================================================================
// StudentUtilityApp.java
// ---------------------------------------------------------------
// Author: Agnibesh Maity
// Description:
// A complete beginner-friendly Java program that demonstrates
// multiple basic programming concepts in one place.
// It allows the user to:
// 1. Calculate Sum of Numbers
// 2. Check Even or Odd
// 3. Find Factorial
// 4. Generate Fibonacci Series
// 5. Display Simple Student Info
// ---------------------------------------------------------------
// Version: 1.0
// Created: October 2025
// ================================================================
import java.util.Scanner;
public class StudentUtilityApp {
// ------------------------------------------------------------
// 1. Sum of two numbers
// ------------------------------------------------------------
public static void sumOfNumbers(Scanner sc) {
System.out.println("\n--- SUM OF TWO NUMBERS ---");
System.out.print("Enter first number: ");
int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();
System.out.println("✅ The sum is: " + (a + b));
}
// ------------------------------------------------------------
// 2. Check Even or Odd
// ------------------------------------------------------------
public static void checkEvenOdd(Scanner sc) {
System.out.println("\n--- EVEN OR ODD CHECKER ---");
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num % 2 == 0)
System.out.println("✅ " + num + " is Even.");
else
System.out.println("✅ " + num + " is Odd.");
}
// ------------------------------------------------------------
// 3. Factorial Calculator
// ------------------------------------------------------------
public static void factorialCalculator(Scanner sc) {
System.out.println("\n--- FACTORIAL CALCULATOR ---");
System.out.print("Enter a number: ");
int n = sc.nextInt();
long fact = 1;
for (int i = 1; i <= n; i++)
fact *= i;
System.out.println("✅ Factorial of " + n + " = " + fact);
}
// ------------------------------------------------------------
// 4. Fibonacci Series Generator
// ------------------------------------------------------------
public static void fibonacciSeries(Scanner sc) {
System.out.println("\n--- FIBONACCI SERIES GENERATOR ---");
System.out.print("Enter number of terms: ");
int n = sc.nextInt();
int a = 0, b = 1, c;
System.out.print("📘 Fibonacci Series: ");
for (int i = 1; i <= n; i++) {
System.out.print(a + " ");
c = a + b;
a = b;
b = c;
}
System.out.println();
}
// ------------------------------------------------------------
// 5. Display Student Information
// ------------------------------------------------------------
public static void studentInfo(Scanner sc) {
sc.nextLine(); // consume newline
System.out.println("\n--- STUDENT INFORMATION ---");
System.out.print("Enter your name: ");
String name = sc.nextLine();
System.out.print("Enter your department: ");
String dept = sc.nextLine();
System.out.print("Enter your roll number: ");
String roll = sc.nextLine();
System.out.println("\n🎓 STUDENT PROFILE 🎓");
System.out.println("--------------------------");
System.out.println("Name: " + name);
System.out.println("Department: " + dept);
System.out.println("Roll No.: " + roll);
System.out.println("--------------------------");
System.out.println("✨ Welcome, " + name + "! Keep learning and growing.");
}
// ------------------------------------------------------------
// Main Menu
// ------------------------------------------------------------
public static void mainMenu() {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("\n==============================================");
System.out.println("🎯 STUDENT UTILITY APP - MULTI PURPOSE TOOL 🎯");
System.out.println("==============================================");
System.out.println("1️⃣ Calculate Sum of Two Numbers");
System.out.println("2️⃣ Check Even or Odd");
System.out.println("3️⃣ Find Factorial");
System.out.println("4️⃣ Generate Fibonacci Series");
System.out.println("5️⃣ Display Student Information");
System.out.println("6️⃣ Exit");
System.out.println("----------------------------------------------");
System.out.print("Enter your choice (1-6): ");
choice = sc.nextInt();
switch (choice) {
case 1 -> sumOfNumbers(sc);
case 2 -> checkEvenOdd(sc);
case 3 -> factorialCalculator(sc);
case 4 -> fibonacciSeries(sc);
case 5 -> studentInfo(sc);
case 6 -> System.out.println("\n👋 Exiting... Thank you for using StudentUtilityApp!");
default -> System.out.println("\n⚠️ Invalid choice! Please try again.");
}
} while (choice != 6);
sc.close();
}
// ------------------------------------------------------------
// Program Entry Point
// ------------------------------------------------------------
public static void main(String[] args) {
mainMenu();
}
}