ASSIGNMENTS

                            BASICS OF PROGRAMMING

QUESTION 1:
Search for a name
Write a program to accept an array of names and a name and check whether thename is present in the array. Return the count of occurrence. Use the following array as input
{“Dave”, “Ann”, “George”, “Sam”, “Ted”, “Gag”, “Saj”, “Agati”, “Mary”, “Sam”,
“Ayan”, “Dev”, “Kity”, “Meery”, “Smith”, “Johnson”, “Bill”, “Williams”, “Jones”,
“Brown”, “Davis”, “Miller”, “Wilson”, “Moore”, “Taylor, “Anderson”, “Thomas”,
“Jackson”}
Improve the understandability of the below given code:
import java.util.*;
class problem3
{
int[] numArray = new int[10];
public static void incrementElements (int[] integerArray)
{
int arraylen = integerArray.length;
for (int i = 0; i < arraylen; i ++)
{
System.out.println(integerArray[i]);
}
for (int i = 0; i < arraylen; i ++)
{
integerArray[i] = integerArray[i] + 10;
}
for (int i=0; i < arraylen; i ++)
{
System.out.println(integerArray[i]);
}
}
QUESTION2:
Greatest common divisor
Calculate the greatest common divisor of two positive numbers a and b.
gcd(a,b) is recursively defined as
gcd(a,b) = a if a =b
gcd(a,b) = gcd(a-b, b) if a >b
gcd(a,b) = gcd(a, b-a) if b > a
Improve the understandability of the below given code:
class Problem1
{
int[] a;
int nElems;
public ArrayBub(int max)
{
a = new int[max];
}
public void insert(int value)
{
a[nElems] = value;
nElems++;
}
public void Sort()
{
int out, in;
for(out=nElems-1; out>1; out–)
for(in=0; in<out; in++)
if( a[in] > a[in+1] )
swap(in, in+1); }
public void swap(int one, int two)
{
long temp = a[one];
a[one] = a[two];
a[two] = temp;
}
                                                   DATABASE CONCEPTS
Question 1: Provide the create table syntax to Create a Table Employee whose details are as below.
Employee(EmployeeID, LastName, FirstName, Address, DateHired)
Soln: create table Employee( EmployeeID int(6) primary key,LastName varchar(20),FirstName varchar(20),Address varchar2(50),date date );
Question 2: Provide the INSERT query to be used in Employee Table to fill the Details.
Soln: Insert into Employee values( 100,’gourav’,'kishan’,'hyderabad’,date);
Question 3: When we give SELECT * FROM EMPLOYEE .How does it Respond?
Soln: when we type the following query of select * from employee it returns all the data present that is all the columns in employee table. In this case it shows the above values in the insert statement.
Question 4: Create a Table CLIENT whose details are as below.
Client(ClientID, LastName, FirstName, Balance, EmployeeID)
Soln: create table Client(ClientID int(6), LastName varchar(20), FirstName varchar(20), Balance float(10) , EmployeeID foreign key references Employee(EmployeeID));
Question 5: Provide the INSERT query to be used in CLIENT Table to fill the Details.
Soln: INSERT INTO Client(ClientID,LastName,FirstName,Address, EmployeeId) Values (value1,value2,value3,value4 );
We can also use dynamic way to insert values into the table using the ‘&’ operation EX (‘& value1′,’&value2′ and so on … )
Question 6: When we give SELECT * FROM CLIENT .How does it Respond?
Soln: It returns all the rows and columns present in the client table . that is it shows all the field data of client table.
Question 7: Choose the correct answer. The SQL command to create a table is:
a. Make Table
b. Alter Table
c. Define Table
d. Create Table
Soln: d (Create table)
Question 8: Choose the correct answer. The DROP TABLE statement:
a. deletes the table structure only
b. deletes the table structure along with the table data
c. WORKS whether or not referential integrity constraints would be violated
d. is not an SQL statement
Soln: b (Deletes the table structure along with the table data)
Question 9: What are the different data types available in SQL server?
Soln:
1) Numeric :  Stores numeric values.
2) Monetary : It stores numeric values with decimal places. It is used specially for currency values.
3) Date and Time : It stores date and time information.
4) Character : It supports character based values of varying lengths.
5) Binary : It stores data in strict binary (0 or 1) representation.
6) Special purpose: SQL Server contains Complex data types to handle the XML Documents,Globally unique identifiers etc.
Question 10: Which is the subset of SQL commands used to manipulate Oracle Database structures, includingtables?
Soln: DDL( Data Deifinition Language)
Question 11: What operator performs pattern matching?
Soln:  LIKE Operator
Question 12: What operator tests column for the absence of data?
Soln: IS NULL Operator
Question 13: Which command executes the contents of a specified file?
Soln:  START or @ Command
Question 14: What is the parameter substitution symbol used with INSERT INTO command?
Soln: ‘&’ commonly known as ampersand operator
Question 15: Which command displays the SQL command in the SQL buffer, and then executes it?
Soln: RUN
Question 16: What are the wildcards used for pattern matching?
Soln: _ and %
_ = single character substitution
% = multiple character substitution
Question 17: State whether true or false.
EXISTS, SOME, ANY are operators in SQL.
Soln: TRUE
Question 18: State whether true or false
!=, <>, ^= all denote the same operation.
 Soln: TRUE
Question 19: What are the privileges that can be granted on a table by a user to others?
Soln: Insert, update, delete, select, references, index, execute, alter, all
Question 20: What command is used to get back the privileges offered by the GRANT command?
Soln: REVOKE
Question 21: Which system tables contain information on privileges granted and privileges obtained?
Soln: USER_TAB_PRIVS_MADE,
USER_TAB_PRIVS_RECD
Question 22: Which system table contains information on constraints on all the tables created?
Soln: USER_CONSTRAINTS
Question 23: What is the difference between TRUNCATE and DELETE commands?
Soln:
1. Delete is a DML command and Truncate is a DDL command.
2. Where clause can be used with delete only.
3. THE Delete operation can be rolled back, Truncate operation cannot be rolled back again that is it is a permanent delete. 

Question 24: What command is used to create a table by copying the structure of another table?
Soln: CREATE TABLE .. AS SELECT command
Explanation :
To copy only the structure, the WHERE clause of the SELECT command should contain aFALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.

                                   JAVA BASICS 1

Introduction to Java basics 1


1.Write a program to find the difference between sum of the squares and the square of the sums of n numbers?
2.Develop a program that accepts the area of a square and will calculate its perimeter.
3.Develop the program calculateCylinderVolume., which accepts radius of a cylinder’s base disk and its height and computes the volume of the cylinder.
4.Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program calculateTax which determines the tax on the gross pay. Define calculateNetPay that determines the net pay of an employee from the number of hours worked. Assume an hourly rate of $12.


