Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
507 views

Assignments - PR 101 - Basic - Java

Here are the steps to create the tables for the department store database schema with constraints: 1. Create a cluster called Supp_Product: CREATE CLUSTER Supp_Product ( SuppNo NUMBER(4) ) SIZE 512; 2. Create the tables with constraints: CREATE TABLE Section ( SectionNo NUMBER(2) CONSTRAINT Section_PK PRIMARY KEY, Description VARCHAR2(30) CONSTRAINT Section_Desc_NN NOT NULL, Section_Head_EmpNo NUMBER(4) CONSTRAINT Section_Head_FK REFERENCES Employees(EmpNo) ); CREATE TABLE Employees ( EmpNo NUMBER(4) CONSTRAINT Employees_PK PRIMARY KEY, First_

Uploaded by

prathameshr_3
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
507 views

Assignments - PR 101 - Basic - Java

Here are the steps to create the tables for the department store database schema with constraints: 1. Create a cluster called Supp_Product: CREATE CLUSTER Supp_Product ( SuppNo NUMBER(4) ) SIZE 512; 2. Create the tables with constraints: CREATE TABLE Section ( SectionNo NUMBER(2) CONSTRAINT Section_PK PRIMARY KEY, Description VARCHAR2(30) CONSTRAINT Section_Desc_NN NOT NULL, Section_Head_EmpNo NUMBER(4) CONSTRAINT Section_Head_FK REFERENCES Employees(EmpNo) ); CREATE TABLE Employees ( EmpNo NUMBER(4) CONSTRAINT Employees_PK PRIMARY KEY, First_

Uploaded by

prathameshr_3
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Education and Research Department

Assignments for
PR 101 J2EE Foundation Package
Jan 2008

Document no: ER/CORP/CRS/J2EE-PR101/004


Authorized By Ver. Revision Signature / Date
Srikantan Moorthy Ver.3.1 Jan-2008

COMPANY CONFIDENTIAL
Infosys Document Revision History

Document Revision History

Ver.
Date Author(s) Reviewer(s) Description
Revision
3.1 Jan -2008 Amandeep Thind Rahul Ghali Baseline

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 ii


Infosys Assignment for PR 101 J2EE Foundation Package

Contents

Assignment for Basic Java Programming…………4


Assignment for Adv. Java Programming…………5
Assignment for Oracle……………………………..7

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 3


Infosys Assignment for PR 101 J2EE Foundation Package

Assignment for Basic Java Programming

Assignment 1:
Write the Java class CommandArg to accept the two numbers through
command line. Convert the numbers to integer type, perform the addition and print
the result on the screen.(Hint : Use Wrapper classes)
(Approx time : 10 min)

Assignment 2:
Create an applet MyApplet which takes User’s first name and last name from
the html file as parameter and displays it in the applet and the status bar of the
applet as a String.
(Approx time : 10 min)

Assignment 3:
Write a java program to accept a String from command line. Breakup the
above String into a char Array and print them one by one.
(Approx time : 10 min)

Assignment 4:
Create your own exception class. Write a constructor for this class that takes
a String argument and stores it. Write a method that prints out the stored String.
Use try-catch to practice the exception created by your class.
(Approx time : 10 min)
Assignment 5:
Create a class MySuper in a package MySuperpack. Create another class
MySub in another package MySubPackage. MySub overrides a method add() define
in MySuper. MySub should call MySuper’s version of add() and also the overridden
version.(Hint :Use super)
(Approx time : 15 min)

Assignment 5:
Create a JApplet in Swing to create a Course enrollment form with appropriate
components and event handlers.
(Approx time : 25 min)

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 4


Infosys Assignment for PR 101 J2EE Foundation Package

Assignment for Advance Java Programming

Assignment 1:
Create a programmer defined thread class by extending the java.land.Thread
class. Override the run() method to print the message “Hello Threads”. Write
another program to create 5 instances of above thread which will run
simultaneously.
(Approx time : 15 min)

Assignment 2:
Write the above program using java.lang.Runnable interface.
(Approx time : 10 min)

Assignment 3:
Modify the above program to print the same message 5 times. Use the
sleep() method to sleep the thread for some time. Try with changing the priority of
the threads.
(Approx time : 10 min)
Assignment 5:
Write the Java program to store following string into BigJava.dat file.
“Welcome to the world of Java Programming”. Use the java.io.FileOutputStream
class for the writing the string.
(Approx time : 20 min)
Assignment 6:
Write another java program to copy the contents of file BigJava.dat to
SmallJava.dat file. Use java.io.FileInputStream class to perform the copy.
(Approx time : 10 min)

Assignment 7:
Modify the above assignment such that input and output operations are
performed with buffering using BufferedInputStream and BufferedOutputStream.
(Approx time : 10 min)

Assignment 8:
To write a program that read several types of information from files: binary,
Java objects, text, zipped files, etc.

HINT : Read text files using the classes FileReader, BufferedReader, FileWriter, and
BufferedWriter. It is without a graphical user interface, taking parameters from the
command line.
(Approx time : 15 min)

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 5


Infosys Assignment for PR 101 J2EE Foundation Package

Assignment 9:
To write a program that uses BufferedReaderStream and its readLine()
method to count the number of white space characters in the input.

(Approx time : 20 min)

Database : For assignment no. 10 to 12, create a table Employee having the
following fields EmpID, EmpName and Age. Make the EmpID field as a sequence.
Insert valid data into the table like

EmpID EmpName Age


101 John 35
102 Harry 25
103 Potter 40

Assignment 10:
To write a program to insert data into a table using java.sql.Statement
interface.

HINT: executeUpdate() method returns an int as to how many rows got affected.So if
the return value is 0 it indicates that insertion failed.
(Approx time : 20 min)

Assignment 11:
To write a program to insert data into a table using PreparedStatement.

(Approx time : 15 min)

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 6


Infosys Assignment for PR 101 J2EE Foundation Package

Assignments for Oracle


Create the following table with given constraints

• Section ( SectionNo Number(2), Description Varchar2(30),


Section_Head_EmpNo)

• Employees( EmpNo Number(4), First_Name Varchar2(30), Last_Name


Varchar2(30), Address Varchar2(30), Grade Number(2), Salary Number(9,2),
SectionNo Number(2), Date_Joined Date)

• Customers( CustNo Number(4), First_Name Varchar2(30), Last_Name


Varchar2(30), CustType char(1), Credit_Limit Number(7,2), Credit_Card_No
Number(16), Credit_Card_Type Varchar2(8))

• Suppliers (SuppNo Number(4), Name Varchar2(30), Address Varchar2(30), City


Varchar2(30) )

• Products (ProductNo Number(4), Product_Category_Code Char(3), Description


Varchar2(30), Price Number(9,2), Qty_On_Hand Number(5))

• Product_CategoryMaster( Product_Category_Code Char(3), Description


Varchar2(15))

• Suppliers_Products ( SuppNo Number(4), ProductNo Number(4),


Date_Supplied Date, Qty_Supplied Number(5))

• Customers_Products( CustNo Number(4), ProductNo Number(4),


Date_of_Purchase Date, Qty_Purchased Number(5))

Constraints
• The column names which have been underlined are the primary keys for the
tables.
• Employees can belong to only one section
• Customers can be of two types Regular and Ad-hoc
• Maximum credit limit allowed is Rs. 10000.
• Quantity of goods supplied cannot be less than 0 and cannot be greater than
10000 for a particular supply.

Description
• A department store has many sections such as Toys, Cosmetics, Clothing,
Household Items, Electronics etc.
• Each section has many employees
• Each section also has a head who is responsible for the section’s performance.
• The department store also has many customer who purchase goods from
various sections

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 7


Infosys Assignment for PR 101 J2EE Foundation Package

• Regular customers get credit at the department store


• The store procures goods from various suppliers.
• The goods are stored in a warehouse and transferred to the store as and
when requirement comes up

1. Create a cluster called Supp_Product.

2. Create the tables with all appropriate constraints. Use the constraints
UNIQUE, NOT NULL, CHECK , PRIMARY KEY, FOREIGN KEY etc.
wherever necessary. Add the tables Suppliers and Supliers_Products to
the cluster Supp_Product. Create an index on the cluster
Supp_Product.

3. Create a sequence called Seq_Product which will start at 1 and


increment by 1. Try rolling back now. What happens? C

4. Add data to the master tables and then to the other tables using
INSERT INTO statements.
5. Add at least 2 rows in each of the master tables, and 5 rows in the
other tables. While inserting into the product table use
Seq_Product.

6. Commit all the changes that have been made so far.

7. Find all employees whose names begin with ‘A’ and end with ‘A’.

8. Find all products whose descriptions have the characters ‘me’ .

9. Find the total salary paid by each section to employees.

10. Display the section names and the names of the employees who
belong to that section.

11. Display the section name and the name of the person who heads the
section.

12. Display supplier names and cities. If the city is null, display ‘LOCAL’.
Use the NVL function for this.

13. Display the customer names and the customer type. If the customer
type is ‘R’ display ‘Regular’ , if the customer type is ‘A’ display ‘Ad-
hoc’. Use the DECODE function for this.

14. Try creating a view which when used, will display the supplier names,
product names , the quantity supplied and the date supplied for all
records in Supp_Products. The listing should be in alphabetical order of
supplier names.

15. A view with the above specs cannot be created. Why?

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 8


Infosys Assignment for PR 101 J2EE Foundation Package

16. How then will you meet the above requirement?

17. List all suppliers who have not supplied any products. Use an outer
join to do this.

18. Display the average salary of employees.

19. Display the customer no and the total number of products purchased
by him, for those customers who have purchased at least 2 or more
different products. Sort the listing in ascending order of customer
number.

20. Display the customer name and product names which have been
purchased by him. The customer and product names should be in
upper case.

21. Display the products that have been supplied more than a month ago.

22. Display employee names and the date joined for employees. Date
should be in the format ‘DD-MMM-YYYY’.

23. Display employee names and the number of months between today’s
date and the joining date.

24. Display product names and the price rounded to the nearest integer.

25. Find the product which has the greatest price in each category.

26. Write a PL/SQL block of code which will let you insert a record into the
Section table. Use variables to represent the values of section_no,
description and section_head_empno. Use anchored declarations for
these variables. What happens if you try to insert a value of
section_no which already exists in the section table?

27. Write a PL/SQL anonymous block which will insert 50 records into
test_table. Insert the current date value into the table. (Use SYSDATE
to get the system date). [To see the value of SYSDATE type the
following at the SQL Prompt: SELECT SYSDATE FROM DUAL;]. (create
a table called test_table, with 2 columns RecordNumber (type:
Number(3)) and CurrentDate(type: Date)).

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 9


Infosys Assignment for PR 101 J2EE Foundation Package

28. Do this using the following:

a) Declare a constant MAX_RECORDS which has a value of 50. Use


this value as the maximum number of records to be inserted
b) Do this using FOR loop, a While loop

29. At the SQL prompt, issue a ROLLBACK. Try displaying the records in
test_table. Can you see all the records? If not, how can you make sure
that the changes made by the block are permanent?

30. Given an employee number, display the following information to the


user:
Employee name (first_name + last_name)
Employee section no
Employee Designation
Obtain the designation as follows:
Grade Designation
1 Vice President
2 Senior Manager
3 Assistant Manager
4 Section Supervisor
5 Sales Assistant

Use the %ROWTYPE declaration for obtaining the employee


information from the tables.

31. Write a PL/SQL anonymous block, which will display the product no ,
product_category code, product category description, product
description , price and quantity on hand of all products which have a
quantity_on_hand of 1000 or more. Use a cursor to obtain the values
from the tables. Use a LOOP…END LOOP to fetch the rows from the
cursor. Remember to give an EXIT WHEN condition in the loop. Display
the row number of each record as it is fetched (Hint: use
%ROWCOUNT for this)

32. Write a PL/SQL anonymous block which will increase the price of all
products by 10%, for those products which are in the product category
‘Cosmetics’. Use a FOR..UPDATE clause with the cursor declaration for
this.

33. Modify problem 6 to retreive information of employees who been in the


company for at least 2 years. Additionally, retreive only the
mentioned fields from the table and use a RECORD type declaration in
the PL./SQL code. Use a FOR loop for fetching rows from the cursor.
Is this better than using a Loop..End Loop?

34. Write a PL/SQL anonymous block which will retreive customer names
and assign the concatenated name(first_name + last_name) to a
PL/SQL table. Display the names from the PL/SQL table.

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 10


Infosys Assignment for PR 101 J2EE Foundation Package

35. For each of the above blocks of code, add the appropriate exception
handlers. If you do not know of the exception which may occur, print
the sql error code and error message when an unknown exception
occurs.

36. In an anonymous block, insert a record into the Suppliers_Products


table. If the qty_supplied exceeds 10000, raise a user defined
exception which will print a message ‘ Quantity exceeds 10000 –
cannot insert record’ and rollback changes. (How else can you
implement this?)

ER/CORP/CRS/J2EE-PR101/004 Version No. 1.0 11

You might also like