Saturday, 1 December 2012

Operating System ppt downloads

1 comments


Power Point Slide is best way to revise all content of book at last time, William Stalling has written amazing book. but some students feels that its too lengthy for reading all contents of book because last month of exam remaining and we have to cover many subjects in this December.

our one anonymous reader has shared link of ppt for OS with us, we are thankful to him/her for sharing this useful content with us. so for quick revision of Operating System download now ppts here.

Download link:

http://faculty.simpson.edu/lydia.sinapova/www/cmsc335/StallingsPPT.htm

NOTE : all ppts are in docx format. you need MS OFFICE 7 to view this.

Tell your friends about this ppts so they also can revise Operating System. We are again grateful to our readers for sharing study materials with us. Thank You All

Friday, 5 October 2012

GTU List of Java Programs

1 comments


GTU Java program Definitions ::



1. Write a simple java application to print a pyramid with 5 lines. The first line has one character, 2nd line has two characters and so on. The character to be used in the pyramid is taken as a command line argument.

2 Write a class, with main method, which declares floating point variables and observe the output of dividing the floating point values by a 0, also observe the effect of assigning a high integer value (8 digits and above) to a float and casting it back to int and printing.

3. Write a class called Statistics, which has a static method called average, which takes a one-dimensional array for double type, as parameter, and prints the average for the values in the array. Now write a class with the main method, which creates a two-dimensional array for the four weeks of a month, containing minimum temperatures for the days of the week(an array of 4 by 7), and uses the average method of the Statistics class to compute and print the average temperatures for the four weeks.

4. Define a class called Product, each product has a name, a product code and manufacturer name. Define variables, methods and constructors, for the Product class. Write a class called TestProduct, with the main method to test the methods and constructors of the Product class.

5. Define a class called CartesianPoint, which has two instance variables, x and y. Provide the methods getX() and getY() to return the values of the x and y values respectively, a method called move() which would take two integers as parameters and change the values of x and y respectively, a method called display() which would display the current values of x and y. Now overload the method move() to work with single parameter, which would set both x and y to the same values, .
Provide constructors with two parameters and overload to work with one parameter as well. Now define a class called TestCartesianPoint, with the main method to test the various methods in the CartesianPoint class.

6. Define a class called Triangle, which has constructor with three parameters, which are of type Cartesian Point, defined in the exercise 6. Provide methods to find the area and the perimeter of the Triangle, a method display() to display the three Cartesian Points separated by ':' character, a method move() to move the first Cartesian Point to the specified x, y location, the move should take care of relatively moving the other points as well, a method called rotate, which takes two arguments, one is the Cartesian Point and other is the angle in clockwise direction. Overload the move method to work with Cartesian Point as a parameter. Now define a class called TestTriangle to test the various methods defined in the Triangle class.

7. Override the toString, equals and the hash Code methods of the classes Triangle defined in exercises 5 and 6 above, in appropriate manner, and also redefine the display methods to use the toString method.

8. Define an abstract class called Polygon. Provide a constructor which takes an array of Cartesian Point as parameter. Also provide method called perimeter, which calculates and returns the perimeter of the Polygon. Declare abstract method area for this class. Also define a method called move, which takes two parameters x and y to specify the destination for the first point of the Polygon, and overload to make it work for Cartesian Point as a parameter. Now update the classes Triangle and Rectangle in the exercise 8 above, to be a subclass of the Polygon class. Write appropriate class with main method to test the polymorphism in the area method.

9. Write an application that defines a Sphere class with three constructors.  The first form accepts no arguments.  It assumes the sphere is centered at the origin and has a radius of one unit.  The second form accepts one double value that represents the radius of the sphere.  It assumes the sphere is centered at the origin.  The third form accepts four double arguments.  These specify the coordinates of the center and the radius.  Provide two instance methods to this class.  The first named move(), which takes three double parameters that are new values for the co-ordinates of the center.  The second is named scale(), which takes one double parameter that is used to scale the radius.  Demonstrate these methods.

10. Write a program that illustrates method overriding.  Class Bond is extended by ConvertibleBond.  Each of these classes defines a display() method that outputs the string “Bond” or  “ConvertibleBond”, respectively.  Declare an array to hold six Bond objects.  Initialize the elements of the array with a mix of Bond and ConvertibleBond objects.  Execute a program loop to invoke the display() method of each object.

11. The abstract Airplane class has three subclasses named B747, B757 and B767.  Each airplane type can transport a different number of passengers.  Each airplane object has a unique serial number.  Write an application that declares class hierarchy.  Instantiate several types of airplanes and display them.  Override the toString() method of Object to return a string with the type, serial number and capacity.

12. The abstract Monster class has three concrete subclasses named Vampire, Werewolf and Zombie.  Create six different monsters of various types and store them in a one-dimensional array.  Create a loop that displays the type of each monster.

13. The abstract Widget class has four concrete subclasses named Widget A, WidgetB, WidgetC and WidgetD.  Each of these four classes has a different mass in kilograms.  The mass of any WidgetA object is 4 kilograms.  The masses for the WidgetB, WidgetC and WidgetD classes are 1, 5 and 17 kilograms, respectively.  Each widget object has a string that identifies its color.  Create six different Widgets and store them in a one-dimension array.  Display the entries in the array and their total mass.

14. The abstract Fruit class has four subclasses named Apple, Banana, Orange and Strawberry.  Write an application that demonstrates how to establish this class hierarchy.  Declare one instance variable of type string that indicates the color of a fruit.  Create and display instances of these object. Override the toString() method of Object to return a string with the name of the fruit and its color.

15. Define one abstract class named Mammal.  Bear, Elephant, Horse and Lion are concrete classes which extends Mammal.  Define interface Vehicle which declares drive() method and this interface is implemented by the Elephant and Horse classes.  Write main() method which creates and initializes an array of four Mammal objects.  Call drive() method for each object which has implemented Vehicle interface.

16. Interface Material defines a set of String constants for various materials.  Abstract class MaterialObject has one instance variable named material of type String.  These records the material used to construct the object.  Classes Ball, Coin and Ring extend MaterialObject .  The constructor initializes the material variable.  Class MaterialObjects instantiates these three classes.  A different material is passed to each constructor.  Display material of each object.

17. Interface A declares a display() method.  Classes C1, C2 and C3 implement that method.  The main() method declares variable a of type A.  Therefore, it can hold a reference to any object of class C1, C2 and C3 and invoking the display() method relative to the interface reference.

18. Interface LuminousObject declares lightOff() and lightOn() methods.  Class SolidObject is extended by Cone and Cube.  Class LuminousCone extends Cone and implements LuminousObject.  Class LuminousCube extends Cube and implements LuminousObject.  Instantiate the LuminousCone and LuminousCube classes.  Use interface reference to refer to those objects.  Invoke the methods of the LuminousObject interface via the interface reference.

19. The abstract class Fish declares one abstract method named display().   It also has two abstract subclasses named FreshWaterFish and SaltWaterFish.  Define three concrete subclasses named Trout, Flounder and Tuna.  Trout extends FreshWaterFish and Flounder and Tuna both extends SaltWaterFish.  Write a main() method which creates an array of type Fish.  Instantiate and assign different types of Fish to the elements of the array.  Display the name of fish which is of type SaltWaterFish using display() method.

20. Declare interfaces I1 and I2.  Interface I3 extends both of these interfaces.  Also declare interface I4.  Class X implements I3.  Class W extends X and implements I4.  Create an object of class W.  Use the instanceof operator to test if that object implements each of the interfaces and is of type X.

21.  The abstract class Animal has abstract subclasses named Bird and Reptile.  Classes Dove, Eagle, Hawk, Penguin and Seagull extend Bird.  Classes Rattlesnake and Turtle extend Reptile.  The ColdBlooded interface defines no constants and declares no methods.  It is implemented by Reptile.  The OceanDwelling interface also defines no constants and declares no methods.  It is implemented by the Penguin, Seagull and Turtle classes.  Define all of these classes and implement the interface as specified.  Create one instance of each class.  Then display all ColdBooded animals and all OceanDwelling animals.

22. The abstract class Robot has concrete subclasses named RobotA, RobotB and RobotC.  Class RobotA1 extends RobotA.  Classes RobotB1 and RobotB2 extend RobotB.  Class RobotC1 extends RobotC.  The Locomotion interface declares three methods named forward(), reverse() and stop().  It is implemented by classes RobotB and RobotC.  The Sound interface declares one method named beep().  It is implemented by classes RobotA1, RobotB1 and RobotC.  Define all of these classes and implement the interfaces as specified.  Create one instance of each class. Then invoke the beep() method of all objects that are of type Sound. Also invoke the stop() method of all objects that are of types Locomotion.

23. The abstract class Tent has concrete subclasses named TentA, TentB, TentC and TentD. The Waterproof interface defines no constants and declares no methods. Implement it in any two of above mentioned four classes. Define all of these classes, and implement the interfaces as specified. Create one instance of each class. Then display all waterproof tents. Place this code in a package named tents.

24. Define one class E in package epack.  In class E, three variables are defined of access modifiers protected, private & public. Define class F in package fpack which extends E and write display() method which access variables of class E.  Define class G in package gpack which has one method display() in that create one object of class E and display its variables.  Define class ProtectedDemo in package hpack in which write main() method.  Create objects of class F and G and class display method for both these objects.

25. Make the class CartesianPoint, belong to a package called edu. gtu. geometry, the classes Polygon, Triangle and Rectangle belong to the package edu. gtu. geometry. shapes and the classes TestCartesianPoint, TestTriangle belong to the package edu. gtu.test. Use appropriate access specifiers for the classes and the members of the classes defined in the earlier exercises. Now onwards all the classes must be defined in a package.


Java Practical - 25

0 comments




Program Definition 25 ::



Make the class CartesianPoint, belong to a package called edu. gtu. geometry, the classes Polygon, Triangle and Rectangle belong to the package edu. gtu. geometry. shapes and the classes TestTriangle belong to the package edu. gtu.test. Use appropriate access specifiers for the classes and the members of the classes defined in the earlier exercises. Now onwards all the classes must be defined in a package.





// save this code in edu/gtu/geometry folder
package edu.gtu.geometry;
//program 25

public class CartesianPoint
{
public int x, y;
public CartesianPoint(int a)
{
x = y = a;
}
public CartesianPoint(int a , int b)
{
x = a; y = b;
}

public int getX()
{
return x;
}
public int getY()
{
return y;
}
public void move(int a)
{
x = y = a;
}
public void move(int a, int b)
{
x = a; y = b;
}

public void display()
{
System.out.println("("+ x +", " + y + ")");
}
}



// save this code in edu/gtu/geometry/shapes folder
package edu.gtu.geometry.shapes;
import edu.gtu.geometry.*;
public class Triangle
{
CartesianPoint cp[];
public Triangle(CartesianPoint c[])
{
cp = new CartesianPoint[ c.length ];
for(int i=0;i<c.length;i++)
{
cp[i]=c[i];
}
}

public double area()
{
return ((Math.abs(cp[0].getX()*(cp[1].getY()-cp[2].getY()) + cp[1].getX()*(cp[2].getY()-cp[0].getY()) + cp[2].getX()*(cp[0].getY()-cp[1].getY()))/2));
}
public void display()
{
for ( int i = 0 ; i < 3 ; i++ )
{
cp[i].display();
}
}
}


// save this code in edu/gtu/test folder

package edu.gtu.test;
import edu.gtu.geometry.*;
import edu.gtu.geometry.shapes.*;

class TestTriangle
{
public static void main(String args[])
{
CartesianPoint c[] = new CartesianPoint[ 3 ];
c[0] = new CartesianPoint(5,5);
c[1] = new CartesianPoint(10,5);
c[2] = new CartesianPoint(10,10);

Triangle T1 = new Triangle(c);
T1.display();
System.out.println("Area :: " + T1.area() );
}
}

/*
D:\JAVA >javac edu/gtu/test/*.java

D:\JAVA >java edu.gtu.test.TestTriangle
(5, 5)
(10, 5)
(10, 10)
Area :: 12.0
*/

Thursday, 4 October 2012

Java Practical - 24

0 comments




Program Definition 24 ::

Define one class E in package epack.  In class E, three variables are defined of access modifiers protected, private & public. Define class F in package fpack which extends E and write display() method which access variables of class E.  Define class G in package gpack which has one method display() in that create one object of class E and display its variables.  Define class ProtectedDemo in package hpack in which write main() method.  Create objects of class F and G and class display method for both these objects.




// save this file in epack folder
package epack;
public class E
{
public int publicVar = 10;
protected int protectedVar = 20;
private int privateVar = 30;

}


// save this file in fpack folder
package fpack;
import epack.*;

public class F extends E
{
public void display()
{
System.out.println("from Class F : package fpack");
//System.out.println("private" + privateVar); // not accessible
System.out.println("public" + publicVar);
System.out.println("protected" + protectedVar);

}
}

// save this file in gpack folder
package gpack;
import epack.*;

public class G
{
E eObj = new E();

public void display()
{
System.out.println("from Class G : package gpack");
//System.out.println("private" + eObj.privateVar); // not accessible
System.out.println("public" + eObj.publicVar);
//System.out.println("protected" + eObj.protectedVar); // not accessible
}
}

