IT8501 Model QP Answers
IT8501 Model QP Answers
net
www.AUNewsBlog.net
www.AUNewsBlog.net
PART B - (2 X 12 = 24 marks)
7. a)(i) Write a Javascript program to delete the rollno property from the following object. Also print
the object before and after deleting the property
Sample object: var student = {name:”Santhosh Ravy”, class:”VI”,rollno:29};
Solution
<!DOCTYPE html>
Output:
<html>
Before deleting : Santhosh Rayy VI
<head>
29 After deleting : Santhosh Rayy VI
<title>Delete a property from an object</title>
</head>
<body>
<script language= "JavaScript">
var Student = {
name: " Santhosh Ravy ",
class: "VI",
rollno: 29,
};
var txt = "";
for (x in Student) {
txt += Student[x] + " ";
}
document.write("Before deleting : " + txt);
delete Student.rollno;
var txt1 = "";
for (x in Student) {
txt1 += Student[x] + " ";
}
document.write("after delete : " + txt1);
</script>
</body>
</html>
(ii)Write a Javascript program to search a date (MM/DD/YYYY) within a string
Solution
!DOCTYPE html>
Output
<html>
truefalsetrue
<head>
<meta charset="utf-8">
<title>JavaScript function to check whether a given value is date string or not.</title>
www.AUNewsBlog.net
www.AUNewsBlog.net
</head>
<body>
<script>
function is_dateString(str)
{
regexp = /^(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])\/(?:[0-9]{2})?[0-9]{2}$/;
if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}
document.write(is_dateString("01/01/2015"));
document.write(is_dateString("32/30/2015"));
document.write(is_dateString("02/12/2015"));
</script>
</body>
</html>
OR
b)(i) Write short notes on JavaScript built-in objects
Object
Objects encapsulate data (attributes) and methods (behavior); the data and methods of an object
are tied together intimately. Objects have the property of information hiding. Programs
communicate with objects through well-defined interfaces. Normally, implementation details of
objects are hidden within the objects themselves.
Objects in Javascript are:
Math
String
Date
Boolean and number
Window
Document
Math Object
The Math object’s methods allow the programmer to perform many common mathematical
calculations. Few of it methods are:
Method Description Example
abs( x ) absolute value of x abs( 7.2 ) is 7.2
abs( 0.0 ) is 0.0
abs( -5.6 ) is 5.6
ceil( x ) rounds x to the smallest integer not less ceil( 9.2 ) is 10.0
than x ceil( -9.8 ) is -9.0
cos( x ) trigonometric cosine of x (x in radians) cos( 0.0 ) is 1.0
exp( x ) exponential method ex exp( 1.0 ) is 2.71828
exp( 2.0 ) is 7.38906
IT6503 / Internal Assessment -1 Answer Key Page 3 of 11
www.AUNewsBlog.net
www.AUNewsBlog.net
www.AUNewsBlog.net
www.AUNewsBlog.net
Document Object
Manipulate document that is currently visible in the browser window
Method or Property Description
write( string ) Writes the string to the XHTML document as XHTML code.
writeln( string ) Writes the string to the XHTML document as XHTML code and adds a
newline character at the end.
document.cookie This property is a string containing the values of all the cookies stored on
the user’s computer for the current document. See Section 12.9, Using
Cookies.
document.lastModified This property is the date and time that this document was last modified.
Window Object
Provides methods for manipulating browser window
• Opening New Windows with JavaScript
– The JavaScript command to create a new browser window is
WinObj=window.open(“url”,”name”,”features”)
• The following are the components of the window.open() statement:
– The WinObj variable is used to store the new windowobject. You can access methods and properties
of the new object by using this name.
– The first parameter of the window.open() method is a URL, which will be loaded into the new
window. If it’s left blank, no web page will be loaded. In this case, you could use JavaScript to fill
the window with content.
– .The second parameter specifies a window name (here, WindowName). This is assigned to the
window object’s name property and is used to refer to the window.
– The third parameter is a list of optional features, separated by commas. You can customize the new
window by choosing whether to include the toolbar, status line, and other features. This enables
you to create a variety of “floating” windows, which might look nothing like a typical browser
window
• Setting the Features of a Pop-up Window
– The feature list obeys the following syntax:
“feature1=value1, feature2=value2…featureN=valueN”
• The window.close() method closes a window.
• Browsers don’t normally allow you to close the main browser window without the user’s
permission; this method’s main purpose is for closing windows you have created.
• For example, this statement closes a window called updatewindow: updatewindow.close();
Moving and Resizing Window
• window.moveTo() moves the window to a new position. The parameters specify the x (column) and
y (row) position.
• window.moveBy() moves the window relative to its current position. The x and y parameters can be
positive or negative, and are added to the current values to reach the new position.
• window.resizeTo() resizes the window to the width and height specified as parameters.
IT6503 / Internal Assessment -1 Answer Key Page 5 of 11
www.AUNewsBlog.net
www.AUNewsBlog.net
• window.resizeBy() resizes the window relative to its current size. The parameters are used to modify
the current width and height
(ii) Differentiate Client side scripting and server side scripting with suitable example
Server Side Scripting Client Side Scripting
Executes the server side scripting that Executes the client side scripting that resides
produces the page to be sent to the browser. at the user’s computer
Send out a page but it does not execute client- Execute client-side scripts.
side scripts.
Connect to the databases that reside on the Cannot be used to connect to the databases
web server on the web server
Access the file system residing at the web can’t access the file system that resides at the
server web server
Cannot be blocked by the user Can be blocked by the user
Response is comparatively slower Response is comparatively Faster
8. a) Elaborate the inheritance and their types in Java with example coding
Inheritance
One object acquires all the properties and behaviors of parent object.
Helps for code reusability
Runtime polymorphism can be achieved
Syntax
class subclass-name extends superclass-name {
// body of class
}
www.AUNewsBlog.net
www.AUNewsBlog.net
www.AUNewsBlog.net
www.AUNewsBlog.net
weight = m;
}
// default constructor
BoxWeight() {
super();
weight = -1;
}
// constructor used when cube is created
BoxWeight(double len, double m) {
super(len);
weight = m;
}
}
// Add shipping costs.
class Shipment extends BoxWeight {
double cost;
// construct clone of an object
Shipment(Shipment ob) { // pass object to constructor
super(ob);
cost = ob.cost;
}
// constructor when all parameters are specified
Shipment(double w, double h, double d,
double m, double c) {
super(w, h, d, m); // call superclass constructor
cost = c;
}
// default constructor
Shipment() {
super();
cost = -1;
}
// constructor used when cube is created
Shipment(double len, double m, double c) {
super(len, m);
cost = c;
}
}
class DemoShipment {
public static void main(String args[]) {
Shipment shipment1 = new Shipment(10, 20, 15, 10, 3.41);
Shipment shipment2 = new Shipment(2, 3, 4, 0.76, 1.28);
double vol;
vol = shipment1.volume();
System.out.println("Volume of shipment1 is " + vol);
System.out.println("Weight of shipment1 is "+ shipment1.weight);
System.out.println("Shipping cost: $" + shipment1.cost);
System.out.println();
IT6503 / Internal Assessment -1 Answer Key Page 8 of 11
www.AUNewsBlog.net
www.AUNewsBlog.net
vol = shipment2.volume();
System.out.println("Volume of shipment2 is " + vol);
System.out.println("Weight of shipment2 is "+ shipment2.weight);
System.out.println("Shipping cost: $" + shipment2.cost);
}
}
OR
b) Give a detailed description for creation of package in Java with an example
Package is a group of similar types of classes, interfaces and sub-packages
General form
package pkg;
package pkg1[.pkg2[.pkg3]];
Advantages
categorize the classes and interfaces so that they can be easily maintained.
provides access protection.
removes naming collision.
Example
package mypack;
public class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
}
Compile: javac -d directory javafilename
Run: java pkgname. javafilename
There are three ways to access the package from outside the package.
import package.*;
import package.classname;
fully qualified name.
Example
package MyPack;
class Balance {
String name;
double bal;
Balance(String n, double b) {
name = n;
bal = b;
}
void show() {
if(bal<0)
System.out.print("--> ");
System.out.println(name + ": $" + bal);
}
}
class AccountBalance {
public static void main(String args[]) {
Balance current[] = new Balance[3];
www.AUNewsBlog.net
www.AUNewsBlog.net
www.AUNewsBlog.net
www.AUNewsBlog.net
{large = number1
}
if ((number2 >= number1) && (number2 >= number3))
{large = number2
}
if ((number3 >= number1) && (number3 >= number2))
{large = number3
}
//display the results
window.alert( "The sum is " + sum + "\nThe product is " + product + "\nThe average is
" + average + "\nThe smallest number is " + small + "\nThe largest number is " + large);
//-->
</script>
</head>
<body></body>
</html>
(ii) Write javascript statements to accomplish each of the following tasks:
a) Declare variables sum and x.
var sum, x;
b) Assign 1 to variable x.
x=1;
c)Assign 0 to variable sum.
sum=0
d) Add variable x to variable sum, and assign the result to variable sum.
sum=sum+x;
e) Print "The sum is: ", followed by the value of variable sum
document.writeln( "<h1>The sum is " + sum + "</h1>" );
www.AUNewsBlog.net