A
PROJECT REPORT
ON
“Switch Case Statement”
SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THEAWARD OF
DIPLOMA IN COMPUTER ENGINEERING
SUBMITTED TO
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION, MUMBAI
SUBMITTED BY
Name of Student Roll No
1. Dumbre Sanskar Balasaheb 01
2. Gore Sahil Bajrang 27
3. Gadhave Siddhesh Jyotiram 32
4. Dhole Pranay Sunil 58
GUIDED BY: (Prof. Borude A.S.)
SAMARTH POLYTECHNIC, BELHE
1
CERTIFICATE
This is to certify that the project report entitled “Switch Case Statement” Was
successfully completed by Student of fourth semester diploma in computer
engineering.
All groups members :
1. Dumbre Sanskar Balasaheb 01
2. Gore Sahil Bajrang 27
3. Gadhave Siddhesh Jyotiram 32
4. Dhole Pranay Sunil 58
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 .
Prof. Borude A.S. Prof. Nawale S.K. Prof. Kapile.A.S.
(Subject Teacher) (H.O.D) (Principal)
2
ACKNOWLEDGMENT
This project is done as a semester project, as a part course titled
“Switch Case Statement ”
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 ”
I am also thankful to parents, friend and all staff of computer engineering
department, for providing us relevant information and necessary clarifications, and
great support.
All Group Members.
1. Dumbre Sanskar Balasaheb 01
2. Gore Sahil Bajrang 27
3. Gadhave Siddhesh Jyotiram 32
4. Dhole Pranay Sunil 58
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
Title of Project: “Switch Case Statement”
-Cos addressed by the micro project :-
1. Dumbre Sanskar Balasaheb 01
2. Gore Sahil Bajrang 27
3. Gadhave Siddhesh Jyotiram 32
4. Dhole Pranay Sunil 58
Major Learning Outcomes achieved by students by doing the project:-
a)PracticalOutcomes...................................................................................................................................
........................................................................................................................................................................
......................................................................................................................................................................
b) Unit Outcomes in Cognitive domain
........................................................................................................................................................................
........................................................................................................................................................................
........................................................................................................................................................................
c) Outcomes in Affective Domain
........................................................................................................................................................................
........................................................................................................................................................................
........................................................................................................................................................................
Comments/suggestionsabout team work/leadership/inter-personal communication(if any)
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)
01 Dumbre Sanskar Balasaheb
27 Gore Sahil Bajrang
32 Gadhave Siddhesh Jyotiram
58 Dhole Pranay Sunil
Prof. Borude A.S.
(Name& Signature of Faculty)
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 :-
Calculating the area of different geometric shapes is a common task in
mathematics and engineering. In programming, this task can be accomplished
using conditional statements like if-else or switch case.
Using a switch case statement is a popular approach to calculate the area of
different shapes because it simplifies the code and makes it easier to
maintain. It allows the program to execute different blocks of code based on
the value of a variable or expression, resulting in more efficient and organized
code.
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.
Here is the basic syntax of a switch case statement in many programming
languages:
switch (expression)
{ case value1:
// Code to execute when the expression equals value1
break;
case value2:
// Code to execute when the expression equals value2
break;
// Add more cases as
needed default:
// Code to execute when none of the cases match the expression
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.
Example Of Switch Case :-
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 {
public static void main(String[] args)
{ 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:
System.out.println("Number is not 1, 2, or 3");
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.
Overall, the switch case statement is a powerful control flow statement in
Java that simplifies code, improves efficiency, and enhances readability .
11
Disadvantages Of Swich Case:-
Limited data types:-
Switch case statements can only be used with certain data types, such as
integers and characters. They cannot be used with more complex data types
like strings or floating-point numbers.
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.
Break statement misuse:-
It's easy to misuse the `break` statement in a switch case statement, which
can lead to unexpected behavior in your program. For example, forgetting to
include a `break` statement can cause the program to execute multiple cases,
or not including a `break` statement when it's needed can cause the program
to skip over cases.
Limited flexibility:-
Switch case statements are limited to checking a single variable or
expression. If you need to check multiple variables or expressions,
you will need to use nested switch case statements or a combination
of switch case and if-else statements.
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.
4] The break statement is used inside the switch to terminate a
statement sequence.
5] The break statement is optional. If omitted, execution will continue on
into the next case.
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
Nested Switch Case Statement :-
We can use a switch as part of the statement sequence of an outer switch.
This is called a nested switch. Since a switch statement defines its own block,
no conflicts arise between the case constants in the inner switch and those in
the outer switch.
Example:-
// Java Program to Demonstrate
// Nested Switch Case Statement
// Class
public class GFG {
14
// Main driver method
public static void main(String[] args)
// Custom input
string String Branch =
"CSE"; int year = 2;
// Switch case
switch (year)
// Case
case 1:
a System.out.println(
"elective courses : Advance english, Algebra");
// Break statement to hault execution here
// itself if case is matched
Break;
// Case
case 2:
// Switch inside a switch
// Nested Switch
switch (Branch) {
// Nested case
case "CSE":
case "CCE":
15
System.out.println(
"elective courses : Machine Learning, Big Data");
break;
// Case
case
"ECE":
System.out.println(
"elective courses : Antenna Engineering");
break;
// default case
// It will execute if above cases does not
// execute
default:
// Print statement
System.out.println(
"Elective courses : Optimization");
16
Source Code :-
import java.util.Scanner;
public class Area {
public static void main(String[] args) {
Scanner scanner = new
Scanner(System.in); int choice;
System.out.println("Choose a shape to calculate its
area:");
System.out.println("1. Circle");
System.out.println("2. Rectangle");
System.out.println("3. Triangle");
System.out.print("Enter your choice (1-3): ");
choice = scanner.nextInt();
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:
");
double length = scanner.nextDouble();
System.out.print("Enter the width of the rectangle:
");
double width = scanner.nextDouble();
double rectangleArea = length * width;
System.out.println("The area of the rectangle is " +
rectangleArea);
break;
case 3:
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle:
");
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.
2. Learn how to use switch case statements to control the flow of
execution based on the value of an expression.
3. Learn how to write code that handles different cases using the switch
case statement.
4. Understand the difference between switch case statements and
other conditional statements like if-else statements.
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.
7. Understand how to use switch case statements in complex scenarios
that involve multiple conditions and nested statements.
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 :-
Planned Start Planned Finish Name of Responsible
Sr. No. Details of activity
Date date Team Members
Sanskar dumbre
01 Decide individual micro project Gore sahil
Gadhave siddesh
Dhole pranay
Sanskar dumbre
02 Search micro project topics related To subject. Gore sahil
Gadhave siddesh
Dhole pranay
Sanskar dumbre
03 Selection of micro project title Gore sahil
Gadhave siddesh
Dhole pranay
Sanskar dumbre
04 Search information related to selected topic Gore sahil
Gadhave siddesh
Dhole pranay
Sanskar dumbre
05 Collect information related to selected topic Gore sahil
Gadhave siddesh
Dhole pranay
Sanskar dumbre
06 Completion of micro project Gore sahil
topicProposal
Gadhave siddesh
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