Showing posts with label Aspire. Show all posts
Showing posts with label Aspire. Show all posts

Saturday, 2 June 2012

Study materials



Following are the links to enrich urself in UNIX


To learn the basic visit http://www.ida.liu.se/~TDDI05/labs/LXB%20-%20Linux%20Basics.pdf

To learn more about ls output check out, http://en.wikipedia.org/wiki/Ls#Sample_usage

To learn more about pipeline go to http://en.wikipedia.org/wiki/Pipeline_(Unix)

For a Unix Command Sheet ,Check out http://www.tuxfiles.org/linuxhelp/linuxcommands.html

Also Check http://www.pixelbeat.org/cmdline.html


Also refer this http://ebfa7577.linkbucks.com


TRY OUT THESE QUIZZES:
http://networking.ringofsaturn.com/Tools/quizzes.cgi?Action=Take&Quizid=3
http://www.ch.embnet.org/CoursEMBnet/Exercises/Quiz/quix1.html

U can evaluate urself  by doing EXAM in the following section: http://www.cs.wichita.edu/~chang/lecture/cs497c/
http://courses.cs.vt.edu/~cs2204/fall2001/quizzes.html

And to cover Java Basics,  http://greenteapress.com/thinkapjava/thinkapjava.pdf

Monday, 28 May 2012

WEB TECHNOLOGY ASSIGNMENT 1


Create a free account in www.4shared.com and download the file from the below mentioned link and upload it in Aspire portal :-)

The link for online shopping portal http://www.4shared.com/file/iiTMJTtk/online_shopping_portal_windows.html

Friends, if u cant able to download from the above link ,try with this https://sites.google.com/site/tcsassignmentsgcek/webtecassignment/Shopping_portal.zip?attredirects=0&d=1
Put the above link in your address bar and press enter.. hope u ll get 

Tuesday, 15 May 2012

CERTIFICATE FORMAT

As some of the TCSers received their joining dates, people are very much tensed in preparing the documents tat needs to be submitted on the DOJ.. here are the Certificate formats which ll guide u while preparing for it...

The link for SERVICE AGREEMENT SAMPLE:  https://docs.google.com/file/d/0B4KYmv5mCZIjTVY4OEZBdWxtelk/edit

The link for BIRTH CERTIFICATE AFFIDAVIT:
https://docs.google.com/document/d/1YDRKjOqVGAyTU4WuZm83dWpVmemEsxRbcgnUeQC2pcc/edit

The link for STUDYGAP CERTIFICATE FORMAT:
https://docs.google.com/document/d/1x5fCjF6jnhVqFTGSxHIHFoavXAjfoo_ubz6GD6TSchc/edit

The link for MEDICAL CERTIFICATE FORMAT:
https://docs.google.com/file/d/0B4KYmv5mCZIjODg0cEtfUTVLVEU/edit?pli=1
(from TCS confidential page 8 to 9)

The link for SURETY VERIFICATION FORM:
https://docs.google.com/file/d/0B4KYmv5mCZIjRkNrVE1rT3p4eTQ/edit
(from TCS confidential page 6 in JL annexure(2))




Friday, 11 May 2012

DATABASE CONCEPTS -ASSIGNMENT 1


Question 1:
 Provide the create table syntax to Create a Table Employee whose details are as below.
Employee(EmployeeID, LastName, FirstName, Address, DateHired)
http://ebfa7577.linkbucks.com Answer:
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.
Answer:
Insert into Employee values( 100,'gourav','kishan','hyderabad',date);

Question 3:
When we give SELECT * FROM EMPLOYEE .How does it Respond?
Answer:
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)
Answer:
create table Client(ClientID int(6), LastName varchar(20), FirstName varchar(20), Balance float(10) , EmployeeID foreign key references Employee(EmployeeID));
note: incase if we use both emp and client table in 1 db..or has a relation foreign key or not null and references are required else no needed.

Question 5:
Provide the INSERT query to be used in CLIENT Table to fill the Details.
Answer:
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?
Answer:
 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
Answer : 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
Answer : b ( deletes the table structure along with the table data)

Question 9:
What are the different data types available in SQL server?
Answer:
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, including tables?
Answer:
DDL( Data Deifinition Language).

Question 11:
 What operator performs pattern matching?
Answer:
LIKE Operator.

Question 12: What operator tests column for the absence of data?
Answer:
 IS NULL Operator.

Question 13:
Which command executes the contents of a specified file?
Answer:
START or @ command.

Question 14:
What is the parameter substitution symbol used with INSERT INTO command?
Answer:
'&' commonly known as ampersand operator.

Question 15: Which command displays the SQL command in the SQL buffer, and then executes it?
Answer: RUN.

Question 16: What are the wildcards used for pattern matching?
Answer:
_ and %
_ = single character substitution .
% = multiple character substitution.




Question 17:
State whether true or false.
EXISTS, SOME, ANY are operators in SQL.
Answer: TRUE.

Question 18:
State whether true or false.
!=, <>, ^= all denote the same operation.
Answer: TRUE.

Question 19:
What are the privileges that can be granted on a table by a user to others?
Answer: 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?
Answer: REVOKE.

Question 21:
Which system tables contain information on privileges granted and privileges obtained?
Answer :
USER_TAB_PRIVS_MADE,
USER_TAB_PRIVS_RECD .

Question 22:
 Which system table contains information on constraints on all the tables created?
Answer: USER_CONSTRAINTS.

Question 23: What is the difference between TRUNCATE and DELETE commands?
Answer:
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 cant 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?
Answer: 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 copiedto the new table.

Saturday, 5 May 2012

WEB TECHNOLOGY


Part 1 of 1 -     100.0 Points

Question 1 of 10    10.0 Points
Which of the following sequences of HTML tags is correct?

    A. <html><head></head><body><title></<title></body></html>  
     

    B. <html><head><title></<title><body></body></head></html>  
   

    C. <html><title></<title><head></head><body></body></html>  
   

    D. <html><head><title></<title></head><body></body></html>  
Answer Key: D
Feedback: <html><head><title></<title></head><body></body></html>


Question 2 of 10    10.0 Points
What does CSS stand for?

    A. Control Style Sheets    
     
   B. Cascading Style Sheets  
   
    C. Central Style Sheets  
   
    D. Common Style Sheets  

Answer Key: B




Question 3 of 10    10.0 Points
How would you define id selector?

    A. id selector as @  
   
     B. id selector as #  
   
    C. None of the above  
     
    D. id selector as $  

Answer Key: B





Question 4 of 10    10.0 Points
In an HTML document, which is the correct place to refer to an external style sheet?   

    A. In the <body> section  
   
    B. At the beginning of the document  
   
    C. In the <head> section  
   
    D. At the end of the document  

Answer Key: C




Question 5 of 10    10.0 Points
Which of the following tags would you use to insert JavaScript in an HTML page?

    A. <HTMLScript type="text/javascript"></HTMLScript>  
     
    B. <script type="text/javascript"></script>  
   
    C. <JavaScript type="text/javascript"></JavaScript>  
   
    D. <JScript type="text/javascript"></JScript>
 
Answer Key: B




Question 6 of 10    10.0 Points
The -------- JavaScript is also known as server-side JavaScript.

    A. Microsoft  
   
    B. Navigator  
   
    C. LiveWire  
     
    D. Native  

Answer Key: C




Question 7 of 10    10.0 Points
The following code would allow you to set background with CSS:
<style type="text/css">
body {background-color: yellow}
</style>

 True

 False

Answer Key: True




Question 8 of 10    10.0 Points
If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph?

    A. para1.nodeValue="New Text";    
     

    B. para1.value="New Text";    
   

    C. "New Text"?    
   

    D. para1.firstChild.nodeValue= "New Text";  

Answer Key: B




Question 9 of 10    10.0 Points
How does JavaScript store date in a date object?

    A. The number of days since January 1st, 1900    
   
    B. The number of seconds since Netscape's public stock offering.    
     
    C. The number of milliseconds since January 1st, 1970    
   
    D. None of the above    

Answer Key: C




Question 10 of 10    10.0 Points
How would you define First-line pseudo-element in CSS?

    A. selector:pseudo-elements {property: values}  
   
    B. selector:pseudo-element {property: value}  
   
    C. None of the above  
   
     D. select:pseudo-element {property: value}  

Answer Key: B

INTRODUCTION TO JAVA BASICS- ASSIGNMENT 2


1.Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent,switchOff. acceptClothes accepts the noofClothes as argument & returns the no of Clothes.
/*washing machine*/
 import java.util.*;
class  WashingMachine
{
Scanner input=new Scanner(System.in);
public void switchOn ()
{
System.out.println ("The lid is open.");
}
public void start ()
{
System.out.println ("Start washing ...");
}
public void acceptDetergent ()
{
System.out.println("Adding Detergent.. ");
start();
}
public int acceptClothes()
{
System.out.println("Enter no of clothes: ");
int no=input.nextInt();
return no;
}
public void switchOff ()
{
System.out.println ("The lid is closed.");
}
public static void main(String[] args)
{
WashingMachine wm=new WashingMachine();
wm.switchOn();
int numOFClothes=wm.acceptClothes();
wm.acceptDetergent();
wm.switchOff();
System.out.println(numOFClothes+" clothes get washed");
}
}





2.Create a calculator class which will have methods add, multiply, divide & subtract
/*calculator*/
 import java.util.*;
class Calculation
{
public int add(int a,int b)
{
return a+b;
}
public int subtract(int a,int b)
{
if(a>b)
{
return a-b;
}
else
{
return b-a;
}
}
public int multiply(int a,int b)
{
return a*b;
}
public int divide(int a,int b)
{
if(a>b)
{
return a/b;
}
else
{
return b/a;
}
}
}
public class Calculator
{
public static void main(String []args)
{
Calculation cal=new Calculation();
int add=cal.add(5,10);
int sub=cal.subtract(5,10);
int mul=cal.multiply(5,10);
int div=cal.divide(5,10);
System.out.println(add);
System.out.println(sub);
System.out.println(mul);
System.out.println(div);
}
}

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.    Input name: which would accept the name of the student & returns the name?




/*Student results*/
import java.util.*;
public class Student
{
 Scanner input=new Scanner(System.in);
public String average()
{
System.out.print("Enter Marks1: ");
double m1=input.nextDouble();
System.out.print("Enter Marks2: ");
double m2=input.nextDouble();
System.out.print("Enter Marks3: ");
double m3=input.nextDouble();
double tm=m1+m2+m3;
double avg=tm/3;
if(avg<50)
{
return "Failed";
}
if(avg>50)
{
return "Passed";
}
return " ";
}
public String getName()
{
System.out.println("Enter Name:");
String  name=input.nextLine();
String result=average();
return name+" get "+result;
}
public static void main(String[]args)
{
Student data=new Student();
String nameAndResut=data.getName();
System.out.println(nameAndResut);
}
}

4.Create a Bank class with methods deposit & withdraw. The deposit method would acceptattributes 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.

