MOBILE AND APPLICATION DEVELOPMENT LAB
(18B28CI408)
LAB RECORD
Submitted by
Nishant Kumar [221B253]
Submitted to: Mr. Manik Gandotra
2023-2024
Department of Computer Science & Engineering
JAYPEE UNIVERSITY OF ENGINEERING &
TECHNOLOGY, AB ROAD, RAGHOGARH,
DT. GUNA-473226 MP, INDIA
INDEX
Exp. Experiment Title Start End Signature
No. Date Date
LAB 1
Q1) Write a program in Java to print “Hello World”.
/*************************************************************
class p1 { public static void
main(String[] args)
{
System.out.println("Hello World");
}
}
Q2) Write a program in Java to print these patterns:
*****
*****
*****
*****
/*************************************************************
//This program is developed by Nishant
Kumar(221B253)/***********************************************
**************
class p2
{
public static void main(String[] args)
{ for(int
i=1;i<=4;i++)
{ for(int
j=1;j<=5;j++)
System.out.print('*');
System.out.println();
}
}
Q3) Write a program in Java to print the table of a number received
through command line argument.
/*************************************************************
class p3 { public static void
main(String[] args)
{ int
n=Integer.parseInt(args[0]);
for(int i=1;i<=10;i++)
System.out.println(n+"x"+i+"="+n*i);
}
}
LAB 2
Q1) Test for Inheritance
/*************************************************************
class Mother
{ int
x;
void show()
System.out.println("Mother class - x: "+x);
}
}
class Child extends Mother
{}
class Application
{ public static void main(String[]
args)
Child obj=new Child();
obj.x=10; obj.show();
}
}
Q2) Test for Overriding
/*************************************************************
class Mother
{ public String
show()
{ return "Hello
World";
}
}
class Child extends Mother
{ public String
show()
return "Hello JUET";
}
}
public class Main
{ public static void main(String[]
args) {
Child ob=new Child();
String result=ob.show();
System.out.println(result);
}
}
Q3) Test for Polymorphism
/*************************************************************
class Mother
{ static void
show()
{
System.out.println("Static method in Mother"); }
class Child extends Mother
{ static void
show()
System.out.println("Static method in Child");
}
}
public class Application
{ public static void main(String[]
args)
Mother m1=new Child();
m1.show();
Mother.show();
Child.show(); m1.show();
Child.show();
Child.show();
}
}
Q4) Parametrized Constructors
/*************************************************************
class One {
public One(int x)
{
// Parameterized constructor code goes here
}}
class Two extends One
{
// Class Two must have a constructor that calls the constructor of its superclass
(One) public
Two(int y)
{
super(y); // Call the constructor of the superclass with the necessary argument //
Additional code for class Two goes here
}
}
public class Main
{ public static void main(String[]
args)
{
// Main method or any other testing code can be added here }
LAB 3
Q1) Make your first inheritance based design
There were Pandavs and Kauravs. Arjun and Bheem were Pandavs.
Duryodhan was a Kaurav. Pandavs were characterized by their
skills of fighting (fight ( )), obedience (obey ( )), and kindness (kind (
)). Though Bheem was little less kind but equally obedient as Arjun.
Kauravs were notorious for disobeying and cruelty. But Kauravs
were fighters. Kauravs were 100 in numbers, but one of them
‘Vikarn’ was a noble man- a good fighter, kind and obedient. If you
dive a little more in the history, you will come to know that Pandavs
and Kauravs were actually Bharatvanshi. And all bharatvanshis
had been fighters.
You are required to create a design first on paper and then write
implementation on your machine. Make abstract classes and
concrete classes. Decide which methods should be made abstract or
non-abstract.
/*************************************************************
abstract class Bharatvanshi
{
private String name; private int strength;
public Bharatvanshi(String name,int strength)
{
this.name = name;
this.strength = strength;
}
public abstract void fight();
public void kind()
{
System.out.println(name+" is kind.");
}
public void obey()
{
System.out.println(name +" is obedient.");
}
public String getName()
{
return name;
}
}
class Pandav extends Bharatvanshi
{ public Pandav(String name,int
strength)
{
super(name,strength);
}
public void fight()
{
System.out.println(getName()+" is skilled in fighting."); }
}
class Kaurav extends Bharatvanshi
{ public Kaurav(String name, int
strength)
{
super(name,strength);
}
public void fight()
{
System.out.println(getName()+" is a fighter."); }
public void kind()
{
System.out.println(getName()+" is notorious for cruelty."); }
public void obey()
{
System.out.println(getName()+" disobeys often."); }
}
class Vikarn extends Kaurav
{ public Vikarn(String name,int
strength)
{
super(name,strength);
}
public void kind()
{
System.out.println(getName()+" is a noble man."); }
}
public class Main
{ public static void main(String[]
args)
{
Pandav arjun= new Pandav("Arjun",90);
Pandav bheem= new Pandav("Bheem",85);
Kaurav duryodhan= new Kaurav("Duryodhan",95);
Vikarn vikarn= new Vikarn("Vikarn",88);
arjun.fight(); arjun.kind(); arjun.obey();
bheem.fight(); bheem.kind(); bheem.obey();
duryodhan.fight(); duryodhan.kind();
duryodhan.obey(); vikarn.fight();
vikarn.kind(); vikarn.obey();
}
}
Q2) Interfaces to be implemented by first non-abstract class
Make an interface ‘Testable’ that contains a method declaration for
display ( ).
a) Create a class ‘Test’ that implements Testable. Compile this
class, and write your observations.
b) Create another abstract class ‘AbsTest’ implements Testable.
Compile this class, and write your observations.
/*************************************************************
interface Testable
{ void
display();
}
class Test implements Testable
{ public void
display()
{
System.out.println("Displaying from Test class");
}
}
abstract class AbsTest implements Testable
{}
public class Main
{ public static void main(String[]
args)
{
Test testInstance = new Test();
testInstance.display();
// Uncommenting the following line will result in a compilation error // since
AbsTest is abstract and does not provide a concrete implementation for
display()
//AbsTest absTestInstance = new AbsTest();
}
}
Q3) Beautiful Code: Separate out uncompromisers
JUET students create a game of ducks. There were Rubber Ducks
(RD), Wooden Ducks (WD), RedHead Ducks (RHD), and Lake
Ducks (LD), as of now. There may be more in the future. As it can
be guessed, all ducks can swim. RD and WD can’t fly. RD squeaks.
WD is mute. RHD and LD quack. Design and Implement.
You might be tempted to make an abstract class ‘Duck’ by keeping
fly and quack behaviors abstract and swim behavior defined.
/*************************************************************
interface Swim
{ void
swim();
}
interface Quack
{ void
quack();
}
interface Squeak
{ void
squeak();
}
interface Duck extends Swim
{
}
class RubberDuck implements Duck,Squeak
{
public void swim()
{
System.out.println("Rubber Duck can swim");
}
public void squeak()
{
System.out.println("Rubber Duck squeaks");
}
}
class WoodenDuck implements Duck
{
public void swim()
{
System.out.println("Wooden Duck can swim"); }
}
class RedHeadDuck implements Duck,Quack
{
public void swim()
{
System.out.println("RedHead Duck can swim"); }
public void quack()
{
System.out.println("RedHead Duck quacks"); }
}
class LakeDuck implements Duck,Quack
{
public void swim()
{
System.out.println("Lake Duck can swim"); }
public void quack()
{
System.out.println("Lake Duck quacks"); }
}
public class Main
{
public static void main(String[] args)
{
Duck rubberDuck=new RubberDuck();
rubberDuck.swim();
((Squeak) rubberDuck).squeak(); Duck
woodenDuck=new WoodenDuck();
woodenDuck.swim();
Duck redHeadDuck=new RedHeadDuck();
redHeadDuck.swim();
((Quack) redHeadDuck).quack();
Duck lakeDuck=new LakeDuck();
lakeDuck.swim();
((Quack) lakeDuck).quack();
}}