// save this file in hpack folder
package hpack;
import gpack.*;
import fpack.*;

class ProtectedDemo
{
public static void main( String args[] )
{

F fObj = new F();
G gObj = new G();

fObj.display();
gObj.display();
}
}

/*

D:\JAVA>javac epack/*.java

D:\JAVA>javac fpack/*.java

D:\JAVA>javac gpack/*.java

D:\JAVA>javac hpack/*.java

D:\JAVA>java hpack.ProtectedDemo
from Class F : package fpack
public10
protected20
from Class G : package gpack
public10
*/

Wednesday, 3 October 2012

Java Practical - 23

0 comments



Program Definition 23 ::


The abstract class Tent has concrete subclasses named TentA, TentB, TentC and TentD. The Waterproof interface defines no constants and declares no methods. Implement it in any two of above mentioned four classes. Define all of these classes, and implement the interfaces as specified. Create one instance of each class. Then display all waterproof tents. Place this code in a package named tents.
 

//create tents folder and then write below code



package tents;
abstract class Tent
{
}
class TentA extends Tent implements WaterProof
{}

class TentB extends Tent implements WaterProof
{}

class TentC extends Tent
{}

class TentD extends Tent
{}

interface WaterProof
{}

class Prog23
{
public static void main( String args[] )
{
Tent t[] = new Tent[ 4 ];
t[ 0 ] = new TentA();
t[ 1 ] = new TentB();
t[ 2 ] = new TentC();
t[ 3 ] = new TentD();

for ( Tent ti : t )
{
if ( ti instanceof WaterProof )
{
Class cls = ti.getClass();
System.out.println(cls.getName());
}
}
}
}

/*

D:\JAVA>javac tents/*.java

D:\JAVA>java tents.Prog23
tents.TentA
tents.TentB

*/

Tuesday, 2 October 2012

Java Practical - 22

0 comments



Program Definition 22 ::


The abstract class Robot has concrete subclasses named RobotA, RobotB and RobotC.  Class RobotA1 extends RobotA.  Classes RobotB1 and RobotB2 extend RobotB.  Class RobotC1 extends RobotC.  The Locomotion interface declares three methods named forward(), reverse() and stop().  It is implemented by classes RobotB and RobotC.  The Sound interface declares one method named beep().  It is implemented by classes RobotA1, RobotB1 and RobotC.  Define all of these classes and implement the interfaces as specified.  Create one instance of each class. Then invoke the beep() method of all objects that are of type Sound. Also invoke the stop() method of all objects that are of types Locomotion.
 



abstract class Robot
{
}

class RobotA extends Robot
{
}

class RobotB extends Robot implements Locomotion
{
public void forward()
{
System.out.println(" RobotB >> forward ");
}
public void reverse()
{
System.out.println(" RobotB >> reverse ");
}
public void stop()
{
System.out.println(" RobotB >> stop ");
}
}

class RobotC extends Robot implements Locomotion, Sound
{
public void forward()
{
System.out.println(" RobotC >> forward ");
}
public void reverse()
{
System.out.println(" RobotC >> reverese ");
}
public void stop()
{
System.out.println(" RobotC >> stop ");
}
public void beep()
{
System.out.println(" RobotC >> beep ");
}
}

class RobotA1 extends RobotA implements Sound
{
public void beep()
{
System.out.println(" RobotA1 >> beep ");
}

}

class RobotB1 extends RobotB implements Sound
{
public void beep()
{
System.out.println(" RobotB1 >> beep ");
}

}

class RobotB2 extends RobotB
{}

class RobotC1 extends RobotC
{}

interface Locomotion
{
public void forward();
public void reverse();
public void stop();
}

interface Sound
{
public void beep();
}

class Prog22
{
public static void main( String args[] )
{
Robot[] r = new Robot[7];

r[ 0 ] = new RobotA();
r[ 1 ] = new RobotB();
r[ 2 ] = new RobotC();
r[ 3 ] = new RobotA1();
r[ 4 ] = new RobotB1();
r[ 5 ] = new RobotB2();
r[ 6 ] = new RobotC1();

//beep from Sound implemented classes
for( Robot ri : r )
{
if ( ri instanceof Sound )
{
Sound s = (Sound) ri;
s.beep();
}
if ( ri instanceof Locomotion )
{
Locomotion l = (Locomotion) ri ;
l.stop();
}
}
}
}