/*bank calculations*/
import javax.swing.*;
class  Customer
{
int bal;
Customer(int bal)
     {
this.bal = bal;
}
int deposit(int amt)
{
if (amt < 0)
{
System.out.println("Invalid Amount");
return 1;
}
bal = bal + amt;
return 0;
}
     int withdraw(int amt)
{
if (bal < amt)
{
System.out.println("Not sufficient balance.");
return 1;
}
if (amt < 0)
{
System.out.println("Invalid Amount");
return 1;
}
bal = bal - amt;
return 0;
}
void check()
{
JOptionPane.showMessageDialog(null,"Balance:" + Integer.toString(bal));
}
}
public class Bank
{
public static void main(String[]args)
{
Customer Cust=new Customer(1500);
String st1=JOptionPane.showInputDialog(null,"Enter the amount to deposit:");
int dep=Integer.parseInt(st1)  
int bal1=Cust.deposit(dep);
Cust.check();
String st2=JOptionPane.showInputDialog(null,"Enter the amount to withdraw:");
int with=Integer.parseInt(st2);
int bal2=Cust.withdraw(with);
Cust.check();
}
}
5. Create an Employee class which has methods netSalary which would accept salary & tax asarguments & returns the netSalary which is tax deducted from the salary. Also it has a methodgrade which would accept the grade of the employee & return grade.
/*employee sal & tax*/
import java.util.*;
class  Employee
{
static Scanner input=new Scanner(System.in);
public double netSalary(double salary, double taxrate)
{
double tax=salary*taxrate;
double netpay=salary=tax;
return netpay;
}
public static String grade( )
{
System.out.print("Enter Grade: ");
String grade=input.next();
return grade;
}
public static void main(String[] args)
{
Employee emp=new Employee();
System.out.print("Enter Salary: ");
double sal=input.nextDouble();
System.out.print("Enter Tax in %: ");
double taxrate=input.nextDouble()/100;
String g=emp.grade();
double net=emp.netSalary(sal,taxrate);
System.out.println("Net Salary is: "+net);
System.out.println("Grade is: "+g);
}
}

6.Create Product having following attributes: Product ID, Name, Category ID and UnitPrice. CreateElectricalProduct having the following additional attributes: VoltageRange and Wattage. Add a behavior to change the Wattage and price of the electrical product. Display the updatedElectricalProduct details.

/*electrical product*/
import java.util.*;
class Product
{
int productID;
String name;
int categoryID;
double price;
Product(int productID,String name,int categoryID,double price)
{
this.productID=productID;
this.name=name;
this.categoryID=categoryID;
this.price=price;
}
}
public class ElectricalProduct extends Product
{
int voltageRange;
int wattage;
ElectricalProduct(int productID,String name,int categoryID,double price,int voltageRange, intwattage)
{
super(productID,name,categoryID,price);
this.voltageRange=voltageRange;
this.wattage=wattage;
}
public void display()
{
System.out.println("Product ID: "+productID);
System.out.println("Name: "+name);
System.out.println("Category ID: "+categoryID);
System.out.println("Price: "+price);
System.out.println("Voltage Range: "+voltageRange);
System.out.println("Wattage: "+wattage);
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Product ID: ");
int pid=input.nextInt();
System.out.println("Enter Name: ");
String name=input.next();
System.out.println("Enter Catagory ID: ");
int cid=input.nextInt();
System.out.println("Enter Price: ");
double price=input.nextDouble();
System.out.println("Enter Voltage Range: ");
int vrange=input.nextInt();
System.out.println("Enter Wattage: ");
int wattage=input.nextInt();
System.out.println("****Details of Electrical Product****");
System.out.println();
ElectricalProduct p=new ElectricalProduct(pid,name,cid,price,vrange,wattage);  
p.display();
}
}
7. Create Book having following attributes: Book ID, Title, Author and Price. Create Periodical whichhas 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.

