[Go to site: main page, start]

0% found this document useful (0 votes)
2 views11 pages

Java Programming

The document outlines several Java programming assignments, including a Student Marks Analysis System, a Simple Banking System, a Number Guessing Game, a Palindrome Checker, and an Odd-Even Sum Calculator. Each case study includes a scenario description and corresponding Java code to implement the functionality. The assignments cover various programming concepts such as variables, arrays, methods, and control flow statements.

Uploaded by

Kanishkar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Java Programming

The document outlines several Java programming assignments, including a Student Marks Analysis System, a Simple Banking System, a Number Guessing Game, a Palindrome Checker, and an Odd-Even Sum Calculator. Each case study includes a scenario description and corresponding Java code to implement the functionality. The assignments cover various programming concepts such as variables, arrays, methods, and control flow statements.

Uploaded by

Kanishkar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA PROGRAMMING

ASSIGNMENT 2
CASE STUDY

NAME: KANISHKAR.S

ROLLNO: 2022103713

CLASS: CSE P BATCH 6TH SEMESTER


DATE: 25.01.2025
Topics Covered: Variables, Arrays, Methods, Control Flow Statements
11) Student Marks Analysis System
Scenario: A school needs a program to:

1. Input marks of students in 3 subjects.


2. Calculate the total and average marks for each student.
3. Identify the topper with the highest total marks.

Code:
import [Link];

public class ex1 {

public static void main(String[] args) {

ArrayList<Student> students = new ArrayList<>();

[Link](new Student("Alice", 85, 90, 78));

[Link](new Student("Bob", 88, 76, 92));

[Link](new Student("Charlie", 90, 91, 85));

Student topper = null;

for (Student student : students) {

[Link]();

[Link]([Link]() + " - Total: " + [Link]() + ", Average: " +


[Link]());

if (topper == null || [Link]() > [Link]()) {

topper = student;

[Link]("Topper: " + [Link]() + " with Total Marks: " + [Link]());

class Student {

private String name;

private int subject1, subject2, subject3;

private int totalMarks;


private double averageMarks;

public Student(String name, int subject1, int subject2, int subject3) {

[Link] = name;

this.subject1 = subject1;

this.subject2 = subject2;

this.subject3 = subject3;

public void calculateTotalAndAverage() {

totalMarks = subject1 + subject2 + subject3;

averageMarks = totalMarks / 3.0;

public String getName() {

return name;

public int getTotalMarks() {

return totalMarks;

public double getAverageMarks() {

return averageMarks;

Output:
12)Case Study 12: Simple Banking System
Scenario: Develop a banking system that allows:
1. Depositing money.
2. Withdrawing money.
3. Checking the current balance.
Code:
package classwork;
import [Link];
public class BankingSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
BankAccount account = new BankAccount();
while (true) {
[Link]("\n1. Deposit Money");
[Link]("2. Withdraw Money");
[Link]("3. Check Balance");
[Link]("4. Exit");
[Link]("Enter your choice: ");
int choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter amount to deposit: ");
double depositAmount = [Link]();
[Link](depositAmount);
break;
case 2:
[Link]("Enter amount to withdraw: ");
double withdrawAmount = [Link]();
[Link](withdrawAmount);
break;
case 3:
[Link]("Current Balance: " + [Link]());
break;
case 4:
[Link]("Exiting...");
[Link]();
return;
default:
[Link]("Invalid choice. Try again.");
}
}
}
}
class BankAccount {
private double balance;
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
[Link]("Deposited: " + amount);
} else {
[Link]("Invalid amount.");
}
}

public void withdraw(double amount) {


if (amount > 0 && amount <= balance) {
balance -= amount;
[Link]("Withdrawn: " + amount);
} else {
[Link]("Insufficient balance or invalid amount.");
}
}
public double getBalance() {
return balance;
}
}
Output:
13)Number Guessing Game

Topics Covered: Control Flow Statements, Operators


Scenario: Create a game where the user guesses a randomly generated number between 1 and 100.
● The program should provide hints like "Too high" or "Too low" for incorrect guesses.
● End the game when the user guesses correctly.
Code:
import [Link];
import [Link];
public class NumberGuessingGame {
public static void main(String[] args) {
Random random = new Random();
Scanner scanner = new Scanner([Link]);
int numberToGuess = [Link](100) + 1;
int userGuess;
[Link]("Guess the number between 1 and 100!");
while (true) {
[Link]("Enter your guess: ");
userGuess = [Link]();
if (userGuess == numberToGuess) {
[Link]("Congratulations! You guessed the correct number: " + numberToGuess);
break;
} else if (userGuess > numberToGuess) {
[Link]("Too high! Try again.");
} else {
[Link]("Too low! Try again.");
}
}
[Link]();
}
}
Output:
14) Case Study 14: Palindrome Checker
Scenario: Create a program to check if a given word or phrase is a palindrome (reads the same backward
as forward).
Code:
import [Link];
public class PalindromeChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a word or phrase: ");
String input = [Link]();
String cleanedInput = [Link]("[^a-zA-Z0-9]", "").toLowerCase();
String reversedInput = new StringBuilder(cleanedInput).reverse().toString();
if ([Link](reversedInput)) {
[Link]("The input is a palindrome.");
} else {
[Link]("The input is not a palindrome.");
}
[Link]();
}
}
Output:
15) Case Study 15: Odd-Even Sum Calculator
Topics Covered: Variables, Arrays, Control Flow Statements
Scenario:
Write a program to:
1. Accept an array of integers from the user.
2. Calculate the sum of odd and even numbers separately.
Code:
import [Link];
public class OddEvenSumCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of elements in the array: ");
int n = [Link]();
int[] numbers = new int[n];
[Link]("Enter the elements of the array:");
for (int i = 0; i < n; i++) {
numbers[i] = [Link]();
}
int oddSum = 0, evenSum = 0;
for (int num : numbers) {
if (num % 2 == 0) {
evenSum += num;
} else {
oddSum += num;
}
}
[Link]("Sum of even numbers: " + evenSum);
[Link]("Sum of odd numbers: " + oddSum);
[Link]();
}
}
Output:

You might also like