5.n old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes the number of attendees (of a show) and calculates how much income the show earns.
6.Develop the program calculateCylinderArea, which accepts radius of the cylinder’s base disk and its height and computes surface area of the cylinder.
7.Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall.
8.Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g· t in t time units and a height of 1/2*v*t where v is the speed at t.
9.Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat’s speed perpendicular to the river, and the river’s speed. Speed is distance/time, and the Pythagorean Theorem is c2=a2 + b2.
10.Develop a program that accepts an initial amount of MONEY (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional deposits or withdrawals are made and that a month is 1/12 of a year. Total interest is the product of the principal, the annual interest rate expressed as a decimal, and the number of years.

                                               JAVA BASICS 2

.Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes
2.Create a calculator class which will have methods add, multiply, divide & subtract
3.Create a class called Student which has the following methods:                                 i. Average: which would accept marks of 3 examinations & return whether the student has passed or failed depending on whether he has scored an average above 50 or not.                                                                                                        ii. Inputname: which would accept the name of the student & returns the name.
4.Create a Bank class with methods deposit & withdraw. The deposit method would accept attributes amount & balance & returns the new balance which is the sum of amount & balance. Similarly, the withdraw method would accept the attributes amount & balance & returns the new balance ‘balance – amount’ if balance > = amount or return 0 otherwise.
5.Create an Employee class which has methods netSalary which would accept salary & tax as arguments & returns the netSalary which is tax deducted from the salary. Also it has a method grade which would accept the grade of the employee & return grade.
6.Create Product having following attributes: Product ID, Name, Category ID and UnitPrice. Create ElectricalProduct having the following additional attributes: VoltageRange and Wattage. Add a behavior to change the Wattage and price of the electrical product. Display the updated ElectricalProduct details.
7.Create Book having following attributes: Book ID, Title, Author and Price. Create Periodical which has the following additional attributes: Period (weekly, monthly etc…) .Add a behavior to modify the Price and the Period of the periodical. Display the updated periodical details.
8.Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons…).Add a behavior to change the color and loading capacity. Display the updated truck details.
9.Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results.
10.Write a function Model-of-Category for a Tata motor dealers, which accepts category of car customer is looking for and returns the car Model available in that category. the function should accept the following categories “SUV”, “SEDAN”, “ECONOMY”, and “MINI” which in turn returns “TATA SAFARI” , “TATA INDIGO” , “TATA INDICA” and “TATA NANO” respectively. 

                                           UNIX BASICS 1 