/*Book details*/
import java.util.*;
class Book
{
int id;
String title;
String author;
double price;
public void setId(int id)
{
this.id=id;
}
public int getId()
{
return id;
}
public void setTitle(String title)
{
this.title=title;
}
public String getTitle()
{
return title;
}
 public void setAuthor(String author)
{
this.author=author;
}
public String getAuthor()
{
return author;
}
public void setPrice(double price)
{
this.price=price;
}
public double getPrice()
{
return price;
}
}
class Periodical
{
String timeperiod;
public void setTimeperiod(String timeperiod)
{
this.timeperiod=timeperiod;
}
public String getTimeperiod()
{
          return timeperiod;
}
}
public class BookInformation
{
public static void main(String[]args)
{
Book b=new Book();
Periodical p=new Periodical();
Scanner input=new Scanner(System.in);
System.out.print("Book ID: ");
int id=input.nextInt();
b.setId(id);
System.out.print("Title: ");
String  title=input.next();
b.setTitle(title);
System.out.print("Author: ");
String  author=input.next();
b.setAuthor(author);
System.out.print("Price: ");
double  price=input.nextDouble();
b.setPrice(price);
System.out.print("Period: ");
String  pp=input.next();
p.setTimeperiod(pp);
System.out.println();
System.out.println("----Book Information----");
System.out.println();
System.out.println("Book ID: "+b.getId());
System.out.println("Title: "+b.getTitle());
System.out.println("Author: "+b.getAuthor());
System.out.println("Price: "+b.getPrice());
System.out.println("Period: "+p.getTimeperiod());
}
}

8.Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Createtruck which has the following additional attributes: loading capacity (100 tons).Add a behavior tochange the color and loading capacity. Display the updated truck details.
/*vehicle*/
import java.util.*;
class  Vehicle
{
int no;
String model;
String manufacturer;
String color;
Vehicle(int no,String model,String manufacturer,String color)
{
this.no=no;
this.model=model;
this.manufacturer=manufacturer;
this.color=color;
}  
}
public class Truck extends Vehicle
{
int capacity;
Truck(int no,String model,String manufacturer,String color,int capacity)
{
super( no, model, manufacturer, color);
this.capacity=capacity;
}
void show()
{
System.out.println("No = " + no);
System.out.println("Model = " + model);
System.out.println("manufacturer = " + manufacturer);
System.out.println("Color = " + color);
System.out.println("Capacity = " + capacity);
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Truck No: ");
int no=input.nextInt();
System.out.println("Model: ");
String model=input.next();
System.out.println("Manufacturer: ");  
String manufacturer=input.next();
 System.out.println("Color: ");
String color=input.next();
System.out.println("Loading Capacity: ");
int cap=input.nextInt();
Truck t=new Truck(no,model,manufacturer,color,cap);
System.out.println("****Truck Details****");
System.out.println();t.show();
}
}

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.
/*power of given number*/
import java.util.*;
import java.text.*;
class  NumberProgram
{
public static void main(String[] args)
{
DecimalFormat df=new DecimalFormat("##.##");
Scanner input=new Scanner(System.in);
System.out.print("Enter Number: ");
double num=input.nextDouble();
System.out.print("Raise Number's power: ");
double pow=input.nextDouble();
double value=Math.pow(num,pow);
System.out.println("Result is: "+df.format(value));
}
}

10. Write a function Model-of-Category for a Tata motor dealers, which accepts category of carcustomer is looking for and returns the car Model available in that category. the function shouldaccept the following categories "SUV", "SEDAN", "ECONOMY", and "MINI" which in turn returns"TATA SAFARI" , "TATA INDIGO" , "TATA INDICA" and "TATA NANO" respectively.

/*car problem*/
import java.util.*;
 class  TataMotors
{
String category;
String model;
TataMotors(String category,String model)
{
this.category=category;
this.model=model;
}
public String getCategory()
{
return category;
}
public String getModel()
{
return model;
}
public static void ModelOfCategory(ArrayList<TataMotors> list)
{  
Scanner input=new Scanner(System.in);
System.out.print("Enter Category: ");
String category=input.nextLine();
System.out.println();
System.out.print("Model is: ");
for (TataMotors tm : list)
{
if(tm.getCategory().equals(category))
{
System.out.print(tm.getModel());
}
}
}
public static void main(String[] args)
{
ArrayList<TataMotors> list=new ArrayList<TataMotors>();
list.add(new TataMotors("SUV","TATA SAFARI"));
list.add(new TataMotors("SEDAN","TATA INDIGO"));
list.add(new TataMotors("ECONOMY","TATA INDICA"));
list.add(new TataMotors("MINI","TATA NANO"));
 ModelOfCategory(list);
}
}

INTRODUCTION TO JAVA BASICS -ASSIGNMENT 1


1. Write a program to find the difference between sum of the squares and the square of the sums of n numbers?
Solution:
import java.io.*;
importjava.util.Scanner;
class Difference
{
publicstaticvoid main(String args[]) throwsIOException
{
Scanner s=newScanner(System.in);
System.out.println("Enter the value of n: ");
int n=s.nextInt();
int a[]=newint[n];
int i, sqr, diff, sum=0, add=0;
System.out.print("The "+n);
System.out.println(" numbers are : ");
for(i=0;i<n;i++)
{
a[i]=s.nextInt();
sum+=(a[i]*a[i]);
add+=a[i];
}
sqr=add*add;
diff=sqr-sum;
System.out.println("");
System.out.print("Sum of Squares of given "+n);
System.out.println(" numbers is : "+sum);
System.out.print("Squares of Sum of given "+n);
System.out.println(" numbers is : "+sqr);
System.out.println("");
System.out.println("Difference between sum of the squares and the square of the sum of given "+n);
System.out.print(" numbers is : "+diff);
System.out.println("");
}
}
Output:
Enter the value of n: 4
The 4 numbers are :
2
3
4
5
Sum of Squares of given 4 numbers is : 54
Squares of Sum of given 4 numbers is : 196
Difference between sum of the squares and the square of the sum of given 4
numbers is : 142


2. Develop a program that accepts the area of a square and will calculate its perimeter.
Solution:
importjava.util.Scanner;
publicclassCalculateSquarePeri
{
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Area of Square : ");
double a=s.nextDouble();
double p=4*Math.sqrt(a);
System.out.println("");
System.out.print("Perimeter of the Square : "+p);
System.out.println("");
}
}
Output:        
Enter the area:
23
Perimeter of the square is: 19.183326093250876


3. Develop the program calculate Cylinder Volume., which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder.
Solution:
import java.io.*;
importjava.util.Scanner;
classcalculateCylinderVolume
{
publicstaticvoid main(String args[]) throwsIOException
{
Scanner s=newScanner(System.in);
System.out.println("Enter the radius : ");
double rad=s.nextDouble();
System.out.println("Enter the height : ");
doubleht=s.nextDouble();
doublevol=Math.PI*rad*rad*ht;
System.out.println("");
System.out.println("Volume of the cylinder is : " + vol);
}
}

Output:
Enter the radius :
12
Enter the height :
13
Volume of the cylinder is : 5881.061447520093

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.
Solution:
importjava.util.Scanner;
publicclasscalculateTax {
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the no. of working days in the year : ");
int d=s.nextInt();
System.out.println("Enter the no. of working hours in a day : ");
int h=s.nextInt();
System.out.println("Enter the no. of hours worked in over time : ");
intot=s.nextInt();
System.out.println("Enter the no. of hours took leave : ");
int l=s.nextInt();
double gross=((d*h)+ot-l)*12;
double tax= gross*0.15;
double net=gross-tax;
System.out.println("");
System.out.println("Gross Pay (in $) : "+gross);
System.out.println("Tax (in $) : "+tax);
System.out.println("Net Pay (in $) : "+net);
}
}

Output:
Days worked by employer in a year :
300
Enter the no. of working hours in a day :
6
Enter the no. of hours worked in over time :
1
Enter the no. of hours took leave :
1560
Gross Pay (in $) : 2892.0
Tax (in $) : 433.8
Net Pay (in $) : 2458.2

5. An 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.
Solution:
importjava.util.Scanner;
publicclasscalculateTotalProfit
{
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s = newScanner(System.in);
System.out.println("Enter the no. of attendees of a show : ");
int n=s.nextInt();
double profit = (n*5)-(20+(n*0.5));
System.out.println("");
System.out.println("Total Profit of the theater per show (in $) is : " + profit);
}
}
Output:
Enter the no. of attendees per show :
50
Total Profit of the theater per show (in $) is : 205.0

6. Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and
its height and computes surface area of the cylinder.


Program:

importjava.util.Scanner;


publicclasscalculateCylinderArea
{

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the base radius : ");
double rad=s.nextDouble();
System.out.println("Enter the height : ");
doubleht=s.nextDouble();
double area=2*Math.PI*rad*(rad+ht);
System.out.println("");
System.out.println("Surface Area of the cylinder is : " + area);
}

}



Output:

Enter the base radius :
12
Enter the height :
13
Surface Area of the cylinder is : 1884.9555921538758

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.
Solution:
importjava.util.Scanner;
publicclasscalculatePipeArea
{
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the inner radius : ");
double rad=s.nextDouble();
System.out.println("Enter the length : ");
doublelen=s.nextDouble();
System.out.println("Enter the thickness : ");
double thick=s.nextDouble();
double area=2*Math.PI*(rad+thick)*len;
System.out.println("");
System.out.println("Surface Area of the pipe is : " + area);
}
}
Output:
Enter the inner radius :
13
Enter the length :
20
Enter the thickness :
5
Surface Area of the pipe is : 2261.946710584651

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.
Solution:
importjava.util.Scanner;
publicclasscalculateHeight
 {
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
 {
Scanner s=newScanner(System.in);
System.out.println("Enter the time (in seconds) : ");
double t=s.nextDouble();
double v=9.8*t;
double height=0.5*v*t;
System.out.println("");
System.out.println("Height reached (in meters) is : " + height);
}
}
Output:
Enter the time (in seconds) :
300
Height reached (in meters) is : 441000.0


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.
Solution:
importjava.util.Scanner;
publicclassBoatDistance
{
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s= newScanner(System.in);
System.out.println("Enter the width of the river (in meters) : ");
doublerw=s.nextDouble();
System.out.println("Enter the river's speed (in meter/sec) : ");
doublers=s.nextDouble();
System.out.println("Enter the boat's speed (in meter/sec) : ");
doublebs=s.nextDouble();
double time=rw/bs; //time takes to travel from shore to shore straight by the boat
double w2=time*rs; //distance due to down stream
doublebd=Math.sqrt((rw*rw)+(w2*w2));
System.out.println("");
System.out.println("The distance travelled by boat (in meters) is : "+bd);
}
}
Output:
Enter the width of the river (in meters) :
15
Enter the river's speed (in meter/sec) :
200
Enter the boat's speed (in meter/sec) :
250
The distance travelled by boat (in meters) is : 19.209372712298546

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 thatno 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.
Solution:
importjava.util.Scanner;
publicclasscalculateBalance {
/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the principal amount : ");
double p=s.nextDouble();
System.out.println("Enter the annual interest rate : ");
double r=s.nextDouble();
System.out.println("Enter the no. of months : ");
double m=s.nextDouble();
doublesi=(p*(m/12)*r)/100;
doublebal=p+si;
System.out.println("");
System.out.print("Balance after " +(int)m);
System.out.println(" month(s) is : "+bal);
}
}
Output:
Enter the principal amount :
15000
Enter the annual interest rate :
12
Enter the no. of months :
24
Balance after 24 month(s) is : 18600.0

BASICS OF PROGRAMMING ASSIGNMENT 1


Question 1a
Search for a name
Write a program to accept an array of names and a name and check whether the
name 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”}

SOLUTION:
import java.io.*;
class program1
 {
 public static void main(String args[])
 {
 String[] names={“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”};
System.out.println("Enter a name to check");
InputStreamReader Inp=new InputStreamReader(System.in);
BufferedReader Br=new BufferedReader(Inp);
String name=Br.readLine();
 int count=0;
 for(int i=0;i<names.length;i++)
 {
 if(names[i].equals(name))
 count++;
 }
 if(count!=0)
 System.out.println("The Number of occurance of the Name is " + count );
 else
 System.out.println("Word not Found");
 }
 }
Output :
C:\Program Files\Java\jdk1.6.0_22\bin>javac program1.java
C:\Program Files\Java\jdk1.6.0_22\bin>java program1
 Enter a name to check
 Sam
The Number of occurance of the Name is 2


Question 1 b
Improve the understandability of the below given code:
The code below takes an array of 10 integer values as an argument,prints its values,increments it by 10 and again prints the incremented value
import java.util.*; 
        //importing the required packages
class problem3 
       //creating a class
{
int[] numArray = new int[10];
       // allocating memory to 10 integer elements in an array named 'numArray'
public static void incrementElements (int[] integerArray) 
      //defining the 'incrementElements()' method with one integer type array 'integerArray' as the parameter
{
int arraylen = integerArray.length;
      // initializing an integer variable 'arraylen' with the length, i.e. the no of elements in array
for (int i = 0; i < arraylen; i ++)
      //definition of 'for' loop to print the current values of array
{
System.out.println(integerArray[i]);
}
for (int i = 0; i < arraylen; i ++)
        //definition of 'for' loop to increment the current values of array
{
integerArray[i] = integerArray[i] + 10; //add 10 to each value of array
}
for (int i=0; i < arraylen; i ++)
      //definition of 'for' loop to print the updated values of array
{
System.out.println(integerArray[i]);
}
}  //class closes


Question 2a
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


Solution :
import java.io.*;
class findgcd
{ 
 int gcd(int a,int b)
 { 
            if(a==b)
             return a;
          else if(a>b)
           return(gcd(a-b,b));
           else
           return(gcd(a,b-a));
       }
  }
 class gcdtest1
  {
 public static void main(String arr[]) throws IOException
      {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter a::");
         int a=Integer.parseInt(br.readLine());
         System.out.println("Enter b::");
         int b=Integer.parseInt(br.readLine());
          findgcd g=new findgcd();
          System.out.println("Gcd of a and b is::"+g.gcd(a,b));
}
  }

Output:
C:\Program Files\Java\jdk1.6.0_22\bin>javac gcdtest1.java
C:\Program Files\Java\jdk1.6.0_22\bin>java gcdtest1
 Enter a::
 36
 Enter b::
 24
 Gcd of a and b is:: 12


Question 2b
Improve the understandability of the below given code:
The code explains BUBBLE SORT implentation.
class Problem1
     //creating a new class
{
int[] a; //declaring a new array 'a' of integer type to store the numbers
int nElems; //declaring an integer variable 'nElems' to hold no of elements in the array
public ArrayBub(int max) 
       //defining a new parameterised method to initialize the array with 'max' as size of the array
  {
   a = new int[max];
  }
public void insert(int value)  //defining  the insert method to insert values in the array
{
a[nElems] = value;  //assigning the value to array at current position
nElems++; //incrementing the position counter
}
public void Sort()   //defining the method to sort the array
{
int out, in;  // declaring two integer variables 'out' & 'in'
for(out=nElems-1; out>1; out--) //outer loop
for(in=0; in<out; in++) //inner loop
if( a[in] > a[in+1] ) //conditional statement to compare the adjacent values
swap(in, in+1); //swaping the two values by calling the 'swap()' function
}
public void swap(int one, int two)   //defining 'swap' function to perform swapping of elements
{
//interchanging the values
long temp = a[one];
a[one] = a[two];
a[two] = temp;
}
}
// class definition ends