Docsity

Basic Calculator and Array Sum Experiments for UG Electronics and Computer Science, Exercises of Computer science

Toggle sidebar
bg1
Mahavir Education Trust's
SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE
Chembur, Mumbai - 400 088
UG Program in Electronics and Computer Science
Skill base Lab – OOPM: (C++ and Java), SEM 3, 2023-2024 Page 1
Name of Student: Roll Number :
Class/DIV : Academic Year :2022 2023
Title of Experiment: EXPT 12: DISPLAY BASIC CALCULATOR USING SWITCH
STATEMENT
Date of Performance: Date of Submission:
Program
Executio
n (04)
Documentatio
n (02)
Timely
Submissi
on
(0
2)
Viva
Answ
er
(0
2)
Experime
nt Marks
(10)
Teache
r
Signatu
re
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Basic Calculator and Array Sum Experiments for UG Electronics and Computer Science and more Exercises Computer science in PDF only on Docsity!

SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE

Chembur, Mumbai - 400 088

UG Program in Electronics and Computer Science

Name of Student: Roll Number : Class/DIV : Academic Year :2022 2023 Title of Experiment: EXPT 12: DISPLAY BASIC CALCULATOR USING SWITCH STATEMENT Date of Performance: Date of Submission: Program Executio n (04) Documentatio n (02) Timely Submissi on (

Viva Answ er (

Experime nt Marks (10) Teache r Signatu re

SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE

Chembur, Mumbai - 400 088

UG Program in Electronics and Computer Science

Experiment Number: 12

Aim: Display Basic Calculator Using Switch Statement.

Theory: In this Program we are making a simple calculator that performs addition,

subtraction, multiplication and division based on the user input. The program takes the value of both the numbers (entered by user) and then user is asked to enter the operation (+, -, * and /), based on the input program performs the selected operation on the entered numbers using switch case. Answer the following questions in theory:

  1. In Java, there are different types of variables. Explain each with an example.
  2. What are Java Identifiers?
  3. Instead of writing many if..else statements, you can use the switch statement. Explain its working.

Flowchart / Algorithm:

Program:

Output:

Conclusion:

SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE

Chembur, Mumbai - 400 088

UG Program in Electronics and Computer Science

Experiment Number: 13

Aim: Display Sum of Elements of an Array and average them.

Theory:

We need to calculate the sum of all the elements of an array. This can be solved by looping through the array and add the value of the element in each iteration to variable sum. Sum of all element of an array is 1+2+ 3+ 4+ 5= Answer the following questions in theory:

  1. Explain the syntax of array in java, include accessing, changing the elements.
  2. What is Java Type casting? Explain Widening casting and Narrowing casting.

Flowchart / Algorithm:

Program:

Output:

Conclusion:

SHAH & ANCHOR KUTCHHI ENGINEERING COLLEGE

Chembur, Mumbai - 400 088

UG Program in Electronics and Computer Science

Name of Student: Roll Number : Class/DIV : Academic Year :2022 2023 Title of Experiment : EXPT 14: Accept and Display an entered String and execute length(),concat(),replace(),split() and trim() string methods. Date of Performance: Date of Submission: Program Executio n (04) Documentatio n (02) Timely Submissi on (

Viva Answ er (

Experime nt Marks (10) Teache r Signatu re

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088 Name of Student: Roll Number : Class/DIV : Academic Year :2022 2023 Title of Experiment : EXPT 15: Read and Display the number as command line arguments and display the addition of them Date of Performance: Date of Submission: Program Executio n (04) Documentatio n (02) Timely Submissi on (

Viva Answ er (

Experime nt Marks (10) Teache r Signatu re

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088

Experiment Number: 15

Aim: Read and Display the number as command line arguments and display the addition of

them.

Theory:

The command-line arguments are passed to the program at run-time. Passing command-line arguments in a Java program is quite easy. They are stored as strings in the String array passed to the args parameter of main () method in Java. In fact command line arguments are used just for a subject purpose and maybe it is used in an advanced java core system in order to build the applications, just an expectation. Since, there may be a lot of ways to execute the program.

Flowchart / Algorithm:

Program:

Output: example:

Conclusion:

In this way we have performed method overloading with different numbers and different types of parameters.

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088

Experiment Number: 16

Aim: Define a class, describe its constructor, overload the constructor and instantiate its object.

Theory: A constructor in Java is a special method that is used to initialize objects. The

constructor is called when an object of a class is created. It can be used to set initial values for object attributes:

  1. The constructor name must match the class name, and it cannot have a return type (like void).
  2. Also note that the constructor is called when the object is created.
  3. All classes have constructors by default: if you do not create a class constructor yourself, Java creates one for you. However, then you are not able to set initial values for object attributes. Answer the following question in theory:
  4. Explain Access Modifiers and Non-Access Modifiers in Java

Flowchart / Algorithm:

Program:

Output:

Conclusion:

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088 Name of Student: Roll Number : Class/DIV : Academic Year :2022 2023 Title of Experiment :EXPT 17: Demonstrate Method Overloading Date of Performance: Date of Submission: Program Executio n (04) Documentatio n (02) Timely Submissi on (

Viva Answ er (

Experime nt Marks (10) Teache r Signatu re

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088 Name of Student: Roll Number : Class/DIV : Academic Year :2022 2023 Title of Experiment : EXPT 18: Create thread by implementing ‘run able’ interface or creating ‘Thread Class’. Date of Performance: Date of Submission: Program Executio n (04) Documentatio n (02) Timely Submissi on (

Viva Answ er (

Experime nt Marks (10) Teache r Signatu re

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088

Experiment Number: 18

Aim: Create thread by implementing ‘Runnable’ interface or creating ‘Thread Class’.

Theory: Threads allows a program to operate more efficiently by doing multiple things

at the same time. Threads can be used to perform complicated tasks in the background without interrupting the main program. There are two ways to create a thread. It can be created by extending the Thread class and overriding its run () method: Answer the following question in theory:

  1. Explain both the methods to create a thread with example.
  2. Differentiate between extending” and implementing a thread.
  3. What are concurrency problems in Java Threads?

Flowchart / Algorithm:

Program:

Output:

Conclusion:

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088

Experiment Number: 19

Aim: A Program in Java to implement APPLET and display hello world using applet

Theory:

Applet is a special type of program that is embedded in the webpage to generate dynamic content. It runs inside the browser and works at the client side. Advantage of Applet There are many advantages of applets. They are as follows: ● It works at client side so less response time. ● Secured ● It can be executed by browsers running under many platforms, including Linux, Windows, Mac Os etc. Drawback of Applet ● Plug-in is required at client browser to execute applet. Lifecycle of Java Applet

  1. Applet is initialized.
  2. Applet is started.
  3. Applet is painted.
  4. Applet is stopped.
  5. Applet is destroyed.

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088

Flowchart / Algorithm:

Step 1: START Step 2: Write a java program in notepad and save it by classname.java. Step 3: Compile the java program by using command javac classname.java Step 4: Create an Html file and embed the Applet tag in the HTML file. Step 5: STOP

Program:

Create a Java Source File- Create a file named HelloWorld.java with the Java code shown here: Program: Compile the Source File- Compile the source file using the Java compiler. If compilation succeeds, the compiler creates a file named HelloWorld.class. If compilation fails, make sure you typed in and named the program exactly as shown above. Create an HTML File that Includes the Applet- Create a file named Hello.html in the same directory that contains HelloWorld.class. This HTML file should contain the following text:

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088 Name of Student: Roll Number : Class/DIV : Academic Year :2022 2023 Title of Experiment :EXPT 20: A Program in Java to implement APPLET as a mini project in a group of maximum three students. Date of Performance: Date of Submission: Program Executio n (04) Documentatio n (02) Timely Submissi on (

Viva Answ er (

Experime nt Marks (10) Teache r Signatu re

SHAH & ANCHOR KUTCHHI ENGINEERING

COLLEGE

Chembur, Mumbai - 400 088

Experiment Number: 18

Aim: Create APPLET in JAVA

Theory: Write importance of APPLET you have made.

Flowchart / Algorithm:

Program:

Output:

Conclusion: