Java Programming Lab Manual
Java Programming Lab Manual
2020-21
Look forward,
learn modern
knowledge, and
do not waste
time in studies
of old subjects of
no values.
M.C.A.
Semester-II
❒ The students are also advised to maintain the soft copy of the Lab
File of their completed activities/assignments in the prescribed
format.
COURSE DESCRIPTION 3
CONTENT 3
OBJECTIVES 3
OUTCOMES 4
Week
Contents Page No.
No.
Introduction of Java programming, JDK, Installation of
#1 9
Java and different IDEs of Java on different platform.
Understanding the importance of programming in Object
#2 58
Oriented environment using JAVA
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 2
COURSE TITLE: Laboratory Course-II COURSE CODE: CSM – 2271
CREDIT: 04 PERIODS PER WEEK: 06
CONTINUOUS ASSESSMENT: 40 Marks EXAMS: 60 Marks
COURSE DESCRIPTION
Today almost every branch of computer science is feeling presence of object-
orientation. Object oriented technology is successfully incorporated in various
fields of computer science. Since its arrival on the scene in 1995, the Java has been
accepted as one of the primary programming language.
COURSE CONTENT
This course is designed to provide the students the opportunity of learning the
differences between C++ and JAVA programming, to develop, debug, and execute
JAVA programs.
OBJECTIVES
This course is designed to help students in:
Gaining knowledge about basic Java language syntax and semantics to write
Java programs and use concepts such as variables, conditional and iterative
execution methods etc.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 3
Understanding the fundamentals of object-oriented programming in Java,
including defining classes, objects, invoking methods etc. and exception
handling mechanisms.
Learning the use of arrays, access protection, wrapper classes etc.
Understanding the principles of inheritance, packages and interfaces.
Learning to create applet and application and event handling, AWT controls,
able to create GUI (frame, menu, button, text boxes, layout manager).
Understanding to use the Java SDK environment to create, debug and run
simple Java programs.
OUTCOMES
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 4
Understand the concept of Exception Handling, Files and Streams, Applets
and Graphics and also learn the concept of Applet classes, Applet life cycle
and JAVA Swing (introductory part).
❒ The students are advised to submit the assignments given in theory and lab
classes timely to their respective Teachers/Instructors online.
❒ Each student shall be assigned a system in their introductory lab. They are
advised to do their work on that system only for the whole semester. Students
should store all their lab activities regularly.
❒ All students are advised to understand course objectives and outcomes and
achieve both during their lab work.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 5
❒ All students are advised to solve old placement papers for campus selection.
Following links may be useful for the preparation of your campus
placements.
➢ https://www.indiabix.com/placement-papers/companies/
➢ https://www.offcampusjobs4u.com/download-tcs-placement-test-
question-papers-with-solutions/
➢ https://www.indiabix.com/placement-papers/tcs/
➢ https://www.firstnaukri.com/career-guidance/infosys-placement-papers-
with-solutions-2019-firstnaukri-prep
➢ https://prepinsta.com/ibm/
➢ https://www.faceprep.in/infosys/infosys-aptitude-questions/
➢ https://alpingi.com/infosys-placement-papers-solution-pdf-download/
➢ http://placement.freshersworld.com/
➢ http://drrafiq.org/
➢ https://www.w3schools.com/java/
➢ https://www.tutorialspoint.com/java/index.htm
➢ https://www.javatpoint.com/java-tutorial
The Students are advised to follow below Links for installing application
software:
➢ http://www.jcreator.org/download.htm
➢ https://www.eclipse.org/downloads/
➢ https://netbeans.org/downloads/6.1/index.html
The students are advised to use the following online editors which are much
helpful during the online classes:
➢ https://www.jdoodle.com/online-java-compiler/
➢ https://www.codechef.com/ide
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 6
➢ https://www.onlinegdb.com/online_java_compiler
➢ https://rextester.com/l/java_online_compiler
➢ https://paiza.io/en/projects/new?language=java
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 7
APPENDIX-1
WEEK NO. Template for the Index of Lab File
SIGNATURE
PAGE NO.
OF THE
PROBLEMS WITH DESCRIPTION TEACHER
WITH DATE
1#
1 2#
3#
1#
2 2#
3#
1#
3 2#
3#
Note: The students should use Header and Footer mentioning their roll no. & name
in footer and page no in header.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 8
WEEK #1
OBJECTIVES
To learn the Java programming.
To learn the JDK kit.
To learn the installation of JDK on windows and Linux operating system.
To learn the different IDEs of Java.
To learn how to configure your machine for Java programming.
OUTCOMES
After completing this, the students would be able to:
This Java Development Kit(JDK) allows you to code and run Java programs. It's
possible that you install multiple JDK versions on the same PC. But Its
recommended that you install only latest version.
Step 1)
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 9
Step 2) Next,
Step 3)Once the download is complete, run the exe for install JDK. Click Next
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 10
Step 4) Select the PATH for Java installation and click next.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 11
How to set Environment Variables in Java: Path and Classpath
The PATH variable gives the location of executables like javac, java etc. It is
possible to run a program without specifying the PATH but you will need to give
full path of executable like C:\Program Files\Java\jdk-13.0.1\bin\javac A.java
instead of simple javac A.java
Let's look into the steps to set the PATH and CLASSPATH
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 12
Step 2) Click on advanced system settings
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 13
Step 4) Click on new Button of User variables
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 14
Step 6) Copy the path of bin folder which is installed in JDK folder.
Step 7) Paste Path of bin folder in Variable value and click on OK Button.
Note: In case you already have a PATH variable created in your PC, edit the PATH
variable to
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 15
PATH = <JDK installation directory>\bin;%PATH%;
Here, %PATH% appends the existing path variable to our new value
Note: In case you java installation does not work after installation, change classpath
to
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 16
Step 10) Go to command prompt and type javac commands.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 17
JAVA IDE: NetBean for JAVA
To use NetBeans for Java programming, you need to first install Java Development
Kit (JDK).
Step 1: Download
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 18
How to Install NetBeans on Mac OS X
To use NetBeans for Java programming, you need to first install JDK.
To install NetBeans:
To use NetBeans for Java programming, you need to first install JDK. To install
NetBeans:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 19
$ ./netbeans-7.x-ml-javase-linux.sh// Run
To start NetBeans, run the script "netbeans" in the NetBeans' bin directory:
$ cdnetbeans-bin-directory
$ ./netbeans
Launch NetBeans. If the "Start Page" appears, close it by clicking the "cross" button
next to the "Start Page" title.
For each Java application, you need to create a "project" to keep all the source files,
classes and relevant resources.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 20
Step 2: Write a Hello-world Java Program
To run the program, right-click anywhere in the source (or from the "Run" menu) ⇒
Run File. Observe the output on the output console.
Notes:
• You should create a NEW Java project for EACH of your Java application.
• Nonetheless, NetBeans allows you to keep more than one programs in a
project, which is handy for writing toy programs (such as your tutorial
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 21
exercises). To run a particular program, open and right-click on the source
file ⇒ Run File.
In order to experiment Java programming on your own computer you have to install
Java Development Kit (JDK), if it is not already installed. Also an Integrated
Development Environment (IDE) is helpful. In the class lectures and also in the labs
we will use JCreator as the IDE. JCreator is available only for Windows operating
systems. In the rest of this document, you will find a detailed explanation for
preparing your computer for the CS 101 course, by installing JDK and JCreator.
1. Installing JDK:
"http://www.oracle.com/technetwork/java/javase/downloads/index.html".
1.1.3. Click the icon about Java Platform (JDK) Download, as shown below:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 22
1.1.4. Accept the License Agreement
"http://www.oracle.com/technetwork/java/javase/downloads/index.html".
1.1.7. Scroll down to the section called "Additional Resources" Click the icon
labelled "Download", as shown below:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 23
1.1.8. Accept the license agreement.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 24
1.2. Installing JDK
1.2.2. Click "Yes" to the question "Do you want to allow the following program to
make changes to this computer?"
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 25
Wait during the installation of the JDK.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 26
1.2.6. Press "Close" button to complete the installation of the JDK.
1.3.3. Then click "Program Files". You should see a folder named "Java".
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 27
1.3.4. Click that folder named "Java". The contents of the folder should look like
the following:
1.3.5. Unzip the "jdk-8u31-docs-all.zip" file by double clicking in the folder you
downloaded.
You should see the folder "docs" as shown below:
1.3.6. Drag the "docs" folder in the zip window into the "Java" window.
1.3.7. The contents of the "Java" window should contain three folders as shown
below:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 28
2. Installing JCreator:
2.1.3. Click the "Download" button next to "JCreator Classics, as shown below:
2.1.4. Fill in your name and email address and press the "SUBMIT" button.
Do not use Turkish characters in the name area.
You can uncheck "Yes, keep me informed about new releases and discounts" part if
do not want to get emails about JCreator.
2.1.5. Wait for an email message from JCreator to the address that you gave.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 29
2.1.6. Open the message. Copy the line under the sentence "Thank you for your
interest in JCreator LE. You can download the setup file from the following url:"
below:
2.1.8. Wait for the download to complete. The name of the file is
"jcrea450_setup.exe".
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 30
2.2.4. Press the "Next" button.
2.2.5. Select "I accept the agreement" then press the "Next" button.
2.2.6. Keep the default destination location. Just press the "Next" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 31
2.2.8. Press the "Next" button for the start menu folder.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 32
2.2.10. Press the "Install" button to start installation.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 33
2.3. Setup the JCreator
2.3.1. The JCreator setup wizard window will open. Press the "Next" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 34
2.3.3. On the JDK Home Directory Window, press the "Browse" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 35
2.3.4. Click "Computer", "Local Disk (C:)", "Program Files", "Java", "jdk1.7.0_51",
in this order. Then press the "OK" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 36
2.3.6. Click the "Browse" button on the JDK JavaDoc Directory.
2.3.7. Click "Computer", "Local Disk (C:)", "Program Files", "Java", "doc", in this
order. Then press the "OK" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 37
2.3.8. Press "Finish" to complete the setup.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 38
3. Running JCreator:
3.1.1. The "Start Page" will open. Press "Close" to close the tip window.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 39
3.1.2. Press the "New File" icon on the upper left corner.
3.1.3. Make sure "Java Class" highlighted, press the "Next" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 40
3.1.4. Type HelloWorld in the "Name" area. Press the "Finish" button.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 41
3.1.5. A window by the name "HelloWorld.java" will open. This is the source code
that you will edit. It contains some default code as shown below:
3.1.6. Replace the public HelloWorld() part with public static void main(String[]
args).
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 42
3.1.7. Type in System.out.println("Hello World"); between the curly brace symbols,
as shown below.
3.2.2. You should see the "Process completed." message in the "Build output" part.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 43
3.3. Run Application
3.3.2. You should see Hello World in the "General output" part.
Step 1: Go to the Java Downloads Page and click on the option of Download.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 44
Step 2: Once you click on Download, you will be redirected to a page, where you
have to select the Accept License Agreement radio button. After that, you have to
choose the download link according to your matching system configuration as
below.
Step 3: Now, once the file is downloaded, run the installer and keep clicking on
Next, till you finally get a dialog box, which say, you have finished downloading.
Step 4: Once the installation is over follow the below instructions to set the path of
the file.
Step 4.1: Go to start and search for ‘System’. Then, click on ‘System’ and go to
Advanced System Settings. Refer below.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 45
Step 4.2: Now, click on ‘Environment Variables’ under ‘Advanced’ tab as shown
below:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 46
Step 4.3: Next, under System Variables choose New.
Step 4.4: Enter the variable name as ‘JAVA_HOME’ and the full path to Java
installation directory as per your system as shown below:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 47
Step 4.5: Next thing that you have to do is to configure your environment variables.
Let’s see how to do that. Here, you have to edit the path of the system variable as
shown below.
Step 4.6: Under ‘Variable value’, at the end of the line, enter the path of the folder.
Now, you can click ‘OK’ and you are done.
Now to cross-check the installation, just run following command in cmd – java -
version. It should display the installed version of Java in your system.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 48
Install Eclipse
Step 2: Once the download is over, extract the zipped file by right-clicking on the
folder and choose Extract All. Refer below.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 49
Step 3: You will be then redirected to a dialog box, where you have to choose the
directory in which you wish to extract the files. Then click on Extract. Refer
below.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 50
Programming & Frameworks Training
Step 4: After extracting files, open the folder and launch eclipse.exe.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 51
Step 5: Then, you have to choose the Launch directory for Eclipse and then click
on Launch. Refer below.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 52
Hello World Program
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 53
Step 3: Now, go to the Project, Right-Click on the Project and choose Package. In
the dialog box, which opens up, mention the Package name as below and click on
Finish.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 54
Step 4: Now, right click on the Package, go to New and choose Class. Mention the
class name and click on Finish. Refer below.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 55
Step 5: Now, mention the following code in the workspace.
Package Edureka;
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 56
System.out.println(“Hello World”);
Step 6: Now, execute your file, by right-clicking on the helloworld.java file and
choose Run As → Java Application. You will see Hello World printed on the
console.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 57
WEEK #2
OBJECTIVES
OUTCOMES
PROBLEMS
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 58
WEEK #3
OBJECTIVES
OUTCOMES
PROBLEMS
1# Write a java program for finding the sum, difference, product, quotient,
minimum and maximum of any two integers.
i) Finds the round value of 'num' and stores the result in a variable
numRound of type double.
ii) Finds the ceil value of 'num' and stores the result in a variable numCeil of
type double.
iii) Finds the floor value of 'num' and stores the result in a variable numFloor
of type double.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 59
Cast 'num' to type int and stores the result in a variable numInteger of type
int.Display output of numRound, numCeil, numFloor and numInteger on
screen.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 60
WEEK #4
OBJECTIVES
OUTCOMES
The students would be able to use different control statements and loops
available in JAVA.
PROBLEMS
1# Write a java program to prints the count of odd and even no’s entered.
2# Write a java program to print the squares and cubes for the numbers 1 to 5.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 61
4 5 6
7 8 9 10
11 12 13 14
15 16 17 18 19
1
0 1
1 0 1
0 10 1
1 01 0 1
0 1 0 1 0 1
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 62
WEEK #5
OBJECTIVES
OUTCOMES
The students would be able to use different control statements and loops
available in JAVA.
PROBLEMS
2# Write a program to accept three digits (i.e. 0 - 9) and print all its possible
combinations. (For example if the three digits are 1, 2, 3 than all possible
combinations are: 123, 132,213, 231, 312, 321)
3# Write a Java Program which prompts the user to enter 4 numbers. The program
will then computes and display their sum and their product.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 63
4# Write a Java program which reads a 4-digit number and prints the digits on
separate lines. (Each digit is printed on one line).Output of your program must
be in the following format:
5# The intersection method computes the intersection of two rectangles- that is,
the rectangle that is formed by two overlapping rectangles: You call this
method as follows: Rectangle r3 =r1.intersection (r2);
Write a program that constructs two rectangle objects, prints them, and then
prints their intersection. What happens when the rectangles do not overlap?
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 64
WEEK #6
OBJECTIVES
OUTCOMES
PROBLEMS
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 65
• Number of Even: y”, where x and y are the values of the instance
variables.
The circle class needs to have instance variables to store the radius of the
circle, and the x and y coordinates of the center. Add main program to test the
class Circle repeatedly, until user enters negative value for the radius of the
circle.
3# Write a program in Java that reads in text and prints as output the following:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 66
4# A sales person is paid commission based on the sales he makes as shown by
the following table:
Sales Commission
Under ₹500 2% of Sales
Between ₹500 to ₹5000 5% of Sales
₹5000 and Above 8% of Sales
Now write a demo class to test the Commission class by reading a sale from
the user, using it to create a Commission object after validating that the value
is not negative. Finally, call the commission() method to get and print the
commission. If the sales are negative, your demo should print the message
“Invalid Input”.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 67
WEEK #7
OBJECTIVES
OUTCOMES
PROBLEMS
1# The certain instructor assigns letter grade for his course based on the following
table:
Score Grade
>=90 A+
>=85 A
>=80 B+
>=75 B
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 68
>=65 C+
>=60 C
>=55 D+
>=50 D
<50 F
Write a class, Grader, which has an instance variable, score, an appropriate
constructor and appropriate method letterGrade() that returns the letter grade
as a String.
Now write a demo class to test the Grader class by reading a score from the
user, using it to create a Grader object after validating that the value is not
negative and is not greater than 100. Finally, call the letterGrade() method to
get and print the grade.
2# Implement a Student class with the following fields, constructors and methods:
Fields:
• name;
• totalScore;
• numberOfQuizzes;
Constructors:
• public Student(String name, double score)
• public Student(double score, String name)
• public Student(String name)
Methods:
• public String getName()
• public double getAverage() //this should return zero if no quiz has been
taken.
• public double getTotalScore()
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 69
• public void addQuiz(double score)
• public void printStudent() //this should print the student’s name and
average score.
• public String toString()
Write an application TestStudent that reads a student name and use the Student
class to create a Student object. Then read the scores of the student in three
quizzes and add each to the totalScore of the student using addQuiz() method
and print the student object.
( Note: Make use of this key word wherever it can be used ).
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 70
WEEK #8
OBJECTIVES
To learn the use of member functions and how we access them, using
interfaces for code reusing,
To learn converting between class and interface types, using interfaces for
callbacks; Polymorphism, Inheritance
OUTCOMES
PROBLEMS
1# Write a program that reads in a sentence from the user and prints it out with
each word reversed, but with the words and punctuation in the original order:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 71
3# Write a program that reads in three strings and sorts them lexicographically.
Hint: Enter strings: Charlie Able Banker
Output: Able Banker Charlie
4# Implement the classes for the shapes using an interface for the common
methods, rather than inheritance from the superclass, while still Shape as a
base class.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 72
WEEK #9
OBJECTIVES
To learn the toString method in Java.
To learn the use of member functions and how we access them.,
OUTCOMES
After completing this, the students would be able to:
PROBLEMS
1# Implement a super class Person. Make two classes, Student and Instructor,
inherit from Person. A person has a name and a year of birth. A student has
a major, and an instructor has a salary. Write the class definitions, the
constructors, and the methods toString for all classes. Supply a test program
that tests these classes and methods.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 73
3# Write a Java program to create a super class Vehicle having members
Company and price. Derive 2 different classes LightMotorVehicle (members –
mileage) and HeavyMotorVehicle (members – capacity-in-tons). Accept the
information for n vehicles and display the information in appropriate form.
While taking data, ask the user about the type of vehicle first.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 74
WEEK #10
OBJECTIVES
OUTCOMES
PROBLEMS
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 75
Sav-acct. Include the necessary methods in order to achieve the following
tasks:
4# Implement the classes for the shapes using an interface for the common
methods, rather than inheritance from the superclass, while still Shape as a
base class.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 76
WEEK #11
OBJECTIVES
OUTCOMES
PROBLEMS
3# In a small firm employee numbers are given in serial numerical order, that is 1,
2, 3 etc.Write a menu driven program to perform following operations:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 77
iv) If gross salary of a given employee increases, update the gross salary.
v) Display the record of :
a. a given employee or
b. all employees.
4# Write a program to create a sequential file that could store details about five
products. Details include product code, cost, and number of items available and
are provided through the keyboard.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 78
WEEK #12
OBJECTIVES
To learn the file handling using Java.
To learn various operations performed in file using file handling concepts.
OUTCOMES
PROBLESM
1# Write a Java program which reads student grades from a text file called
grades.txt and prints only the corresponding letter grades into a file called
letter.txt. The letter grades are assigned according to the following table.
Assume that the grades.txt file can have any number of students’ grades. Hint:
The last number in the grades.txt file is -1
Score Grade
>= 90 A+
>= 85 A
>= 80 B+
>= 75 B
>= 65 C+
>= 60 C
>= 55 D+
>= 50 D
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 79
< 50 F
2# Write a program to read a, b, c from data file and store roots of the quadratic
equation in output file. You must open your output file in append mode.
3# Develop an applet that receives three numeric values as input from the user and
then displays the largest of the three on the screen. Write a HTML pages and
test the applet.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 80
WEEK #13
OBJECTIVES
OUTCOMES
PROBLEMS
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 81
3# Write a JAVA Applet program to plot the following face:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 82
WEEK #14
OBJECTIVES
To learn the concept of applet and their applications.
OUTCOMES
After completing this, the students would be able to:
PROBLEMS
1# Write a graphics program that draws a clock face with a time that the user
enters in a text field. (The user must enter the time in the format hh:mm, for
example 09:45).
Hint: You need to find out the angles of the hour hand and the minute hand.
The angle of the hour hand is harder; it travels 360 degree in 12 x 60 minutes.
Your output must be in the following format:
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 83
3# Write an applet to display the following figure:
Sample Output:
4# Draw a “bull’s eye” a set of concentric rings in alternation black and white
colours: Fill a black circle, and then fill a smaller white circle on top, and so
on.
LAB MANUAL/MCA/CSM–2271/LAB-II/CSD-AMU 84