/*

D:\MCA\JAVA\Practical Assigment-2>javac Prog22.java

D:\MCA\JAVA\Practical Assigment-2>java Prog22
 RobotB >> stop
 RobotC >> beep
 RobotC >> stop
 RobotA1 >> beep
 RobotB1 >> beep
 RobotB >> stop
 RobotB >> stop
 RobotC >> beep
 RobotC >> stop
*/

Monday, 1 October 2012

Java Practical - 21

0 comments



Program Definition 21 ::


The abstract class Animal has abstract subclasses named Bird and Reptile.  Classes Dove, Eagle, Hawk, Penguin and Seagull extend Bird.  Classes Rattlesnake and Turtle extend Reptile.  The ColdBlooded interface defines no constants and declares no methods.  It is implemented by Reptile.  The OceanDwelling interface also defines no constants and declares no methods.  It is implemented by the Penguin, Seagull and Turtle classes.  Define all of these classes and implement the interface as specified.  Create one instance of each class.  Then display all ColdBooded animals and all OceanDwelling animals.
 



abstract class Animal
{
}

interface ColdBlooded
{
}
interface OceanDwelling
{
}

abstract class Bird extends Animal
{
}

abstract class Reptile extends Animal implements ColdBlooded
{
}

class Dove extends Bird
{}
class Eagle extends Bird
{}
class Hawk extends Bird
{}
class Penguin extends Bird implements OceanDwelling
{}
class Seagull extends Bird implements OceanDwelling
{}


class RattleSnake extends Reptile
{}
class Turtle extends Reptile implements OceanDwelling
{}


class Prog21
{
public static void main( String args[] )
{

Animal[] animal = new Animal[7];

animal[ 0 ] = new Dove();
animal[ 1 ] = new Eagle();
animal[ 2 ] = new Hawk();
animal[ 3 ] = new Penguin();
animal[ 4 ] = new Seagull();
animal[ 5 ] = new RattleSnake();
animal[ 6 ] = new Turtle();

for ( Animal ai : animal )
{
if ( ai instanceof ColdBlooded )
System.out.println(ai.getClass() + " is ColdBlooded" );
if ( ai instanceof OceanDwelling )
System.out.println(ai.getClass() + " is OceanDwelling" );
}
}
}

/*
D:\MCA\JAVA >javac Prog21.java

D:\MCA\JAVA >java Prog21
class Penguin is OceanDwelling
class Seagull is OceanDwelling
class RattleSnake is ColdBlooded
class Turtle is ColdBlooded
class Turtle is OceanDwelling
*/

Sunday, 30 September 2012

Java Practical - 20

0 comments



Program Definition 20 ::


Define one class E in package epack.  In class E, three variables are defined of access modifiers protected, private & public. Define class F in package fpack which extends E and write display() method which access variables of class E.  Define class G in package gpack which has one method display() in that create one object of class E and display its variables.  Define class ProtectedDemo in package hpack in which write main() method.  Create objects of class F and G and class display method for both these objects.
 



interface I1
{
}

interface I2
{
}

interface I3 extends I1,I2
{
}

interface I4
{
}

class X implements I3
{
}

class W extends X implements I4
{
}

class Prog20
{
public static void main( String args[] )
{
W wObj = new W();

if ( wObj instanceof I1 )
System.out.println(" W implements I1 ");
if ( wObj instanceof I2 )
System.out.println(" W implements I2 ");
if ( wObj instanceof I3 )
System.out.println(" W implements I3 ");
if ( wObj instanceof I4 )
System.out.println(" W implements I4 ");
if ( wObj instanceof X )
System.out.println(" W extends X ");
}
}

/*

D:\JAVA >javac Prog20.java

D:\JAVA >java Prog20
 W implements I1
 W implements I2
 W implements I3
 W implements I4
 W extends X
*/

Saturday, 29 September 2012

Java Practical - 19

0 comments


    Program Definition 19 ::
 
    The abstract class Fish declares one abstract method named display().   It also has two abstract subclasses named FreshWaterFish and SaltWaterFish.  Define three concrete subclasses named Trout, Flounder and Tuna.  Trout extends FreshWaterFish and Flounder and Tuna both extends SaltWaterFish.  Write a main() method which creates an array of type Fish.  Instantiate and assign different types of Fish to the elements of the array.  Display the name of fish which is of type SaltWaterFish using display() method.




abstract class Fish
{
String name;
abstract public void display();
}

