Java handson for tcs xplore 2019
JavaHands-on1
//file1
publicclassArea
{
publicdoublecalculateArea(doubleradius)
{
//PI*r*rareaofcircle
doublep=3.1428571428571428571,area;
area=p*radius*radius;
returnarea;
}
publicdoublecalculateArea(doublelength,doublewidth)
{
//areaofrectangle
doublearea;
area=length*width;
returnarea;
}
publicdoublecalculateArea(doubleheight,doublelength,doublewidth)
{
//areaofcuboid
doublearea;
area=2*(height*length+length*width+width*height);
returnarea;
}
}
//file2
publicclassSolution1
{
publicstaticvoidmain(Stringargs[])
{
Areaar=newArea();
System.out.println(ar.calculateArea(14));
}
}
publicclassSolution2
{
publicstaticvoidmain(Stringargs[])
{
Areaar=newArea();
System.out.println(ar.calculateArea(10.0,12.0));
}
}
//file3
importjava.utils.Scanner;
publicclassSolution3
{
publicstaticvoidmain(Stringargs[])
{
Areaar=newArea();
Scannersc=newScanner(System.in);
System.out.println("enter height");
doubleh=sc.nextDouble();
System.out.println("enterlength");
doublel=sc.nextDouble();
System.out.println("enterwidth");
doublew=sc.nextDouble();
System.out.println(ar.calculateArea(h,l,w));
}
}
JavaHands-on2
File1
publicclassEmployee
{
Employee()
{
intid;
Stringname;
}
}
File2
publicclassSolution
{
publicstaticStringSwapName(Stringe1,Stringe2){
Stringtemp=e1;
e1=e2;
e2=temp;
return(e1+""+e2);
}
publicstaticvoidmain(Stringargs[])
{
Stringe1="aaa";
Stringe2="bbb";
Stringr1=SwapName(e1,e2);
System.out.println(r1);
}
}
JavaHands-on2
File1
File2
publicclassSolution
{
publicstaticStringcheckEmail(Stringe1,Stringe2)
{
Stringname="gmail.com";
booleanr1=e1.endsWith("gmail.com");
booleanr2=e2.endsWith("gmail.com");
booleanr3=name.endsWith("gmail.com");
if(r1==r2==r3)
return"true";
else
return"false";
}
publicstaticvoidmain(Stringargs[])
{
Stringe1="abc@rediff.com";
Stringe2="xyz@gmail.com";
System.out.println(checkEmail(e1,e2));
}
}
Comments
Post a Comment