Question 1: Write a command to list all the files inside a folder i.e. if there is a folder inside a folder then it should list all files inside the sub-folder which is inside the folder to be listed.
Answer 1:  ls -R
Question 2: Search all the files which contains a particular string, say “include” within a folder.
Answer 2:  for i in *.*; do grep -l include $i; done
Question 3: Rename all the files within a folder with suffix “Unix_” i.e. suppose a folder has two files a.txt and b.pdf than they both should be renamed from a single command to Unix_a.txt and Unix_b.pdf
Answer 3:   for i in *.*; do mv $i Unix_$i; done ;
Question 4: Rename all files within a folder with the first word of their content(remember all the files should be text files. For example if a.txt contains “Unix is an OS” in its first line then a.txt should be renamed to Unix.txt
Answer 4:  for i in *.txt; do j= “$(head -1 $i | cut -f1-d” “).txt”; mv “$i” “$j”; done
Question 5:  Suppose you have a C project in a folder called “project”, it contains .c and .h files, it also contains some other .txt files and .pdf files. Write a Linux command that will count the number of lines of your text files. That means total line count of every file. (remember you have to count the lines in .txt files only)
Answer 5 : wc -l *.txt
Question 6 : Rename all files which contain the sub-string ‘foo’, replacing it with ‘bar’ within a given folder.
Answer 6 : for i in ./*foo*; do mv “$i” “${i//foo/bar}”;done
Question 7 : Show the most commonly used commands from “history”. [hint: remember the history command, use cut, and sort it.

Answer 7   :  history |cut -f6- -d” ” | sort

                                              UNIX BASICS 2 

1. Create a tree structure named ‘training’ in which there are 3 subdirectories – ‘level 1’,’ level2’ and ‘cep’. Each one is again further divided into 3. The ‘level 1’ is divided into ‘sdp’, ‘re’ and ‘se’. From the subdirectory ‘se’ how can one reach the home directory in one step and also how to navigate to the subdirectory ‘sdp’ in one step? Give the commands, which do the above actions?
Ans : To navigate from ‘se’ to home directory,in one step,the command is : cd
       To navigate from ‘se’ to ‘sdp’,in one step,the command is : cd ../b
2. How will you copy a directory structure dir1 to dir2 ? (with all the subdirectories)
Ans : cp –R dir1 dir2
3. How can you find out if you have the permission to send a message?
Ans : ls -l ( To check access permissions)
4. Find the space occupied ( in Bytes) by the /home directory including all its subdirectories.
Ans : du -s -b
5. What is the command for printing the current time in 24-hour format?
Ans : date +%T
6. What is the command for printing the year, month, and date with a horizontal tab between the fields?
Ans : date +%Y%t%B%t%e
7. Create the following files: chapa, chapb, chapc, chapd, chape, chapA, chapB, chapC, chapD, chapE, chap01, chap02, chap03, chap04, chap05, chap11, chap12, chap13, chap14, and chap15.
Ans :The general syntax is :
cat > filename
Type the contents of file
Press Ctrl+D

cat > chapa
Type the contents of file
Ctrl+D

Cat > chapb
Type the contents of file
Ctrl+D

Cat > chapc
Type the contents of file

Cat > chapd
Type the contents of file
Ctrl+D

Cat > chape
Type the contents of file
Ctrl+D

Cat > chapA
Type the contents of file
Ctrl+D

Cat > chapB
Type the contents of file
Ctrl+D


Cat > chapC
Type the contents of file
Ctrl+D

Cat > chapD
Type the contents of file
Ctrl+D

Cat > chapE
Type the contents of file
Ctrl+D


Cat > chap01
Type the contents of file
Ctrl+D

Cat > chap02
Type the contents of file
Ctrl+D

Cat > chap03
Type the contents of file
Ctrl+D

Cat > chap04
Type the contents of file
Ctrl+D

Cat > chap05
Type the contents of file
Ctrl+D

Cat > chap11
Type the contents of file
Ctrl+D

Cat > chap12
Type the contents of file
Ctrl+D

Cat > chap13
Type the contents of file
Ctrl+D

Cat > chap14
Type the contents of file
Ctrl+D

Cat> chap15
Type the contents of file
Ctrl+D
8. With reference to question 7, What is the command for listing all files ending in small letters?
Ans : find –name “*[a-z].*”
9. With reference to question 7, What is the command for listing all files ending in capitals?
Ans : find –name “*[A-Z].*”
10. With reference to question 7, What is the command for listing all files whose last but one character is 0?
Ans : find –name “*0?.*”
11. With reference to question 7, What is the command for listing all files which end in small letters but not ‘a’ and ‘c’?
Ans: find –name “*[b d-z].*”
12. In an organisation one wants to know how many programmers are there. The employee data is stored in a file called ‘personnel’ with one record per employee. Every record has field for designation. How can grep be used for this purpose?
Ans : grep -c “programmers” personnel
13. In the organisation mentioned in question 12 how can sed be used to print only the records of all employees who are programmers.
Ans : sed -n /programmers/p personnel
14. In the organisation mentioned in question 12 how can sed be used to change the designation ‘programmer’ to ‘software professional’ every where in the ‘personnel’ file
Ans :  sed ‘s/programmer/software professional/g’ personnel
15. Find out about the sleep command and start five jobs in the background, each one sleeping for 10 minutes.
Ans :sleep 10m & sleep 10m & sleep 10m & sleep 10m & sleep 10m &
16. How do you get the status of all the processes running on the system? i.e. using what option?
Ans : ps -e

                                           WEB TECHNOLOGY


Scenario: Online Shopping Portal
XYZ.com wants to create an online shopping portal for managing its registered customers and their shopping.
The customers need to register themselves first before they do shopping using the shopping portal. However, everyone, whether registered or not, can view the various products along with the prices listed in the portal.
The registered customers, after logging in, are allowed to place order for one or more products from the products listed in the portal. Once the order is placed, the customer gets a reference order number and the order status should be “order in process”.
The customers can track their order using the given reference number.
The management of XYZ.com should be able to modify the order status of a particular reference order number to “shipped” once the products are shipped to the shipping address entered by the customer at the time of placing the order.
Can you help XYZ.com to realize their dream of having an online shopping portal?
Steps to be followed
Create the interface for the XYZ.com shopping portal using HTML/XHTML and CSS.
Implement the client side validations using JavaScript.
Create the tables using MySQL.
Implement the functionality using the server side scripting language, PHP.
Integrate all the above tasks and make the XYZ.com shopping portal functional.
Note: Please zip your casestudy files and upload it here. You can submit only one file

1 comment:

comment here....