abstract class SaltWaterFish extends Fish
{
}

abstract class FreshWaterFish extends Fish
{
}

class Trout extends FreshWaterFish
{
Trout( String n )
{
this.name = n;
}
public void display()
{
System.out.println( name );
}
}

class Flounder extends SaltWaterFish
{
Flounder( String n )
{
this.name = n ;
}
public void display()
{
System.out.println( name );
}
}

class Tuna extends SaltWaterFish
{
Tuna( String n )
{
this.name = n ;
}
public void display()
{
System.out.println( name );
}
}


class Prog19
{
public static void main( String args[] )
{
Fish fish[] = new Fish[3] ;

fish [ 0 ] = new Trout("Trout");
fish [ 1 ] = new Flounder("Flounder");
fish [ 2 ] = new Tuna("Tuna");

for ( Fish f : fish)
{
//finds fish that belongs to SaltWater using instanceOf operator
if ( f instanceof SaltWaterFish)
f.display();
}
}
}

/*

D:\JAVA >javac Prog19.java

D:\JAVA >java Prog19
Flounder
Tuna
*/

Friday, 28 September 2012

Java Practical - 18

0 comments


    Program Definition 18 ::
 
     Interface LuminousObject declares lightOff() and lightOn() methods.  Class SolidObject is extended by Cone and Cube.  Class LuminousCone extends Cone and implements LuminousObject.  Class LuminousCube extends Cube and implements LuminousObject.  Instantiate the LuminousCone and LuminousCube classes.  Use interface reference to refer to those objects.  Invoke the methods of the LuminousObject interface via the interface reference.




interface LuminousObject
{
public void lightOn();
public void lightOff();
}

class SolidObject
{
}

class Cube extends SolidObject
{
}

class Cone extends SolidObject
{
}

class LuminousCone extends Cone implements LuminousObject
{
public void lightOn()
{
System.out.println( " lightOn() from LuminousCone class " );
}
public void lightOff()
{
System.out.println( " lightOff() from LuminousCone class " );
}
}

class LuminousCube extends Cube implements LuminousObject
{
public void lightOn()
{
System.out.println( " lightOn() from LuminousCube class " );
}
public void lightOff()
{
System.out.println( " lightOff() from LuminousCone class " );
}
}


class Prog18
{
public static void main( String args[] )
{
LuminousObject lObj[] = new  LuminousObject[2];

lObj[ 0 ] = new LuminousCone();
lObj[ 1 ] = new LuminousCube();

for ( LuminousObject l : lObj )
{
l.lightOn();
}

for ( LuminousObject l : lObj )
{
l.lightOff();
}
}
}

/*

D:\MCA\JAVA >javac Prog18.java

D:\MCA\JAVA >java Prog18
 lightOn() from LuminousCone class
 lightOn() from LuminousCube class
 lightOff() from LuminousCone class
 lightOff() from LuminousCone class
*/

Thursday, 27 September 2012

Java Practical - 17

0 comments


    Program Definition 17 ::
 
     Interface A declares a display() method.  Classes C1, C2 and C3 implement that method.  The main() method declares variable a of type A.  Therefore, it can hold a reference to any object of class C1, C2 and C3 and invoking the display() method relative to the interface reference.




interface A
{
public void display();
}

class C1 implements A
{
public void display()
{
System.out.println("C1 display called");
}
}
class C2 implements A
{
public void display()
{
System.out.println("C2 display called");
}

}
class C3 implements A
{
public void display()
{
System.out.println("C3 display called");
}

}

class Prog17
{
public static void main( String args[] )
{
C1 c1 = new C1();
C2 c2 = new C2();
C3 c3 = new C3();

c1.display();
c2.display();
c3.display();
}
}

/*
D:\JAVA >javac Prog17.java

D:\JAVA >java Prog17
C1 display called
C2 display called
C3 display called
*/

Tuesday, 25 September 2012

Java Practical - 15

0 comments


    Program Definition 15 ::
 
     Define one abstract class named Mammal.  Bear, Elephant, Horse and Lion are concrete classes which extends Mammal.  Define interface Vehicle which declares drive() method and this interface is implemented by the Elephant and Horse classes.  Write main() method which creates and initializes an array of four Mammal objects.  Call drive() method for each object which has implemented Vehicle interface.




interface Vhicle
{

public void drive();
}

class Mammel
{

}

class Bear extends Mammel
{


}

class Elephant extends Mammel implements Vhicle
{
public void drive()
{
System.out.println("Elephant Called");
}

}

