Professional Documents
Culture Documents
JPR .MICROPRO1.
JPR .MICROPRO1.
PROJECT REPORT
ON
SUBMITTED TO
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION, MUMBAI
SUBMITTED BY
In partial fulfillment of the requirements for the award of the Diploma in Computer
engineering and submitted to the Department of Computer of Samarth Polytechnic,
Belhe work carried out during a period for the academic year 2023-24 as per
curriculum .
2
ACKNOWLEDGMENT
I am really thankful to our course the Principal Prof. Kapile A.S. and the HOD Prof.Navale
S.K. Samarth Polytechnic, Belhe for his invaluable guidance and assistance, without
which the accomplishment of the task would have never been possible.
I also thanks Prof. Borude A.S. for giving this opportunity to explore into the real world
and realize the interrelation without which a Project can never progress. In this
present project I have chosen the topic-“Switch Case Statement ”
3
ANNEXUREII
Evaluation Sheet for Micro Project
Academic Year:-2023-24 Name of Faculty:- Prof. Borude A.S. Course:-Computer engineering
Course Code :- CO-4-I Subject Code :- 22412 Semester:- IV
Marksoutof6 Marksoutof4
For performance Forperformance in
Roll Student Name in group oral / Total out of 10
No. activity(D5 Col.8) presentation(D5
Col.9)
4
INDEX
Sr no. Name of content Page no.
01 Intoduction 6
02 Switch Case Statement 7
03 Adavantages of Switch Case 11
04 Disadvantages Of Swich Case 12
05 Flow Diagram Of Switch Case 13
Statement
06 Rules for Switch Statements 14
07 Source Code 17
08 Output Of Program 19
09 Conclusion and Cource 20
outcomes(Cos)
10 Referance 21
5
Intoduction :-
The basic idea behind using a switch case statement for calculating the area of
different shapes is to prompt the user to select a shape, read the user input,
and then use a switch statement to perform the appropriate calculation for
the selected shape. Each case in the switch statement corresponds to a
specific shape, and the program calculates the area of that shape using the
appropriate formula.
Using switch case statements for calculating the area of different shapes
allows for easy expansion of the program to include additional shapes without
requiring significant modifications to the code. The switch case statement
makes it simple to add more cases as required and eliminates the need for
complex if-else statements.
6
Switch Case Statement:-
A switch case statement is a control flow statement used in many
programming languages to perform different actions based on different
values of a single variable or expression. It allows you to check the value of a
variable or expression against a list of possible values and execute a block of
code corresponding to the matching value.
switch (expression)
{ case value1:
break;
case value2:
break;
needed default:
break;
7
In this code, `expression` is the variable or expression to evaluate, and each
`case` is a possible value that the expression could have. When the expression
matches one of the values in the cases, the code corresponding to that case is
executed. The `break` statement is used to exit the switch case block and
continue executing the rest of the code after the block.
The `default` case is optional and is executed when none of the cases match
the expression. It is often used as a catch-all to handle unexpected values.
Switch case statements are commonly used in situations where you want to
perform different actions based on the value of a variable or expression, such
as in menu-driven programs, calculator applications, and games.
let day = new Date().getDay(); // Get the current day of the week (0-6)
let dayName;
switch (day)
{ case 0:
dayName =
"Sunday"; break;
case 1:
dayName = "Monday";
break;
8
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
default:
dayName = "Unknown";
9
Example 2 :-
public class Main {
{ int num = 2;
switch(num)
case 1:
System.out.println("Number is 1");
break;
case 2:
System.out.println("Number is 2");
break;
case 3:
System.out.println("Number is 3");
break;
default:
10
Adavantages of Switch Case :-
Readability:-
The switch case statement is more readable and intuitive than a nestedif-
else statement when dealing with a large number of possible cases.
Efficiency:-
The switch case statement is generally more efficient than a nested if-
else statement when dealing with a large number of possible cases
because the compiler can generate more efficient code for the switch
case statement.
Code simplification:-
The switch case statement simplifies the code and makes it more concise by
eliminating the need for multiple if-else statements.
Ease of use:-
The switch case statement is easy to use and understand, even for beginners,
because it has a clear and straightforward syntax.
Case fall-through:-
The switch case statement allows for case fall-through, which means that
multiple cases can be handled by the same code block, saving time and effort
in writing repetitive code.
11
Disadvantages Of Swich Case:-
No range checking:-
Switch case statements do not provide a way to check a range of values. For
example, if you want to check if a number is between 1 and 10, you would
need to use a series of if-else statements.
Limited flexibility:-
12
Flow Diagram Of Switch Case Statement :-
13
Some Important Rules for Switch Statements :-
1] There can be any number of cases just imposing condition check
but remember duplicate case/s values are not allowed.
2] The value for a case must be of the same data type as the variable in
the switch.
3] The value for a case must be constant or literal. Variables are not allowed.
6] The default statement is optional and can appear anywhere inside the
switch block. In case, if it is not at the end, then a break statement must be
kept after the default statement to omit the execution of the next case
statement
Example:-
// Java Program to Demonstrate
// Class
14
// Main driver method
// Custom input
// Switch case
switch (year)
// Case
case 1:
a System.out.println(
Break;
// Case
case 2:
// Nested Switch
switch (Branch) {
// Nested case
case "CSE":
case "CCE":
15
System.out.println(
break;
// Case
case
"ECE":
System.out.println(
break;
// default case
// execute
default:
// Print statement
System.out.println(
16
Source Code :-
import java.util.Scanner;
switch (choice)
{ case 1:
System.out.print("Enter the radius of the circle: ");
17
double radius = scanner.nextDouble();
double circleArea = Math.PI * Math.pow(radius, 2);
System.out.println("The area of the circle is " +
circleArea);
break;
case 2:
System.out.print("Enter the length of the rectangle:
");
18
double height = scanner.nextDouble();
double triangleArea = 0.5 * base * height;
System.out.println("The area of the triangle is " +
triangleArea);
break;
default:
System.out.println("Invalid choice!");
break;
}
}
Output Of Program :-
19
Conclusion:-
In Java, the switch case statement provides a convenient way to execute
different code blocks based on the value of an expression. Here are some key
takeaways and best practices to keep in mind when using the switch case
statement in Java:
Cource outcomes(Cos) :-
1. Understand the syntax and semantics of switch case statements in Java.
3. Learn how to write code that handles different cases using the switch
case statement.
5. Develop good coding practices for using switch case statements, such
as including a default case and using break statements.
6. Learn how to use switch case statements with different data types, such
as char, byte, short, int, and String.
20
Referance Of The Project :-
1] https://www.oracle.com/technetwork/java/javase/downloads/index.html
2] https://docs.oracle.com/en/java/index.html
3] https://www.oracle.com/technetwork/java/index.html
21
Action Plan :-
Gadhave siddesh
Dhole pranay
Sanskar dumbre
Gadhave siddesh
Dhole pranay
Sanskar dumbre
Gadhave siddesh
Dhole pranay
Sanskar dumbre
Gadhave siddesh
Dhole pranay
Sanskar dumbre
Gadhave siddesh
Dhole pranay
Sanskar dumbre
Dhole pranay
Sanskar dumbre
07 Analyze collected data For micro-Project report.
Gore sahil
Gadhave siddesh
Dhole pranay
Sanskar dumbre
08 Finalize collected data For micro-Project report.
Gore sahil
Gadhave siddesh
Dhole pranay
22
Thank you!!!
23