Java Programming Manual
Java Programming Manual
Java Programming Manual
SCHOOL OF COMPUTING
LAB MANUAL
YEAR/SEM : II / IV
Prepared By,
Dr.N.PARTHEEBAN/Associate Professor
Dr.R.KAVITHA/Associate Professor
Mrs.VIJAYALAKSHMI.K/Assistant Professor
Mrs.S.UMA/Assistant Professor
1
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
VISION
To offer high quality education in the field of computer science and engineering by
imparting quality training, hands on experience and value education.
To create an environment encourages for research and to innovate new
technologies in the field of Computer Science and Engineering and across
disciplines in order to serve the needs of industry, government and society.
Encourage students to become self-motivated, ethically strong, problem solving
individuals who can find and understand the knowledge needed to be successful in
the profession
After 3-5 years from the year of graduation, our graduates will,
2
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
3
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
4
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
SYLLABUS
COURSE CODE COURSE TITLE L T P C
1151CS302 JAVA PROGRAMMING LAB 0 0 2 1
Course Category: Program Core
A. Preamble :
Most of the software need to develop runs in cross platform. Java is the one of the pioneer
software development tool developed used for cross platform development software. From the system
towards the handheld devices all place Java become one of the most dominant software. This course
provides a basic concept about Object Oriented Programming, Database connectivity, Networking
and finally provides programming skills in java. After successful completion of this course learners
can able to develop software modules for real world problem.
B. Pre-requisites:
Sl. No Course Code Course Name
1 1150CS201 Problem Solving using C
C. Related Courses:
Sl. No Course Code Course Name
1 1156CS601 Minor Project
2 1156CS701 Major Project
D. Course Outcomes:
Students undergoing this course are able to
Knowledge Level
CO
Course Outcomes (Based on revised
Nos.
Bloom’s Taxonomy)
Write a java program using classes, methods, Objects and
1 control structures.
S3
Implement inheritance, interfaces and packages in various S3
2 applications.
Develop simple applications for handling pre-defined and user S3
3 defined exceptions.
Develop simple applications using GUIs and event driven S3
4 programming.
5 Construct an application using JDBC. S3
F. Course Content
-LIST OF EXPERIMENTS:
1. Simple Java applications
- for understanding reference to an instance of a class (object), methods
- Handling Strings in Java
2. Constructors
-Implement constructor overloading.
3. Inheritance
- To Implement Method Overloading and Method Overriding.
4. Package creation.
- Developing user defined packages in Java
5. Interfaces
- Developing user-defined interfaces and implementation
- Use of predefined interfaces
6. Threading
- Creation of thread in Java applications
- Multithreading
7. Exception Handling Mechanism in Java
- Handling pre-defined exceptions
- Handling user-defined exceptions
8. AWT-To Create Different Layout Managers.
9. JDBC-To connect Oracle/MS Access for Table creation and Data Manipulation.
G. Learning Resources
i. Text Books
1.E. Balaguruswamy,Programming in java , Fourth Edition,TMH,2010.
2. PatricNaughton , Herbert Schildt, The Complete Reference “Java 2 “, Ninth edition
Tata McGraw Hills ,2014.
ii. Reference Books
1. H.M.Deitel and P.J.Deitel –“Java How to Program” Pearson Prentice Hall 6th Edition,
2011.
2. Sachinmalhotra, ”Programming in JAVA”, Oxford University Press, 2011.
3. Maydene Fisher, Jonathan Ellis, Jonathan Bruce,”JDBC Database access with java”
Addison-Wesley, Third Edition 2003
4. Bruce Eckel – “Thinking in Java” Pearson Prentice Hall Third Edition-2006
iii. Online Resources
1. docs.oracle.com/javaee/6/tutorial/doc/girgm.html
2. www.webreference.com/programming/java.html
3. www.apl.jhu.edu/~hall/java/Documentation.html
6
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
LIST OF EXPERIMENTS
1.Given the following table containing information about employees of an organization,
develop a small java application which accepts employee id from the command prompt and
displays the following details as output:
7
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
You are expected to write a program to perform the basic components like insert, delete, display,
search etc. on a list. The list should contain string object items. The operations should be
available to the user through a console-based menu as shown below:
MAINMENU
1.Insert
2.Search
3.Delete
4.Display
5.Replace
6.Sort
7.Shuffle
8.Reverse
9.Exit
Enter your choice (1…9):1
Enter the item to be inserted :Bottle
Inserted Successfully.
MAINMENU
1.Insert
2.Search
3.Delete
4.Display
5.Replace
6.Sort
7.Shuffle
8.Reverse
9.Exit
Enter your choice (1…9):1
Enter the item to be inserted :Water
Inserted Successfully.
MAINMENU
1.Insert
2.Search
3.Delete
4.Display
5.Replace
6.Sort
7.Shuffle
8.Reverse
8
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
9.Exit
Enter your choice (1…9):1
Enter the item to be inserted :Cap
Inserted Successfully.
2 (a) To write simple java application program to implement control statement for
generating the followings:
3. The goal of this project is to design and implement a simple inventory control system for
a small video rental store. Note: This program based on OOPS and Inheritance.
Member functions
• String getName();
• void doCheckout();
• void doReturn();
• void receiveRating(int rating);
• intgetRating();
9
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
• booleangetCheckout();
Constructor
• Video(String name);
2.Videostore
Member variables
Video[] store
Member Functions
• void addVideo(String name);
• void doCheckout(String name);
• void doReturn(String name);
• void receiveRating(String name, int rating);
• void listinventory();
3. VideoLaucher
Contains the main method to test the program.
5. Write a Java Program to implement Interest Calculator based on the following scenario.
Calculate interest based on the type of account and the status of the account holder.
The rate of interest changes according to the amount (greater than or less than 1 crore) age
of the account holder (General or Senior citizen) and the number of days if the type of
account is FD or RD.
10
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Rate of RD Interest:
Current Rate of Interest
Maturity period General Senior Citizen
6 months 7.50 8.00
9 months 7.75 8.25
12 months 8.00 8.50
15 months 8.25 8.75
18 months 8.50 9.00
21months 8.75 9.25
Requirements:
1.Seprate classes should be created for the different types of accounts.
2.All class should be derived form an abstract class named ‘Account’ which should contain a
method called ’calculate interest’
3.Implement the ‘calculate Interest’ method according to the type of the account, interest rates,
amount and age of the account holder.
4.if the user enters an Invalid value(e.g negative)if any field, raise a user defined exception.
Account(Abstract)
double interestRate
Double amount
Abstract double calculateInterest()
FDAccount
double interestRate
double amount
int noOfDays
int ageOfACHolder
abstract double calculateInterest()
11
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
SBAccount
double interestRate
Double amount
abstract double calculateInterest()
RDAccount
double interestRate
double amount
int noOfmonths
double monthlyAmount;
abstract double calculateInterest()
Sample Output
MAIN MENU
____________
1.Interest Calculator-SB
2. Interest Calculator-FD
3. Interest Calculator-RD
4.Exit
Enter your option (1…4 ):1
Enter the Average amount in your account:10000
Interest gained:Rs.400
MAIN MENU
1.Interest Calculator-SB
2. Interest Calculator-FD
3. Interest Calculator-RD
4.Exit
MAIN MENU
1.Interest Calculator-SB
2. Interest Calculator-FD
12
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
3. Interest Calculator-RD
4.Exit
MAIN MENU
1.Interest Calculator-SB
2. Interest Calculator-FD
3. Interest Calculator-RD
4.Exit
7. To write a java program for developing a chatting application(Client and Server) using
Thread.
1. Create two threads named ‘Rabbit’ and ‘Tortoise’ . The threads created should run
100 meters and the thread which finishes first ‘ wins the race’. When one of the threads wins the
race, stop the second thread.
Start both the threads and observe which thread finishes first.
2. Since the rabbit is faster than Tortoise, set a high priority to Rabbit and observe the
results.
3. Now modify the program so that the ‘Rabbit’ thread ‘ sleeps ‘ or 1000 milliseconds after
running 60 meters. Observe which thread wins the race.
13
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
We can create threads in two ways: either by extending thread class or by implementing
Runnable interface.
We can use for loop or iterating rom 0 to 100. A print statement can be included so that we can
see how far each thread has run.
Here, test data is available in array of Student objects. The functions accept either a
student object or an array of students as arguments.
If the given object has any data errors, then, the program is expected to return appropriate
error messages by throwing the exceptions. Or, if given object has no data errors, then, we need
to find the grade and print the same.
Also, need to implement counter functions to count the number of null entries in the
given array of objects.
Package 1: com.mile1.bean
Class Student
Variables Description
String name; Instance variables
int marks[];
String grade;
Constructors Auto generated
public Student() {
}
public Student(String grade, int[] marks,
String name)
{
// do the initialization
}
Methods Auto generated
Provide public Getters And public Setters for all instance
variables
Package 2: com.mile1.exception
All the classes in this package should extend the Exception class.
Class Method Description
NullMarksArrayException Override toString() method Return "mark array is null"
NullNameException Override toString() method Return "name is null"
NullStudentObjectException Override toString() method Return "object is null"
14
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package 3: com.mile1.service
Class StudentReport
Method Description
Assumption:
public StringfindGrades Only valid objects are passed to this function. So, just
(Student studentObject) concentrate on the logic part.
public String validate Check whether there is any null data in the given object.
(Student studentObject) If given Object itself is null, then, throw the
throws NullNameException, NullStudentObjectException.
NullMarksArrayException, Else
we need to look for null inside the object.
NullStudentObjectException 1) Check whether name is null. If so, throw the
NullNameException
{
2) Check whether marks array is null. If so, throw the
// write code here NullMarksException
Package3 com.mile1.service
ClassStudentService
Note: If you are not careful, you will get NullPointerException in these function.
Method Description
15
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
public
intfindNumberOfNullMarksArray This function is used to count the number of objects in
(Student studentObjects[]) studentObjectswhere the marks array in that objects is
{ null.
// write code here
Declare Counter=0;
Check (studentObjects is not null)
If so{
for ( each student in studentObjects array {
} if (student !=null and student.getMarks() is null)
Counter++;
}
return the Counter value;
}
public intfindNumberOfNullName
(Student studentObjects[]) This function is used to count the number of objects in
{ studentObjectswhere the name in that object is null.
// similar to findNumberOfNullMarksArrayfunction
public intfindNumberOfNullObjects This function is used to count the number of null objects
(Student studentObjects[]) in studentObjects[] array.
{
Declare Counter=0;
Check (studentObjects!= null)
If so
{
for (each student in studentObjectsarray ){
// write code here if (student is null) Counter++;
} }
Package 4 com.mile1.main
Class StudentMain – Test Code Given
This is used to test your project locally
Variables
static Student data[] = new Student[4];
Methods
16
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
StudentMain() // Constructor
{
// Code Given
}
TestCases:-
TC1 -- Calculate the grades for valid objects – Check for A+ grade computation.
TC8 -- Calculate the grades for valid objects – Check for F grade computation.
Test the validate function Implementation in service package
Check whether the validate function handles the following situations.
TC2 -- If the Object is null, throw NullStudentObjectException().
TC3-- If the Name is null, throw NullNameException().
TC4 -- If the Marks array is null, throw NullMarksArrayException().
Test the counting functions Implementation in service package
TC5 –Test findNumberOfNullNamefunction.
TC6–Test findNumberOfNullObjects function.
TC7 -- Test findNumberOfNullName
SAMPLE DATA SET1: Note that your program will be tested with another set of data. Not this
set of data. This is given to understand the testing process used in the background.
17
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
{77,55,12});
s[7]= new Student(null,newint[]{13,88,13}); 114 // this is invalid object
Validate function will
throw new
NullNameException()
s[8]= new Student("J1",null); -- // this is invalid object
Validate function will
throw new
NullMarksArrayException
()
s[9]= null; -- // this is invalid object
Validate function will
throw new
NullStudentObjectExcepti
on()
10. To write a java program to simulate the traffic light using AWT component.
12. Develop a mini project on Inventory and Sales System application based on java with
Data base Connectivity.(Oracle SQL PLUS).
Project Objective:
As per the requirement from the client you are required to create a console based application
using java as frontend and oracle as backend for their inventory and sales maintenance. Already
the design team have completed the requirement design and you are expected the complete the
assigned module.
Project Design:
Database Design: you are required to get the Database ready using Oracle SQL Plus.
Task1:
Create a table called TBL_STOCK with the given specification:
Task2:
Enter sample record into TBL_STOCK table:
Product_I Product_Name Quantity_On_Hand Product_unit_price Reorder_Leve
D l
RE1001 REDME Note 3 20 12000 5
ip1002 Iphone 5s 10 21000 2
PA1003 Panasonic p55 50 5500 5
Task 3:
Create the following sequence:
Sequence _Name Start value Incremental Value
SEQ_SALES_ID 1000 1
SEQ_PRODUCT_ID 1004 1
Task 4:
Create a view named V_SALES_REPORT usingTBL_SALES table based joined with
TBL_STOK table based on ProductID order the result based on Profit_ Amount in descending
and Sales_ID in Ascending.
Column Name Description
Sales_ID
Sales _Date
Product-+_ID
Product_Name
Quantity_Sold
Sales_Price_per_unit
Profit_Amount Return the difference between Sales_Price_Per_Unit And
Product_Unit_Price.
19
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
20
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
22
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
The objective of this following assessment is to check your ability to complete a project as per
the provided “Project Design”.
14. House Management System
15. Weather Forecast System
16. University Management System
17. Bus Schedule Management System
18. Library Management system
Project Assessment
Project Design:
A. Database Design:
1. Create a new user in database [ To be done in the backend by using sql commands ]
a) Note: Do NOT use the default scott/tiger account of oracle for this project. You will have
to create a new user in the below mentioned format.
b) Username/password : B<batchnumber><employeeid>
23
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
For example, if your batch number is 39806 and Employee number is 12345, then the oracle user
should be B3980612345 and the password should be B3980612345
c) For JDBC connection, only use orcl as service name and 1521 as port number
3. Create Table [ To be done using sql commands, after logging-in as the new user that
has been created in above step ]
B. System Design:
Name of the package Usage
com.wipro.hms.service This package will contain the class that displays the console
menu and takes the user input.
com.wipro.hms.bean This package will contain the bean class
com.wipro.hms.dao This package will contain the class that will do the database
related operations
com.wipro.hms.util This package will contain a class to establish database
connection and also another class that handles the user defined
exception.
Package: com.wipro.hms.util
Class Method and Variables Description
DBUtil DB connection class
24
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.hms.bean
Class Method and Variables Description
RentalPropertyBean Class
private float rentalAmount;
private int noOfBedRooms;
private String location;
private String city;
private String propertyId;
Package: com.wipro.hms.dao
Class Method and Variables Description
RentalProp DAO class
ertyDAO
public String This method should return the propertyId
generatePropertyID(String city) which is auto generated using sequence.
Format: First 3 letters of the city in uppercase
followed by the 4 digit auto generated
number.
E.g. CHE1000 – if the city name is Chennai
public int This method should invoke
createRentalProperty(RentalProp the generatePropertyIDmethod of this class,
ertyBean bean) receive the id and initialize the bean with the
id value.
It should then insert the bean’s
properties into the rental_tbl and should return
the count of the records inserted
If there is some Exception(could be
SQLException or any other Exception), the
function should return -1.
Package: com.wipro.hms.service
Class Method and Variables Description
Rental Main class
Property
Service
public static void main(String[] The code that is needed to test your program
args) goes here. A sample code is shown at the end
of the document.
25
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Main Method:
You can write code in the main method and test all the above test cases. A sample code of
the main method to test a test case is shown below for your reference.
public static void main(String[] args) {
RentalPropertyBean bean=new RentalPropertyBean();
bean.setCity("Chennai");
bean.setLocation("Velachery");
bean.setNoOfBedRooms(2);
bean.setRentalAmount(15000);
RentalPropertyService service=new RentalPropertyService();
System.out.println(service.addRentalProperty(bean));
}
Project Assessment
26
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
3. Understand the project requirements and ACCORDINGLY WRITE the code and logic in
the classes and methods so as to meet all given requirements.
Creating the project
1. You are expected to create your project locally using eclipse (or any other IDE) on your
desktop.
Project Objective:
An online application needs to be created for entering weather reports for various locations and
later for viewing the reports.
Note: This application will cover only limited functionalities for the assessment.
Sample Output:
menu.html
27
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
If there is any error while adding the record, the following page should be displayed.
error.html
2. If “View Forecast” link is Clicked on menu.html, the below given page should be displayed
viewForecast.jsp
If matching records exists in the database, display the schedule details in the below given page.
displayForecast.jsp
28
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Project Design:
A. Database Design:
1. Create a new user in database [ To be done in the backend by using sql commands ]
a) Note: Use the default scott/tiger account of oracle for this project. You will have to create
a new user in the below mentioned format.
c) For JDBC connection, only use orcl as service name and 1521 as port number
3. Create Table [ To be done using sql commands, after logging-in as the new user that
has been created in above step ]
29
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.weather.util
Package: com.wipro.weather.bean
Class Method and Variable Names Description
WeatherBean Bean Class
String reportId ID number of the weather report
String location Location
Date date java.util.Date
int humidity Humidity
30
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.weather.dao
Class Method and Description
Variables
WeatherDAO DAO class
public String This method is used to insert the weatherBean
createForecast(Weat attributes into the WEATHER_TB table
herBeanweatherBea If the insertion is successful, this method should
n) return the reportId of the weatherBean
It returns “FAIL” if the value is not inserted
public This method is used to fetch the weather report of
WeatherBeanfetchFo a specific location on a specific date from the
recast(String WEATHER_TB table.
location, Date date) If no records are found, this method will return
null.
public String This method is used to generate the reportId of
generateReportID(St the Weather forecast before the report is stored in the
ring location,Date WEATHER_TB table.
date) The reportId should be a combination of the
date in YYYYMMDD format followed by first two
letters of location in uppercase followed by a two
digit random number generated by the sequence
WEATHER_SEQ
ie. If the date entered is 14 Dec 2015 and the
location is Bengaluru then the reportId should be
20151214BE11 where 11 is the number generated from
sequence.
31
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.weather.service
Class Method and Description
Variables
Administrator
public String This method receives a WeatherBean object
addForecast(Weath The following checks need to be made before
erBeanweatherBean proceeding further
) 1. If the weatherBean object is null or location is null
or date is null, then this should throw an
InvalidInputException and return the exception
message “INVALID INPUT”
2. If the length of location name is less than 2
characters then it should return “INVALID
LOCATION”
3. The date should be a future date. If the date is in
the past or current date, then it should return “INVALID
DATE”
4. Calls the reportExists(String location,Date
date) method of WeatherDAO to check whether the
report already exists for the given location and date. If
exists, then it should return “ALREADY EXISTS”
Otherwise calls generateReportID(String
location,Date date)ofWeatherDAO which will return a
reportId
If the reportId is successfully generated, initialize
the weather bean id and
call createForecast(WeatherBeanweatherBean) of
WeatherDAO and return a string indicating the status of
the operation
public This method receives a location and date
WeatherBeanviewF It should call fetchForecast(String location, Date
orecast(String date) of WeatherDAO and will return the matching bean
location,Date date) object
Package: com.wipro.weather.servlets
Class Method and Description
Variables
MainServlet Servlet Class
public String This method is invoked by the
addForecast(HttpSer doPost(HttpServletRequest request, HttpServletResponse
vletRequest request) response) method of the Servlet Class if the Client has
clicked on ‘Add Forecast’ link in the menu page
32
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
33
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
34
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Project Assessment
Create a console based Java application that allows the university admin to validate and add
school or college students, calculate grade points and display the final grade on the basis of
marks obtained.
Project Design:
Create a sequence STUD_SEQ starting with 1000 and incrementing by 5.
Create the STUD_DETAILS table with the following columns :
Note: only these fields need to be added in database.
Column Name Data_Type
studentId Varchar(7)
studentName Varchar(25)
studentAge Integer
studentType Varchar(1)
StudentAdmNo Integer
studentGP Integer
A. System Design:
Name of the package Usage
com.wipro.ums.bean This package will contain the bean classes
com.wipro.ums.util This package will contain the user defined exception class
com.wipro.ums.main This package will contain the main class that is used to test the
application
com.wipro.ums.service This package will contain the class that is used to validate the
data and calculate the result
com.wipro.ums.dao This package will contain the class that is used to add students
details to the database.
Package: com.wipro.ums.util
Class Method and Variables Description
StudentValidationException An Exception Class
public String toString() Returns the message
“Invalid Student Details”
Package: com.wipro.ums.bean
Class Method and Variables Description
StudentBean Abstract Class
public StudentBean() Zero argument constructor
String studentId Unique five digit Student ID
String studentName Student name
intstudentAge Student age
char studentType Student type
intStudentAdmNo Five digit admission number of the
student
intstudentMarks[] Array of marks in six subjects
intstudentGP Grade point obtained by student
36
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.ums.bean
Class Method and Variables Description
SchoolStudentBean Class
public SchoolStudentBean() Zero argument constructor
public intcalcGradePoints(int[] This method accepts the marks
marks) array, calculates average marks by
diving sum of all marks[i] by
length of the array.
Then it computes and returns the
grade points (as given in the “Table
for School Student”) on the basis
of average marks calculated.
It should return -1 for any case not
specified in table.
public String It calculates and returns the student
calcGrade(intsGradePoint) grade on the basis of sGradePoint.
Refer the grading given in the
“Table for School Student”.
It should return null for any case
not specified in table.
Package: com.wipro.ums.bean
Class Method and Variables Description
College Class
Student
Bean
public Zero argument constructor
CollegeStudentBean()
public This method accepts the marks array, calculates
intcalcGradePoints(int[] average marks by diving sum of all marks[i] by
marks) length of the array.
Then it computes and returns the grade points (as
given in the “Table for College Student”) on the
basis of average marks calculated.
It should return -1 for any case not specified in
table.
public String It calculates and returns the student grade on the
calcGrade(intsGradePoint) basis of sGradePoint.
37
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.ums.dao
Class Method and Variables Description
StudentDA Class
O
public String This method adds the studBean to the
addStudent(StudentBeanstudBean) STUD_TABLE.
It should return “SUCCESS” in case
student data has been added successfully.
It should return “FAILURE” in any other
case.
Package: com.wipro.ums.service
Class Method and Variables Description
Student Class
Service
public String generateID(String This method accepts studentName and
studentName, StudentAdmNo and generates studentId as
intStudentAdmNo) follows:
First two letters of studentName converted
38
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
39
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Project Assessment
40
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
If there is any error while adding the record, the following page should be displayed.
41
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
errorInserting.html
2. If “View Schedule” link is Clicked on menu.html, the below given page should be
displayed
viewSchedule.jsp
If matching records exists in the database, display the schedule details in the below given page.
displaySchedule.jsp
42
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Project Design:
A. Database Design:
1. Create a new user in database [ To be done in the backend by using sql commands ]
a) Note: Do NOT use the default scott/tiger account of oracle for this project. You will have
to create a new user in the below mentioned format.
b) Username/password : B<batchnumber><employeeid>
For example, if your batch number is 39806 and Employee number is 12345, then the oracle user
should be B3980612345 and the password should be B3980612345
c) For JDBC connection, only use orcl as service name and 1521 as port number
3. Create Table [ To be done using sql commands, after logging-in as the new user that
has been created in above step ]
43
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.bus.util
Class Method and Variables Description
DBUtil DB connection class
static Establish a connection to
Connection getDBConnection() the database and return the
java.sql.Connection
reference
Package: com.wipro.bus.bean
Class Method and Variable Description
Names
ScheduleBea Bean Class
n
String scheduleId ID number of the schedule
String source Source of bus schedule
String destination Destination of bus schedule
String startTime Start time of bus
String arrivalTime Arrival time of the bus
Setters and Getters for Using Eclipse, create getters and setters for all the
all properties properties
Package: com.wipro.bus.dao
Class Method and Variables Description
ScheduleDA DAO class
O
public String This method receives a ScheduleBean object
44
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.bus.service
Class Method and Variables Description
Administrato
r
public String This method receives a ScheduleBean object
addSchedule(Schedule Refer testcases given at the end of the
Bean scheduleBean) document and perform the necessary validations.
If same source and destination is provided
should give back a message “Source and
Destination Same”
If validation is successful, then
Call generateID(String source, String
destination) from dao which will return a schedule
ID and store the same in the bean.
Invoke createSchedule(ScheduleBean
scheduleBean) from dao and return the string value
For other user defined error messages, please look at
the test cases given at the end of the document.
publicArrayList<Sched This method receives the names of source and
uleBean> destination and returns an ArrayList of
viewSchedule(String ScheduleBean with matching records.
source,String
destination)
Package: com.wipro.bus.servlets
Class Method and Variables Description
45
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
46
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
47
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
48
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Project Assessment
49
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
3. Understand the project requirements and ACCORDINGLY WRITE the code and logic in
the classes and methods so as to meet all given requirements.
Creating the project and testing it –
1. You are expected to create your project locally using eclipse (or any other IDE) on your
desktop.
Project Objective:
Azim Premji University maintains a library of Books written by their faculty members which are
published by different Publishers. Develop a web based application that helps the librarian to
perform some basic operations like
a) Adding a book to the database
b) Fetching the details of the book including the Author information
Menu.html
50
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
On Successful Insert, the user should be directed to the menu.html page again.
51
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
View.jsp
Invalid.html
52
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Project Design:
A. Database Design:
1. Create a new user in database [ To be done in the backend by using sql commands ]
a) Note: Do NOT use the default scott/tiger account of oracle for this project. You will have
to create a new user in the below mentioned format.
b) Username/password : B<batchnumber><employeeid>
For example, if your batch number is 39806 and Employee number is 12345, then the oracle user
should be B3980612345 and the password should be B3980612345
c) For JDBC connection, only use orcl as service name and 1521 as port number
3. Create Table [ To be done using sql commands, after logging-in as the new user that
has been created in above step ]
Sample Input:
AUTHOR_CODE AUTHOR_NAME CONTACT_NO
----------- -------------------- ---------------------------------------
1 RobinSharma 8800799224
2 R.K.Narayan 9971935000
3 Paulo Coelho 1234567890
53
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.book.util
Class Method and Variables Description
DBUtil DB connection class
public static Establish a connection to the
Connection getDBConnection() database and return the
java.sql.Connection reference
Package: com.wipro.book.bean
Package: com.wipro.book.dao
54
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
55
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.book.service
56
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
Package: com.wipro.book.servlets
Class Method and Variables Description
MainServle Servlet Class
t
public String This method is invoked by the
addBook(HttpServletReques doPost(HttpServletRequest request,
t request) HttpServletResponse response) method of the
Servlet Class if the Client has clicked on ‘Add
Book’ link in the menu page
This method will create a BookBean Object
and will initialize all its properties with the values
that are available in the request object
It will invoke the Administrator class’s
addBook(BookBean bookBean) by passing the
BookBean object that was initialized
The method will return the String value
received from addBook(BookBean bookBean)
method
public BookBean This method will invoke the
viewBook(String isbn) viewBook(String isbn) method of the
Administrator Class and it should return the
BookBean object received
void This method processes the Client’s request
doPost(HttpServletRequest It accesses a request parameter called
request, ‘operation’ and based on the value of that
HttpServletResponse parameter, it’ll decide whether to access the
response) throws addBook(HttpServletRequest request) or
57
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
58
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
59
1151CS302-JAVA PROGRAMMING LAB LAB MANUAL
60