class Horse extends Mammel implements Vhicle
{
public void drive()
{
System.out.println("Horses Called");
}
}

class Lion extends Mammel
{

}

class TestMammel
{
public static void main( String args[] )
{

Horse h = new Horse();
Elephant e = new Elephant();

h.drive();
e.drive();

}
}


/*

D:\JAVA >javac TestMammel.java

D:\JAVA >java TestMammel
Horse Called
Elephant Called
*/

Monday, 24 September 2012

Java Practical - 14

0 comments


    Program Definition 14::

     The abstract Fruit class has four subclasses named Apple, Banana, Orange and Strawberry.  Write an application that demonstrates how to establish this class hierarchy.  Declare one instance variable of type string that indicates the color of a fruit.  Create and display instances of these object. Override the toString() method of Object to return a string with the name of the fruit and its color.




abstract class Fruit
{
String color;

Fruit( String c )
{
color = c ;
}
abstract public String toString();

}

class Apple extends Fruit
{
Apple( String c )
{
super(c);
}

public String toString()
{
return "Apple color :: " + color ;
}

}

class Banana extends Fruit
{
Banana( String c )
{
super(c);
}
public String toString()
{
return "Banana color :: " + color ;
}
}

class Orange extends Fruit
{
Orange( String c )
{
super(c);
}
public String toString()
{
return "Orange color :: " + color ;
}

}

class Stawberry extends Fruit
{
Stawberry( String c )
{
super(c);
}
public String toString()
{
return "Stawberry color :: " + color ;
}

}

class TestFruit
{
public static void main( String args[] )
{

Fruit f[] = new Fruit[4];

f[ 0 ] = new Apple("Red");
f[ 1 ] = new Banana("Yellow");
f[ 2 ] = new Orange("Orange");
f[ 3 ] = new Stawberry("Red");


for( Fruit f1 : f )
{
System.out.println(f1.toString());
}

}
}


/*
D:\JAVA >javac TestFruit.java

D:\JAVA >java TestFruit
Apple color :: Red
Banana color :: Yellow
Orange color :: Orange
Stawberry color :: Red
*/

Sunday, 23 September 2012

Java Practical - 13

0 comments


    Program Definition 13 ::

     The abstract Widget class has four concrete subclasses named Widget A, WidgetB, WidgetC and WidgetD.  Each of these four classes has a different mass in kilograms.  The mass of any WidgetA object is 4 kilograms.  The masses for the WidgetB, WidgetC and WidgetD classes are 1, 5 and 17 kilograms, respectively.  Each widget object has a string that identifies its color.  Create six different Widgets and store them in a one-dimension array.  Display the entries in the array and their total mass.




abstract class Widget
{
int weight;
String color;

Widget( int w , String c )
{
weight = w ; color = c ;
}
abstract public void display();
}

class WidgetA extends Widget
{

WidgetA( String c )
{
super( 4 , c);
}

public void display()
{
System.out.println( "Weight = " + weight + "\n color = " + color );
}
}

class WidgetB extends Widget
{
WidgetB( String c )
{
super( 1 , c );
}
public void display()
{
System.out.println( "Weight = " + weight + "\n color = " + color );
}

}

class WidgetC extends Widget
{
WidgetC( String c )
{
super( 5 , c );
}
public void display()
{
System.out.println( "Weight = " + weight + "\n color = " + color );
}

}

class WidgetD extends Widget
{
WidgetD( String c )
{
super( 17 , c );
}
public void display()
{
System.out.println( "Weight = " + weight + "\n color = " + color );
}

}


class TestWidget
{
public static void main( String args[] )
{
Widget w[] = new Widget[6];

w[ 0 ] = new WidgetA("yellow");
w[ 1 ] = new WidgetA("black");
w[ 2 ] = new WidgetB("violet");
w[ 3 ] = new WidgetC("red");
w[ 4 ] = new WidgetC("white");
w[ 5 ] = new WidgetD("blue");


int totalMass = 0;
for( Widget w1 : w)
{
w1.display();

totalMass = totalMass + w1.weight ;
}

System.out.println("\nTotal Mass is :: " + totalMass);
}
}


/*
D:\JAVA >java TestWidget
Weight = 4
 color = yellow
Weight = 4
 color = black
Weight = 1
 color = violet
Weight = 5
 color = red
Weight = 5
 color = white
Weight = 17
 color = blue
Total Mass is :: 36
*/

Saturday, 22 September 2012

Java Practical - 12

0 comments


    Program Definition 12 ::
 
     The abstract Monster class has three concrete subclasses named Vampire, Werewolf and Zombie.  Create six different monsters of various types and store them in a one-dimensional array.  Create a loop that displays the type of each monster.




abstract class Monster
{
String name;

Monster(String n)
{
name = n;
}

abstract public void display();
}

class Vampire extends Monster
{

Vampire(String n)
{
super(n);
}


public void display()
{
System.out.println("This is Vampire :: " + name);
}
}

class Werewolf extends Monster
{

Werewolf(String n)
{
super(n);
}
public void display()
{
System.out.println("This is Werewolf :: " + name);
}
}

class Zombie extends Monster
{
Zombie(String n)
{
super(n);
}

public void display()
{
System.out.println("This is Zombie :: " + name);
}
}

class TestMonster
{
public static void main( String[] args)
{
Monster[] m = new Monster[6];

m[0] = new Vampire("vam1");
m[1] = new Vampire("vam1");
m[2] = new Zombie("zom1");
m[3] = new Zombie("zom1");
m[4] = new Werewolf("wolf1");
m[5] = new Werewolf("wolf1");


for ( Monster m1 : m)
{
m1.display();
}

}
}


/*
D:\JAVA >javac TestMonster.java

D:\JAVA >java TestMonster
This is Vampire :: vam1
This is Vampire :: vam1
This is Zombie :: zom1
This is Zombie :: zom1
This is Werewolf :: wolf1
This is Werewolf :: wolf1
*/

Friday, 21 September 2012

Java Practical - 11

0 comments


    Program Definition 11 ::
 
     The abstract Airplane class has three subclasses named B747, B757 and B767.  Each airplane type can transport a different number of passengers.  Each airplane object has a unique serial number.  Write an application that declares class hierarchy.  Instantiate several types of airplanes and display them.  Override the toString() method of Object to return a string with the type, serial number and capacity..





abstract class Airplane
{
protected int serialNumber;
protected int passengerCapacity;
protected String name;
Airplane(int sn, String nm ,int pc)
{
serialNumber = sn ;
name = nm ;
passengerCapacity = pc ;
}

public String toString()
{
return "serial number : " + serialNumber + "  \n passenger capacity : " +

passengerCapacity + " \n  name : " + name;

}
}


class B747 extends Airplane
{

B747(int sn , String nm, int pc)
{
super(sn , nm,  pc);
}
}

class B757 extends Airplane
{
B757(int sn , String nm, int pc)
{
super(sn , nm,  pc);
}
}

class B767 extends Airplane
{
B767(int sn , String nm , int pc)
{
super(sn ,nm,  pc);
}
}

class TestAirplane
{
public static void main(String args[])
{
System.out.println(" Program 11");

B747 b1 = new B747(001,"Boying", 450);
B757 b2 = new B757(101,"Airbus", 750);

System.out.println(b1.toString());
System.out.println(b2.toString());

}
}

/*
D:\JAVA >javac Prog11.java

D:\JAVA >java TestAirplane
 Program 11
serial number : 1
 passenger capacity : 450
  name : Boying

serial number : 101
 passenger capacity : 750
  name : Airbus
*/




Thursday, 20 September 2012

Java Practical - 10

0 comments


    Program Definition 10 ::
 
     Write a program that illustrates method overriding.  Class Bond is extended by ConvertibleBond.  Each of these classes defines a display() method that outputs the string “Bond” or  “ConvertibleBond”, respectively.  Declare an array to hold six Bond objects.  Initialize the elements of the array with a mix of Bond and ConvertibleBond objects.  Execute a program loop to invoke the display() method of each object.




class Bond
{
public void display()
{
System.out.println("Bond");
}
}
class ConvertibleBond extends Bond
{
public void display()
{
System.out.println("ConvertibleBond");
}
}

class Prog10
{
public static void main(String args[])
{
Bond[] b = new Bond[ 6 ];

b[ 0 ] = new Bond();
b[ 1 ] = new ConvertibleBond();
b[ 2 ] = new Bond();
b[ 3 ] = new ConvertibleBond();
b[ 4 ] = new Bond();
b[ 5 ] = new ConvertibleBond();

for ( Bond bi : b )
{
bi.display();
}
}
}

/*

D:\JAVA>javac Prog10.java

D:\JAVA>java Prog10
Bond
ConvertibleBond
Bond
ConvertibleBond
Bond
ConvertibleBond
*/

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT